fix(peipei-eye): 编辑模式下改用 sharedMaterial 避免材质泄漏
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -225,7 +225,10 @@ public class EyeTarget : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
Material currentMaterial = spriteRenderer.material;
|
||||
Material currentMaterial = Application.isPlaying
|
||||
? spriteRenderer.material
|
||||
: spriteRenderer.sharedMaterial;
|
||||
|
||||
bool usesUnifiedShader = currentMaterial != null
|
||||
&& currentMaterial.shader != null
|
||||
&& currentMaterial.shader.name == shader.name;
|
||||
@@ -234,13 +237,22 @@ public class EyeTarget : MonoBehaviour
|
||||
Texture mainTex = currentMaterial != null && currentMaterial.HasProperty("_MainTex")
|
||||
? currentMaterial.GetTexture("_MainTex")
|
||||
: null;
|
||||
spriteRenderer.material = new Material(shader)
|
||||
var runtimeMaterial = new Material(shader)
|
||||
{
|
||||
name = $"{gameObject.name}_EyeUnified_Runtime"
|
||||
};
|
||||
if (mainTex != null)
|
||||
{
|
||||
spriteRenderer.material.SetTexture("_MainTex", mainTex);
|
||||
runtimeMaterial.SetTexture("_MainTex", mainTex);
|
||||
}
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
spriteRenderer.material = runtimeMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteRenderer.sharedMaterial = runtimeMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,9 @@ namespace AibisDream
|
||||
return false;
|
||||
}
|
||||
|
||||
material = spriteRenderer.material;
|
||||
material = Application.isPlaying
|
||||
? spriteRenderer.material
|
||||
: spriteRenderer.sharedMaterial;
|
||||
return IsReady;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user