Spine.Unity namespace and some editor tweaks.

This commit is contained in:
pharan 2016-03-19 16:54:43 +08:00
parent 50a0960a7d
commit 9e8fdeef6c
9 changed files with 1226 additions and 1174 deletions

View File

@ -28,20 +28,20 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
//#define BAKE_ALL_BUTTON
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.IO; using System.IO;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using Spine; using Spine;
namespace Spine.Unity {
[CustomEditor(typeof(AtlasAsset))] [CustomEditor(typeof(AtlasAsset))]
public class AtlasAssetInspector : Editor { public class AtlasAssetInspector : Editor {
private SerializedProperty atlasFile, materials; private SerializedProperty atlasFile, materials;
private AtlasAsset atlasAsset; private AtlasAsset atlasAsset;
private List<bool> baked; private List<bool> baked;
@ -78,8 +78,6 @@ public class AtlasAssetInspector : Editor {
} }
} }
override public void OnInspectorGUI () { override public void OnInspectorGUI () {
serializedObject.Update(); serializedObject.Update();
AtlasAsset asset = (AtlasAsset)target; AtlasAsset asset = (AtlasAsset)target;
@ -166,6 +164,48 @@ public class AtlasAssetInspector : Editor {
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
EditorGUI.indentLevel--; EditorGUI.indentLevel--;
#if BAKE_ALL_BUTTON
// Check state
bool allBaked = true;
bool allUnbaked = true;
for (int i = 0; i < regions.Count; i++) {
allBaked &= baked[i];
allUnbaked &= !baked[i];
}
if (!allBaked && GUILayout.Button("Bake All")) {
for (int i = 0; i < regions.Count; i++) {
if (!baked[i]) {
baked[i] = true;
bakedObjects[i] = SpineEditorUtilities.BakeRegion(atlasAsset, regions[i]);
}
}
} else if (!allUnbaked && GUILayout.Button("Unbake All")) {
bool unbakeResult = EditorUtility.DisplayDialog("Delete All Baked Regions", "Are you sure you want to unbake all region prefabs? This cannot be undone.", "Yes", "Cancel");
switch (unbakeResult) {
case true:
//delete
for (int i = 0; i < regions.Count; i++) {
if (baked[i]) {
string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset);
string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath);
string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name);
string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeRegionName(regions[i]) + ".prefab").Replace("\\", "/");
AssetDatabase.DeleteAsset(bakedPrefabPath);
baked[i] = false;
}
}
break;
case false:
//do nothing
break;
}
}
#endif
} }
if (serializedObject.ApplyModifiedProperties() || if (serializedObject.ApplyModifiedProperties() ||
@ -174,4 +214,6 @@ public class AtlasAssetInspector : Editor {
asset.Reset(); asset.Reset();
} }
} }
}
} }

View File

@ -14,8 +14,9 @@ using UnityEditor.AnimatedValues;
using UnityEngine; using UnityEngine;
using Spine; using Spine;
[CustomEditor(typeof(SkeletonDataAsset))] namespace Spine.Unity {
public class SkeletonDataAssetInspector : Editor { [CustomEditor(typeof(SkeletonDataAsset))]
public class SkeletonDataAssetInspector : Editor {
static bool showAnimationStateData = true; static bool showAnimationStateData = true;
static bool showAnimationList = true; static bool showAnimationList = true;
static bool showSlotList = false; static bool showSlotList = false;
@ -31,9 +32,9 @@ public class SkeletonDataAssetInspector : Editor {
private SerializedProperty controller; private SerializedProperty controller;
#endif #endif
#if SPINE_TK2D #if SPINE_TK2D
private SerializedProperty spriteCollection; private SerializedProperty spriteCollection;
#endif #endif
private bool m_initialized = false; private bool m_initialized = false;
private SkeletonDataAsset m_skeletonDataAsset; private SkeletonDataAsset m_skeletonDataAsset;
@ -92,14 +93,14 @@ public class SkeletonDataAssetInspector : Editor {
serializedObject.Update(); serializedObject.Update();
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
#if !SPINE_TK2D #if !SPINE_TK2D
EditorGUILayout.PropertyField(atlasAssets, true); EditorGUILayout.PropertyField(atlasAssets, true);
#else #else
EditorGUI.BeginDisabledGroup(spriteCollection.objectReferenceValue != null); EditorGUI.BeginDisabledGroup(spriteCollection.objectReferenceValue != null);
EditorGUILayout.PropertyField(atlasAssets, true); EditorGUILayout.PropertyField(atlasAssets, true);
EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup();
EditorGUILayout.PropertyField(spriteCollection, true); EditorGUILayout.PropertyField(spriteCollection, true);
#endif #endif
EditorGUILayout.PropertyField(skeletonJSON); EditorGUILayout.PropertyField(skeletonJSON);
EditorGUILayout.PropertyField(scale); EditorGUILayout.PropertyField(scale);
if (EditorGUI.EndChangeCheck()) { if (EditorGUI.EndChangeCheck()) {
@ -974,4 +975,6 @@ public class SkeletonDataAssetInspector : Editor {
tex = this.m_previewUtility.EndStaticPreview(); tex = this.m_previewUtility.EndStaticPreview();
return tex; return tex;
} }
}
} }

View File

@ -28,14 +28,13 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
using System; using System;
using System.IO; using System.IO;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using Spine;
public class Menus { namespace Spine.Unity {
public static class Menus {
[MenuItem("Assets/Create/Spine Atlas")] [MenuItem("Assets/Create/Spine Atlas")]
static public void CreateAtlas () { static public void CreateAtlas () {
CreateAsset<AtlasAsset>("New Atlas"); CreateAsset<AtlasAsset>("New Atlas");
@ -81,4 +80,5 @@ public class Menus {
Selection.activeObject = gameObject; Selection.activeObject = gameObject;
EditorGUIUtility.PingObject(Selection.activeObject); EditorGUIUtility.PingObject(Selection.activeObject);
} }
}
} }

View File

@ -28,14 +28,15 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
using System; using System;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using Spine; using Spine;
[CustomEditor(typeof(SkeletonAnimation))] namespace Spine.Unity {
public class SkeletonAnimationInspector : SkeletonRendererInspector {
[CustomEditor(typeof(SkeletonAnimation))]
public class SkeletonAnimationInspector : SkeletonRendererInspector {
protected SerializedProperty animationName, loop, timeScale, autoReset; protected SerializedProperty animationName, loop, timeScale, autoReset;
protected bool m_isPrefab; protected bool m_isPrefab;
protected bool wasAnimationNameChanged; protected bool wasAnimationNameChanged;
@ -109,4 +110,5 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {
} }
} }
} }
}
} }

