Reload button and default mix time.

This commit is contained in:
NathanSweet 2014-05-29 21:33:06 +02:00
parent 147c9bd763
commit 968f408445
10 changed files with 54 additions and 39 deletions

View File

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

View File

@ -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();
}
}
}

View File

@ -46,23 +46,26 @@ public class SkeletonRendererInspector : Editor {
}
protected virtual void gui () {
EditorGUILayout.PropertyField(skeletonDataAsset);
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();
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];

View File

@ -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]);

View File

@ -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;
}

View File

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

View File

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

View File

@ -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();
}
}
}

View File

@ -46,21 +46,25 @@ public class SkeletonRendererInspector : Editor {
}
protected virtual void gui () {
EditorGUILayout.PropertyField(skeletonDataAsset);
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();
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.

View File

@ -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]);