Skip to content

Commit

Permalink
Temporary commit
Browse files Browse the repository at this point in the history
  • Loading branch information
from2001 committed Dec 5, 2023
1 parent 268e94c commit 588ecf8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using System.Collections;
using VisualScriptingNodes;

namespace VrmVisualScriptingNodes
{
Expand Down Expand Up @@ -35,16 +36,19 @@ protected override void Definition()

VrmURL = ValueInput<string>("VRM URL", "");
result = ValueOutput<GameObject>("Game Object", (flow) => resultValue);

}

private IEnumerator Enter(Flow flow)
{
string url = flow.GetValue<string>(VrmURL);
Vrm10Instance vrmInstance = null;
UniTask.Create(async () => {vrmInstance = await LoadVrm(url);}).Forget();
UniTask.Create(async () => { vrmInstance = await LoadVrm(url); }).Forget();
yield return new WaitUntil(() => vrmInstance);
resultValue = vrmInstance.gameObject;

Utils.ReplaceErrorShaders(resultValue, Utils.GetShaderForErrorReplacement());

yield return outputTrigger;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,59 @@
using System;
using UnityEngine.Networking;
using System.Runtime.CompilerServices;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

namespace from2001
namespace VisualScriptingNodes
{
public class Utils : MonoBehaviour
{
static int addTest(int a, int b)
static public int addTest(int a, int b)
{
return a + b;
}



public static Shader GetShaderForErrorReplacement(string shaderType = "Unlit")
{
Shader retShader = null;
retShader = shaderType switch
{
"Unlit" => Shader.Find(GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset
? "Universal Render Pipeline/Unlit" : "Unlit/Texture"),
"Lit" => Shader.Find(GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset
? "Universal Render Pipeline/Lit" : "Standard"),
_ => Shader.Find(GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset
? "Universal Render Pipeline/Unlit" : "Unlit/Texture"),
};
return retShader;
}


// GameObjectとその子孫のマテリアルのシェーダーを再帰的に置き換えるヘルパーメソッド
public static void ReplaceErrorShaders(GameObject obj, Shader replacementShader)
{
if (obj.TryGetComponent<Renderer>(out var renderer))
{
foreach (Material mat in renderer.materials)
{
//if (mat.shader == null || Shader.Find(mat.shader.name) == null)
//{
mat.shader = replacementShader;
//}
}
}

// 子GameObjectに対しても同じ処理を行う
foreach (Transform child in obj.transform)
{
ReplaceErrorShaders(child.gameObject, replacementShader);
}
}




}
}

0 comments on commit 588ecf8

Please sign in to comment.