浏览代码

Merge branch '4.0' into 4.1-beta

Harald Csaszar 3 年之前
父节点
当前提交
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;
 
 namespace Spine.Unity.Examples {
-	public class DataAssetsFromExportsExample : MonoBehaviour {
+	public class RuntimeLoadFromExportsExample : MonoBehaviour {
 
 		public TextAsset skeletonJson;
 		public TextAsset atlasText;
 		public Texture2D[] textures;
 		public Material materialPropertySource;
 
+		public float delay = 0;
+		public string skinName;
+		public string animationName;
+
 		SpineAtlasAsset runtimeAtlasAsset;
 		SkeletonDataAsset runtimeSkeletonDataAsset;
 		SkeletonAnimation runtimeSkeletonAnimation;
@@ -54,19 +58,19 @@ namespace Spine.Unity.Examples {
 
 		IEnumerator Start () {
 			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);
 
-			// Extra Stuff
+			// additional initialization
 			runtimeSkeletonAnimation.Initialize(false);
-			runtimeSkeletonAnimation.Skeleton.SetSkin("base");
+			if (skinName != "")
+				runtimeSkeletonAnimation.Skeleton.SetSkin(skinName);
 			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 {
 		protected SerializedProperty animationName, loop, timeScale, autoReset;
 		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 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();
 
 			serializedObject.ApplyModifiedProperties();
-
-			if (!isInspectingPrefab) {
-				if (requireRepaint) {
-					UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
-					requireRepaint = false;
-				}
-			}
 		}
 
 		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 maskMaterialsNone, maskMaterialsInside, maskMaterialsOutside;
 		protected SpineInspectorUtility.SerializedSortingProperties sortingProperties;
+		protected bool wasInitParameterChanged = false;
+		protected bool requireRepaint = false;
 
 		protected bool isInspectingPrefab;
 		protected bool forceReloadQueued = false;
@@ -196,6 +198,13 @@ namespace Spine.Unity.Editor {
 					SceneView.RepaintAll();
 				}
 			}
+
+			if (!isInspectingPrefab) {
+				if (requireRepaint) {
+					UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+					requireRepaint = false;
+				}
+			}
 		}
 
 		protected virtual void DrawInspectorGUI (bool multi) {
@@ -259,6 +268,9 @@ namespace Spine.Unity.Editor {
 
 			bool valid = TargetIsValid;
 
+			foreach (var o in targets)
+				ApplyModifiedMeshParameters(o as SkeletonRenderer);
+
 			// Fields.
 			if (multi) {
 				using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox)) {
@@ -330,8 +342,10 @@ namespace Spine.Unity.Editor {
 
 					using (new SpineInspectorUtility.IndentScope()) {
 						using (new EditorGUILayout.HorizontalScope()) {
+							EditorGUI.BeginChangeCheck();
 							SpineInspectorUtility.ToggleLeftLayout(initialFlipX);
 							SpineInspectorUtility.ToggleLeftLayout(initialFlipY);
+							wasInitParameterChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
 							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 () {
 			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 };
 
 		public static List<string> GetRequiredAtlasRegions (string skeletonDataPath) {
-			List<string> requiredPaths = new List<string>();
+			HashSet<string> requiredPaths = new HashSet<string>();
 
 			if (skeletonDataPath.Contains(".skel")) {
-				AddRequiredAtlasRegionsFromBinary(skeletonDataPath, requiredPaths);
-				return requiredPaths;
+				List<string> requiredPathsResult = new List<string>();
+				AddRequiredAtlasRegionsFromBinary(skeletonDataPath, requiredPathsResult);
+				return requiredPathsResult;
 			}
 
 			TextReader reader = null;
@@ -143,11 +144,11 @@ namespace Spine.Unity.Editor {
 			}
 
 			if (root == null || !root.ContainsKey("skins"))
-				return requiredPaths;
+				return new List<string>();
 
 			var skinsList = root["skins"] as List<object>;
 			if (skinsList == null)
-				return requiredPaths;
+				return new List<string>();
 
 			foreach (Dictionary<string, object> skinMap in skinsList) {
 				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) {

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

@@ -181,7 +181,10 @@ namespace Spine.Unity {
 			var drawOrderItems = drawOrder.Items;
 			for (int i = 0; i < drawOrderCount; 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;
 				Attachment attachment = slot.Attachment;
 
@@ -303,7 +306,10 @@ namespace Spine.Unity {
 			var drawOrderItems = drawOrder.Items;
 			for (int i = 0; i < drawOrderCount; 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;
 				Attachment attachment = slot.Attachment;
 #if SPINE_TRIANGLECHECK