浏览代码

[unity] Minor: example script documentation improved (CustomMaterialOverride).

Harald Csaszar 3 年之前
父节点
当前提交
689daa147a
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      spine-unity/Assets/Spine Examples/Scripts/MaterialReplacementExample.cs

+ 7 - 0
spine-unity/Assets/Spine Examples/Scripts/MaterialReplacementExample.cs

@@ -47,6 +47,13 @@ namespace Spine.Unity.Examples {
 		MaterialPropertyBlock mpb;
 
 		void Start () {
+			// Use the code below to programmatically query the original material.
+			// Note: using MeshRenderer.material will fail since it creates an instance copy of the Material,
+			// MeshRenderer.sharedMaterial might also fail when called too early or when no Attachments
+			// are visible in the initial first frame.
+			if (originalMaterial == null)
+				originalMaterial = skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;
+
 			previousEnabled = replacementEnabled;
 			SetReplacementEnabled(replacementEnabled);
 			mpb = new MaterialPropertyBlock();