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

Reload button and default mix time.

NathanSweet 11 жил өмнө
parent
commit
968f408445

+ 0 - 1
spine-tk2d/Assets/spine-tk2d/Editor/BoneComponentInspector.cs

@@ -41,7 +41,6 @@ public class BoneComponentInspector : Editor {
 		boneName = serializedObject.FindProperty("boneName");
 		followBoneRotation = serializedObject.FindProperty("followBoneRotation");
 		followZPosition = serializedObject.FindProperty("followZPosition");
-
 	}
 
 	override public void OnInspectorGUI () {

+ 5 - 2
spine-tk2d/Assets/spine-tk2d/Editor/SkeletonDataAssetInspector.cs

@@ -35,7 +35,7 @@ using Spine;
 
 [CustomEditor(typeof(SkeletonDataAsset))]
 public class SkeletonDataAssetInspector : Editor {
-	private SerializedProperty spriteCollection, skeletonJSON, scale, fromAnimation, toAnimation, duration;
+	private SerializedProperty spriteCollection, skeletonJSON, scale, fromAnimation, toAnimation, duration, defaultMix;
 	private bool showAnimationStateData = true;
 
 	void OnEnable () {
@@ -45,6 +45,7 @@ public class SkeletonDataAssetInspector : Editor {
 		fromAnimation = serializedObject.FindProperty("fromAnimation");
 		toAnimation = serializedObject.FindProperty("toAnimation");
 		duration = serializedObject.FindProperty("duration");
+		defaultMix = serializedObject.FindProperty("defaultMix");
 	}
 
 	override public void OnInspectorGUI () {
@@ -62,6 +63,8 @@ public class SkeletonDataAssetInspector : Editor {
 		if (skeletonData != null) {
 			showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data");
 			if (showAnimationStateData) {
+				EditorGUILayout.PropertyField(defaultMix);
+
 				// Animation names.
 				String[] animations = new String[skeletonData.Animations.Count];
 				for (int i = 0; i < animations.Length; i++)
@@ -98,7 +101,7 @@ public class SkeletonDataAssetInspector : Editor {
 			if (serializedObject.ApplyModifiedProperties() ||
 				(UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
 			) {
-				asset.Clear();
+				asset.Reset();
 			}
 		}
 	}

+ 13 - 10
spine-tk2d/Assets/spine-tk2d/Editor/SkeletonRendererInspector.cs

@@ -46,23 +46,26 @@ public class SkeletonRendererInspector : Editor {
 	}
 
 	protected virtual void gui () {
+		SkeletonRenderer component = (SkeletonRenderer)target;
+		
+		EditorGUILayout.BeginHorizontal();
 		EditorGUILayout.PropertyField(skeletonDataAsset);
+		float reloadWidth = GUI.skin.label.CalcSize(new GUIContent("Reload")).x + 20;
+		if (GUILayout.Button("Reload", GUILayout.Width(reloadWidth))) {
+			if (component.skeletonDataAsset != null) {
+				component.skeletonDataAsset.Reset();
+			}
+			component.Reset();
+		}
+		EditorGUILayout.EndHorizontal();
 
-		SkeletonRenderer component = (SkeletonRenderer)target;
 		if (!component.valid) {
 			component.Reset();
 			component.LateUpdate();
-			if (!component.valid) {
-				EditorGUILayout.BeginHorizontal();
-				EditorGUILayout.Space();
-				if (GUILayout.Button("Refresh")) component.Reset();
-				EditorGUILayout.Space();
-				EditorGUILayout.EndHorizontal();
-				EditorGUILayout.Space();
-				return;
-			}
+			if (!component.valid) return;
 		}
 
+
 		// Initial skin name.
 		{
 			String[] skins = new String[component.skeleton.Data.Skins.Count];

+ 5 - 3
spine-tk2d/Assets/spine-tk2d/SkeletonDataAsset.cs

@@ -41,10 +41,11 @@ public class SkeletonDataAsset : ScriptableObject {
 	public String[] fromAnimation;
 	public String[] toAnimation;
 	public float[] duration;
+	public float defaultMix;
 	private SkeletonData skeletonData;
 	private AnimationStateData stateData;
 
-	public void Clear () {
+	public void Reset () {
 		skeletonData = null;
 		stateData = null;
 	}
@@ -53,14 +54,14 @@ public class SkeletonDataAsset : ScriptableObject {
 		if (spriteCollection == null) {
 			if (!quiet)
 				Debug.LogError("Sprite collection not set for skeleton data asset: " + name, this);
-			Clear();
+			Reset();
 			return null;
 		}
 		
 		if (skeletonJSON == null) {
 			if (!quiet)
 				Debug.LogError("Skeleton JSON file not set for skeleton data asset: " + name, this);
-			Clear();
+			Reset();
 			return null;
 		}
 
@@ -78,6 +79,7 @@ public class SkeletonDataAsset : ScriptableObject {
 		}
 
 		stateData = new AnimationStateData(skeletonData);
+		stateData.DefaultMix = defaultMix;
 		for (int i = 0, n = fromAnimation.Length; i < n; i++) {
 			if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue;
 			stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);

+ 3 - 3
spine-unity/Assets/spine-unity/AtlasAsset.cs

@@ -39,7 +39,7 @@ public class AtlasAsset : ScriptableObject {
 	public Material[] materials;
 	private Atlas atlas;
 
-	public void Clear () {
+	public void Reset () {
 		atlas = null;
 	}
 
@@ -47,13 +47,13 @@ public class AtlasAsset : ScriptableObject {
 	public Atlas GetAtlas () {
 		if (atlasFile == null) {
 			Debug.LogError("Atlas file not set for atlas asset: " + name, this);
-			Clear();
+			Reset();
 			return null;
 		}
 
 		if (materials == null || materials.Length == 0) {
 			Debug.LogError("Materials not set for atlas asset: " + name, this);
-			Clear();
+			Reset();
 			return null;
 		}
 

+ 1 - 1
spine-unity/Assets/spine-unity/Editor/AtlasAssetInspector.cs

@@ -51,7 +51,7 @@ public class AtlasAssetInspector : Editor {
 		if (serializedObject.ApplyModifiedProperties() ||
 			(Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
 		) {
-			asset.Clear();
+			asset.Reset();
 		}
 	}
 }

+ 0 - 1
spine-unity/Assets/spine-unity/Editor/BoneComponentInspector.cs

@@ -41,7 +41,6 @@ public class BoneComponentInspector : Editor {
 		boneName = serializedObject.FindProperty("boneName");
 		followBoneRotation = serializedObject.FindProperty("followBoneRotation");
 		followZPosition = serializedObject.FindProperty("followZPosition");
-
 	}
 
 	override public void OnInspectorGUI () {

+ 5 - 2
spine-unity/Assets/spine-unity/Editor/SkeletonDataAssetInspector.cs

@@ -35,7 +35,7 @@ using Spine;
 
 [CustomEditor(typeof(SkeletonDataAsset))]
 public class SkeletonDataAssetInspector : Editor {
-	private SerializedProperty atlasAsset, skeletonJSON, scale, fromAnimation, toAnimation, duration;
+	private SerializedProperty atlasAsset, skeletonJSON, scale, fromAnimation, toAnimation, duration, defaultMix;
 	private bool showAnimationStateData = true;
 
 	void OnEnable () {
@@ -45,6 +45,7 @@ public class SkeletonDataAssetInspector : Editor {
 		fromAnimation = serializedObject.FindProperty("fromAnimation");
 		toAnimation = serializedObject.FindProperty("toAnimation");
 		duration = serializedObject.FindProperty("duration");
+		defaultMix = serializedObject.FindProperty("defaultMix");
 	}
 
 	override public void OnInspectorGUI () {
@@ -59,6 +60,8 @@ public class SkeletonDataAssetInspector : Editor {
 		if (skeletonData != null) {
 			showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data");
 			if (showAnimationStateData) {
+				EditorGUILayout.PropertyField(defaultMix);
+
 				// Animation names.
 				String[] animations = new String[skeletonData.Animations.Count];
 				for (int i = 0; i < animations.Length; i++)
@@ -95,7 +98,7 @@ public class SkeletonDataAssetInspector : Editor {
 			if (serializedObject.ApplyModifiedProperties() ||
 				(UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
 			) {
-				asset.Clear();
+				asset.Reset();
 			}
 		}
 	}

+ 14 - 10
spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs

@@ -46,21 +46,25 @@ public class SkeletonRendererInspector : Editor {
 	}
 
 	protected virtual void gui () {
+		SkeletonRenderer component = (SkeletonRenderer)target;
+
+		EditorGUILayout.BeginHorizontal();
 		EditorGUILayout.PropertyField(skeletonDataAsset);
+		float reloadWidth = GUI.skin.label.CalcSize(new GUIContent("Reload")).x + 20;
+		if (GUILayout.Button("Reload", GUILayout.Width(reloadWidth))) {
+			if (component.skeletonDataAsset != null) {
+				if (component.skeletonDataAsset.atlasAsset != null)
+					component.skeletonDataAsset.atlasAsset.Reset();
+				component.skeletonDataAsset.Reset();
+			}
+			component.Reset();
+		}
+		EditorGUILayout.EndHorizontal();
 
-		SkeletonRenderer component = (SkeletonRenderer)target;
 		if (!component.valid) {
 			component.Reset();
 			component.LateUpdate();
-			if (!component.valid) {
-				EditorGUILayout.BeginHorizontal();
-				EditorGUILayout.Space();
-				if (GUILayout.Button("Refresh")) component.Reset();
-				EditorGUILayout.Space();
-				EditorGUILayout.EndHorizontal();
-				EditorGUILayout.Space();
-				return;
-			}
+			if (!component.valid) return;
 		}
 
 		// Initial skin name.

+ 6 - 4
spine-unity/Assets/spine-unity/SkeletonDataAsset.cs

@@ -41,10 +41,11 @@ public class SkeletonDataAsset : ScriptableObject {
 	public String[] fromAnimation;
 	public String[] toAnimation;
 	public float[] duration;
+	public float defaultMix;
 	private SkeletonData skeletonData;
 	private AnimationStateData stateData;
 
-	public void Clear () {
+	public void Reset () {
 		skeletonData = null;
 		stateData = null;
 	}
@@ -53,20 +54,20 @@ public class SkeletonDataAsset : ScriptableObject {
 		if (atlasAsset == null) {
 			if (!quiet)
 				Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
-			Clear();
+			Reset();
 			return null;
 		}
 
 		if (skeletonJSON == null) {
 			if (!quiet)
 				Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
-			Clear();
+			Reset();
 			return null;
 		}
 
 		Atlas atlas = atlasAsset.GetAtlas();
 		if (atlas == null) {
-			Clear();
+			Reset();
 			return null;
 		}
 
@@ -84,6 +85,7 @@ public class SkeletonDataAsset : ScriptableObject {
 		}
 
 		stateData = new AnimationStateData(skeletonData);
+		stateData.DefaultMix = defaultMix;
 		for (int i = 0, n = fromAnimation.Length; i < n; i++) {
 			if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) continue;
 			stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]);