View File

@ -1,5 +1,3 @@
/***************************************************************************** /*****************************************************************************
* SkeletonAnimatorInspector created by Mitch Thompson * SkeletonAnimatorInspector created by Mitch Thompson
* Full irrevocable rights and permissions granted to Esoteric Software * Full irrevocable rights and permissions granted to Esoteric Software
@ -7,10 +5,10 @@
using System; using System;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using Spine;
[CustomEditor(typeof(SkeletonAnimator))] namespace Spine.Unity {
public class SkeletonAnimatorInspector : SkeletonRendererInspector { [CustomEditor(typeof(SkeletonAnimator))]
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
protected SerializedProperty layerMixModes; protected SerializedProperty layerMixModes;
protected bool isPrefab; protected bool isPrefab;
protected override void OnEnable () { protected override void OnEnable () {
@ -40,4 +38,5 @@ public class SkeletonAnimatorInspector : SkeletonRendererInspector {
} }
} }
} }
}
} }

View File

@ -33,8 +33,10 @@ using System;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
[CustomEditor(typeof(SkeletonRenderer))] namespace Spine.Unity {
public class SkeletonRendererInspector : Editor {
[CustomEditor(typeof(SkeletonRenderer))]
public class SkeletonRendererInspector : Editor {
protected static bool advancedFoldout; protected static bool advancedFoldout;
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, submeshSeparators, front, zSpacing; protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, submeshSeparators, front, zSpacing;
@ -140,11 +142,12 @@ public class SkeletonRendererInspector : Editor {
serializedObject.Update(); serializedObject.Update();
DrawInspectorGUI(); DrawInspectorGUI();
if (serializedObject.ApplyModifiedProperties() || if (serializedObject.ApplyModifiedProperties() ||
(Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
) { ) {
if (!Application.isPlaying) if (!Application.isPlaying)
((SkeletonRenderer)target).Initialize(true); ((SkeletonRenderer)target).Initialize(true);
} }
} }
}
} }

View File

@ -34,7 +34,8 @@ using System.Collections;
using UnityEditor; using UnityEditor;
using System.Reflection; using System.Reflection;
public static class SpineInspectorUtility { namespace Spine.Unity {
public static class SpineInspectorUtility {
#region Sorting Layer Field Helpers #region Sorting Layer Field Helpers
static readonly GUIContent SortingLayerLabel = new GUIContent("Sorting Layer"); static readonly GUIContent SortingLayerLabel = new GUIContent("Sorting Layer");
@ -89,4 +90,6 @@ public static class SpineInspectorUtility {
EditorGUILayout.PropertyField(m_SortingOrder, OrderInLayerLabel); EditorGUILayout.PropertyField(m_SortingOrder, OrderInLayerLabel);
} }
#endregion #endregion
}
} }

View File

@ -149,7 +149,7 @@ namespace Spine.Unity {
EditorGUIUtility.PingObject(Selection.activeObject); EditorGUIUtility.PingObject(Selection.activeObject);
} }
[MenuItem("Assets/Spine/Instantiate (UnityUI)", false, 0)] [MenuItem("Assets/Spine/Instantiate (UnityUI)", false, 10)]
static void InstantiateSkeletonGraphic () { static void InstantiateSkeletonGraphic () {
Object[] arr = Selection.objects; Object[] arr = Selection.objects;
foreach (Object o in arr) { foreach (Object o in arr) {
@ -161,7 +161,7 @@ namespace Spine.Unity {
} }
} }
[MenuItem("Assets/Spine/Instantiate (UnityUI)", true, 0)] [MenuItem("Assets/Spine/Instantiate (UnityUI)", true, 10)]
static bool ValidateInstantiateSkeletonGraphic () { static bool ValidateInstantiateSkeletonGraphic () {
Object[] arr = Selection.objects; Object[] arr = Selection.objects;

View File

@ -212,7 +212,7 @@ namespace Spine.Unity {
spineMeshGenerator.Scale = canvas.referencePixelsPerUnit; // TODO: move this to a listener to of the canvas? spineMeshGenerator.Scale = canvas.referencePixelsPerUnit; // TODO: move this to a listener to of the canvas?
canvasRenderer.SetMesh(spineMeshGenerator.GenerateMesh(skeleton)); canvasRenderer.SetMesh(spineMeshGenerator.GenerateMesh(skeleton));
this.UpdateMaterial(); //this.UpdateMaterial(); // TODO: This allocates memory.
} }
} }
#endregion #endregion