暂且修了LookAt
This commit is contained in:
28
Assets/Scripts/Extensions/ShaderExtension.cs
Normal file
28
Assets/Scripts/Extensions/ShaderExtension.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ShaderExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 对于从AssetBundle中加载的材质,修改Shader参数可能会出现异常情况。
|
||||
/// 此时需要在生成物体的时候,重新初始化Shader。
|
||||
/// </summary>
|
||||
public static void InitializeShader(this Renderer renderer)
|
||||
{
|
||||
foreach (Material material in renderer.materials)
|
||||
{
|
||||
string shaderName = material.shader.name;
|
||||
Shader shader = Shader.Find(shaderName);
|
||||
|
||||
if (shader != null)
|
||||
{
|
||||
material.shader = shader;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Shader '{shaderName}' not found for material '{material.name}' on renderer '{renderer.name}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user