Browse Source

Merge branch '4.0' into 4.1-beta

Harald Csaszar 3 years ago
parent
commit
b1e81fc1b2

+ 14 - 10
spine-unity/Assets/Spine Examples/Scripts/DataAssetsFromExportsExample.cs → spine-unity/Assets/Spine Examples/Scripts/RuntimeLoadFromExportsExample.cs

@@ -32,13 +32,17 @@ using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine;
 
 
 namespace Spine.Unity.Examples {
 namespace Spine.Unity.Examples {
-	public class DataAssetsFromExportsExample : MonoBehaviour {
+	public class RuntimeLoadFromExportsExample : MonoBehaviour {
 
 
 		public TextAsset skeletonJson;
 		public TextAsset skeletonJson;
 		public TextAsset atlasText;
 		public TextAsset atlasText;
 		public Texture2D[] textures;
 		public Texture2D[] textures;
 		public Material materialPropertySource;
 		public Material materialPropertySource;
 
 
+		public float delay = 0;
+		public string skinName;
+		public string animationName;
+
 		SpineAtlasAsset runtimeAtlasAsset;
 		SpineAtlasAsset runtimeAtlasAsset;
 		SkeletonDataAsset runtimeSkeletonDataAsset;
 		SkeletonDataAsset runtimeSkeletonDataAsset;
 		SkeletonAnimation runtimeSkeletonAnimation;
 		SkeletonAnimation runtimeSkeletonAnimation;
@@ -54,19 +58,19 @@ namespace Spine.Unity.Examples {
 
 
 		IEnumerator Start () {
 		IEnumerator Start () {
 			CreateRuntimeAssetsAndGameObject();
 			CreateRuntimeAssetsAndGameObject();
-			runtimeSkeletonDataAsset.GetSkeletonData(false); // preload.
-			yield return new WaitForSeconds(0.5f);
-
+			if (delay > 0) {
+				runtimeSkeletonDataAsset.GetSkeletonData(false); // preload
+				yield return new WaitForSeconds(delay);
+			}
 			runtimeSkeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(runtimeSkeletonDataAsset);
 			runtimeSkeletonAnimation = SkeletonAnimation.NewSkeletonAnimationGameObject(runtimeSkeletonDataAsset);
 
 
-			// Extra Stuff
+			// additional initialization
 			runtimeSkeletonAnimation.Initialize(false);
 			runtimeSkeletonAnimation.Initialize(false);
-			runtimeSkeletonAnimation.Skeleton.SetSkin("base");
+			if (skinName != "")
+				runtimeSkeletonAnimation.Skeleton.SetSkin(skinName);
 			runtimeSkeletonAnimation.Skeleton.SetSlotsToSetupPose();
 			runtimeSkeletonAnimation.Skeleton.SetSlotsToSetupPose();
-			runtimeSkeletonAnimation.AnimationState.SetAnimation(0, "run", true);
-			runtimeSkeletonAnimation.GetComponent<MeshRenderer>().sortingOrder = 10;
-			runtimeSkeletonAnimation.transform.Translate(Vector3.down * 2);
-
+			if (animationName != "")
+				runtimeSkeletonAnimation.AnimationState.SetAnimation(0, animationName, true);
 		}
 		}
 	}
 	}
 
 

+ 0 - 0
spine-unity/Assets/Spine Examples/Scripts/DataAssetsFromExportsExample.cs.meta → spine-unity/Assets/Spine Examples/Scripts/RuntimeLoadFromExportsExample.cs.meta


+ 0 - 8
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonAnimationInspector.cs

@@ -38,7 +38,6 @@ namespace Spine.Unity.Editor {
 	public class SkeletonAnimationInspector : SkeletonRendererInspector {
 	public class SkeletonAnimationInspector : SkeletonRendererInspector {
 		protected SerializedProperty animationName, loop, timeScale, autoReset;
 		protected SerializedProperty animationName, loop, timeScale, autoReset;
 		protected bool wasAnimationParameterChanged = false;
 		protected bool wasAnimationParameterChanged = false;
-		protected bool requireRepaint;
 		readonly GUIContent LoopLabel = new GUIContent("Loop", "Whether or not .AnimationName should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.");
 		readonly GUIContent LoopLabel = new GUIContent("Loop", "Whether or not .AnimationName should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.");
 		readonly GUIContent TimeScaleLabel = new GUIContent("Time Scale", "The rate at which animations progress over time. 1 means normal speed. 0.5 means 50% speed.");
 		readonly GUIContent TimeScaleLabel = new GUIContent("Time Scale", "The rate at which animations progress over time. 1 means normal speed. 0.5 means 50% speed.");
 
 
@@ -79,13 +78,6 @@ namespace Spine.Unity.Editor {
 			SkeletonRootMotionParameter();
 			SkeletonRootMotionParameter();
 
 
 			serializedObject.ApplyModifiedProperties();
 			serializedObject.ApplyModifiedProperties();
-
-			if (!isInspectingPrefab) {
-				if (requireRepaint) {
-					UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
-					requireRepaint = false;
-				}
-			}
 		}
 		}
 
 
 		protected void TrySetAnimation (SkeletonAnimation skeletonAnimation) {
 		protected void TrySetAnimation (SkeletonAnimation skeletonAnimation) {

+ 31 - 0
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonRendererInspector.cs

@@ -70,6 +70,8 @@ namespace Spine.Unity.Editor {
 		protected SerializedProperty maskInteraction;
 		protected SerializedProperty maskInteraction;
 		protected SerializedProperty maskMaterialsNone, maskMaterialsInside, maskMaterialsOutside;
 		protected SerializedProperty maskMaterialsNone, maskMaterialsInside, maskMaterialsOutside;
 		protected SpineInspectorUtility.SerializedSortingProperties sortingProperties;
 		protected SpineInspectorUtility.SerializedSortingProperties sortingProperties;
+		protected bool wasInitParameterChanged = false;
+		protected bool requireRepaint = false;
 
 
 		protected bool isInspectingPrefab;
 		protected bool isInspectingPrefab;
 		protected bool forceReloadQueued = false;
 		protected bool forceReloadQueued = false;
@@ -196,6 +198,13 @@ namespace Spine.Unity.Editor {
 					SceneView.RepaintAll();
 					SceneView.RepaintAll();
 				}
 				}
 			}
 			}
+
+			if (!isInspectingPrefab) {
+				if (requireRepaint) {
+					UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+					requireRepaint = false;
+				}
+			}
 		}
 		}
 
 
 		protected virtual void DrawInspectorGUI (bool multi) {
 		protected virtual void DrawInspectorGUI (bool multi) {
@@ -259,6 +268,9 @@ namespace Spine.Unity.Editor {
 
 
 			bool valid = TargetIsValid;
 			bool valid = TargetIsValid;
 
 
+			foreach (var o in targets)
+				ApplyModifiedMeshParameters(o as SkeletonRenderer);
+
 			// Fields.
 			// Fields.
 			if (multi) {
 			if (multi) {
 				using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
 				using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
@@ -330,8 +342,10 @@ namespace Spine.Unity.Editor {
 
 
 					using (new SpineInspectorUtility.IndentScope()) {
 					using (new SpineInspectorUtility.IndentScope()) {
 						using (new EditorGUILayout.HorizontalScope()) {
 						using (new EditorGUILayout.HorizontalScope()) {
+							EditorGUI.BeginChangeCheck();
 							SpineInspectorUtility.ToggleLeftLayout(initialFlipX);
 							SpineInspectorUtility.ToggleLeftLayout(initialFlipX);
 							SpineInspectorUtility.ToggleLeftLayout(initialFlipY);
 							SpineInspectorUtility.ToggleLeftLayout(initialFlipY);
+							wasInitParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
 							EditorGUILayout.Space();
 							EditorGUILayout.Space();
 						}
 						}
 
 
@@ -421,6 +435,23 @@ namespace Spine.Unity.Editor {
 			}
 			}
 		}
 		}
 
 
+		protected void ApplyModifiedMeshParameters (SkeletonRenderer skeletonRenderer) {
+			if (skeletonRenderer == null) return;
+			if (!skeletonRenderer.valid)
+				return;
+
+			if (!isInspectingPrefab) {
+				if (wasInitParameterChanged) {
+					wasInitParameterChanged = false;
+					if (!Application.isPlaying) {
+						skeletonRenderer.Initialize(true);
+						skeletonRenderer.LateUpdate();
+						requireRepaint = true;
+					}
+				}
+			}
+		}
+
 		protected void SkeletonRootMotionParameter () {
 		protected void SkeletonRootMotionParameter () {
 			SkeletonRootMotionParameter(targets);
 			SkeletonRootMotionParameter(targets);
 		}
 		}

+ 7 - 6
spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs

@@ -118,11 +118,12 @@ namespace Spine.Unity.Editor {
 		static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh };
 		static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh };
 
 
 		public static List<string> GetRequiredAtlasRegions (string skeletonDataPath) {
 		public static List<string> GetRequiredAtlasRegions (string skeletonDataPath) {
-			List<string> requiredPaths = new List<string>();
+			HashSet<string> requiredPaths = new HashSet<string>();
 
 
 			if (skeletonDataPath.Contains(".skel")) {
 			if (skeletonDataPath.Contains(".skel")) {
-				AddRequiredAtlasRegionsFromBinary(skeletonDataPath, requiredPaths);
-				return requiredPaths;
+				List<string> requiredPathsResult = new List<string>();
+				AddRequiredAtlasRegionsFromBinary(skeletonDataPath, requiredPathsResult);
+				return requiredPathsResult;
 			}
 			}
 
 
 			TextReader reader = null;
 			TextReader reader = null;
@@ -143,11 +144,11 @@ namespace Spine.Unity.Editor {
 			}
 			}
 
 
 			if (root == null || !root.ContainsKey("skins"))
 			if (root == null || !root.ContainsKey("skins"))
-				return requiredPaths;
+				return new List<string>();
 
 
 			var skinsList = root["skins"] as List<object>;
 			var skinsList = root["skins"] as List<object>;
 			if (skinsList == null)
 			if (skinsList == null)
-				return requiredPaths;
+				return new List<string>();
 
 
 			foreach (Dictionary<string, object> skinMap in skinsList) {
 			foreach (Dictionary<string, object> skinMap in skinsList) {
 				if (!skinMap.ContainsKey("attachments"))
 				if (!skinMap.ContainsKey("attachments"))
@@ -189,7 +190,7 @@ namespace Spine.Unity.Editor {
 				}
 				}
 			}
 			}
 
 
-			return requiredPaths;
+			return requiredPaths.ToList();
 		}
 		}
 
 
 		internal static void AddRequiredAtlasRegionsFromBinary (string skeletonDataPath, List<string> requiredPaths) {
 		internal static void AddRequiredAtlasRegionsFromBinary (string skeletonDataPath, List<string> requiredPaths) {

+ 8 - 2
spine-unity/Assets/Spine/Runtime/spine-unity/Mesh Generation/MeshGenerator.cs

@@ -181,7 +181,10 @@ namespace Spine.Unity {
 			var drawOrderItems = drawOrder.Items;
 			var drawOrderItems = drawOrder.Items;
 			for (int i = 0; i < drawOrderCount; i++) {
 			for (int i = 0; i < drawOrderCount; i++) {
 				Slot slot = drawOrderItems[i];
 				Slot slot = drawOrderItems[i];
-				if (!slot.Bone.Active) continue;
+				if (!slot.Bone.Active) {
+					workingAttachmentsItems[i] = null;
+					continue;
+				}
 				if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true;
 				if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true;
 				Attachment attachment = slot.Attachment;
 				Attachment attachment = slot.Attachment;
 
 
@@ -303,7 +306,10 @@ namespace Spine.Unity {
 			var drawOrderItems = drawOrder.Items;
 			var drawOrderItems = drawOrder.Items;
 			for (int i = 0; i < drawOrderCount; i++) {
 			for (int i = 0; i < drawOrderCount; i++) {
 				Slot slot = drawOrderItems[i];
 				Slot slot = drawOrderItems[i];
-				if (!slot.Bone.Active) continue;
+				if (!slot.Bone.Active) {
+					workingAttachmentsItems[i] = null;
+					continue;
+				}
 				if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true;
 				if (slot.Data.BlendMode == BlendMode.Additive) current.hasPMAAdditiveSlot = true;
 				Attachment attachment = slot.Attachment;
 				Attachment attachment = slot.Attachment;
 #if SPINE_TRIANGLECHECK
 #if SPINE_TRIANGLECHECK