Эх сурвалжийг харах

[unity] Fixed Prefab with `SkeletonRenderSeparator` constantly loading in editor. Closes #1626.

Harald Csaszar 5 жил өмнө
parent
commit
6e9ad610d6

+ 16 - 1
spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonRenderSeparator/Editor/SkeletonRenderSeparatorInspector.cs

@@ -27,6 +27,10 @@
  * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *****************************************************************************/
 
+#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER
+#define NEW_PREFAB_SYSTEM
+#endif
+
 using UnityEngine;
 using UnityEditor;
 
@@ -81,7 +85,18 @@ namespace Spine.Unity.Examples {
 
 			// Restore mesh part for undo logic after undo of "Add Parts Renderer".
 			// Triggers regeneration and assignment of the mesh filter's mesh.
-			if (component.GetComponent<MeshFilter>() && component.GetComponent<MeshFilter>().sharedMesh == null) {
+
+			bool isMeshFilterAlwaysNull = false;
+			#if UNITY_EDITOR && NEW_PREFAB_SYSTEM
+			// Don't store mesh or material at the prefab, otherwise it will permanently reload
+			var prefabType = UnityEditor.PrefabUtility.GetPrefabAssetType(component);
+			if (UnityEditor.PrefabUtility.IsPartOfPrefabAsset(component) &&
+				(prefabType == UnityEditor.PrefabAssetType.Regular || prefabType == UnityEditor.PrefabAssetType.Variant)) {
+				isMeshFilterAlwaysNull = true;
+			}
+			#endif
+
+			if (!isMeshFilterAlwaysNull && component.GetComponent<MeshFilter>() && component.GetComponent<MeshFilter>().sharedMesh == null) {
 				component.OnDisable();
 				component.OnEnable();
 			}

+ 9 - 3
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderSeparator/SkeletonRenderSeparator.cs

@@ -191,8 +191,10 @@ namespace Spine.Unity {
 
 			skeletonRenderer.LateUpdate();
 
-			foreach (var s in partsRenderers)
-				s.ClearMesh();
+			foreach (var partsRenderer in partsRenderers) {
+				if (partsRenderer != null)
+					partsRenderer.ClearMesh();
+			}
 		}
 
 		MaterialPropertyBlock copiedBlock;
@@ -221,6 +223,8 @@ namespace Spine.Unity {
 			int rendererIndex = 0;
 			var currentRenderer = partsRenderers[rendererIndex];
 			for (int si = 0, start = 0; si <= lastSubmeshInstruction; si++) {
+				if (currentRenderer == null)
+					continue;
 				if (submeshInstructionsItems[si].forceSeparate || si == lastSubmeshInstruction) {
 					// Apply properties
 					var meshGenerator = currentRenderer.MeshGenerator;
@@ -245,7 +249,9 @@ namespace Spine.Unity {
 
 			// Clear extra renderers if they exist.
 			for (; rendererIndex < rendererCount; rendererIndex++) {
-				partsRenderers[rendererIndex].ClearMesh();
+				currentRenderer = partsRenderers[rendererIndex];
+				if (currentRenderer != null)
+					partsRenderers[rendererIndex].ClearMesh();
 			}
 
 		}

+ 1 - 1
spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs

@@ -529,7 +529,7 @@ namespace Spine.Unity {
 					separatorSlots.Add(slot);
 				}
 				#if UNITY_EDITOR
-				else
+				else if (!string.IsNullOrEmpty(separatorSlotNames[i]))
 				{
 					Debug.LogWarning(separatorSlotNames[i] + " is not a slot in " + skeletonDataAsset.skeletonJSON.name);
 				}