diff --git a/spine-unity/Assets/spine-unity/Asset Types/Editor/AtlasAssetInspector.cs b/spine-unity/Assets/spine-unity/Asset Types/Editor/AtlasAssetInspector.cs index 93bab1a35..93809a90e 100644 --- a/spine-unity/Assets/spine-unity/Asset Types/Editor/AtlasAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Asset Types/Editor/AtlasAssetInspector.cs @@ -28,126 +28,124 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ +//#define BAKE_ALL_BUTTON using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; using System.Reflection; using System.IO; using UnityEditor; using UnityEngine; using Spine; +namespace Spine.Unity { + + [CustomEditor(typeof(AtlasAsset))] + public class AtlasAssetInspector : Editor { + private SerializedProperty atlasFile, materials; + private AtlasAsset atlasAsset; + private List baked; + private List bakedObjects; -[CustomEditor(typeof(AtlasAsset))] -public class AtlasAssetInspector : Editor { - private SerializedProperty atlasFile, materials; - private AtlasAsset atlasAsset; - private List baked; - private List bakedObjects; + void OnEnable () { + SpineEditorUtilities.ConfirmInitialization(); + atlasFile = serializedObject.FindProperty("atlasFile"); + materials = serializedObject.FindProperty("materials"); + atlasAsset = (AtlasAsset)target; + UpdateBakedList(); + } - void OnEnable () { - SpineEditorUtilities.ConfirmInitialization(); - atlasFile = serializedObject.FindProperty("atlasFile"); - materials = serializedObject.FindProperty("materials"); - atlasAsset = (AtlasAsset)target; - UpdateBakedList(); - } - - void UpdateBakedList () { - AtlasAsset asset = (AtlasAsset)target; - baked = new List(); - bakedObjects = new List(); - if (atlasFile.objectReferenceValue != null) { - Atlas atlas = asset.GetAtlas(); - FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic); - List regions = (List)field.GetValue(atlas); - string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset); - string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath); - string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name); + void UpdateBakedList () { + AtlasAsset asset = (AtlasAsset)target; + baked = new List(); + bakedObjects = new List(); + if (atlasFile.objectReferenceValue != null) { + Atlas atlas = asset.GetAtlas(); + FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic); + List regions = (List)field.GetValue(atlas); + string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset); + string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath); + string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name); - for (int i = 0; i < regions.Count; i++) { - AtlasRegion region = regions[i]; - string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeRegionName(region) + ".prefab").Replace("\\", "/"); - GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject)); - baked.Add(prefab != null); - bakedObjects.Add(prefab); + for (int i = 0; i < regions.Count; i++) { + AtlasRegion region = regions[i]; + string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeRegionName(region) + ".prefab").Replace("\\", "/"); + GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject)); + baked.Add(prefab != null); + bakedObjects.Add(prefab); + } } } - } + override public void OnInspectorGUI () { + serializedObject.Update(); + AtlasAsset asset = (AtlasAsset)target; + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(atlasFile); + EditorGUILayout.PropertyField(materials, true); + if (EditorGUI.EndChangeCheck()) + serializedObject.ApplyModifiedProperties(); - override public void OnInspectorGUI () { - serializedObject.Update(); - AtlasAsset asset = (AtlasAsset)target; - - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(atlasFile); - EditorGUILayout.PropertyField(materials, true); - if (EditorGUI.EndChangeCheck()) - serializedObject.ApplyModifiedProperties(); - - if (materials.arraySize == 0) { - EditorGUILayout.LabelField(new GUIContent("Error: Missing materials", SpineEditorUtilities.Icons.warning)); - return; - } - - for (int i = 0; i < materials.arraySize; i++) { - SerializedProperty prop = materials.GetArrayElementAtIndex(i); - Material mat = (Material)prop.objectReferenceValue; - if (mat == null) { - EditorGUILayout.LabelField(new GUIContent("Error: Materials cannot be null", SpineEditorUtilities.Icons.warning)); + if (materials.arraySize == 0) { + EditorGUILayout.LabelField(new GUIContent("Error: Missing materials", SpineEditorUtilities.Icons.warning)); return; } - } - if (atlasFile.objectReferenceValue != null) { - Atlas atlas = asset.GetAtlas(); - FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic); - List regions = (List)field.GetValue(atlas); - EditorGUILayout.LabelField(new GUIContent("Region Baking", SpineEditorUtilities.Icons.unityIcon)); - EditorGUI.indentLevel++; - AtlasPage lastPage = null; - for (int i = 0; i < regions.Count; i++) { - if (lastPage != regions[i].page) { - if (lastPage != null) { - EditorGUILayout.Separator(); - EditorGUILayout.Separator(); - } - lastPage = regions[i].page; - Material mat = ((Material)lastPage.rendererObject); - if (mat != null) { - GUILayout.BeginHorizontal(); - { - EditorGUI.BeginDisabledGroup(true); - EditorGUILayout.ObjectField(mat, typeof(Material), false, GUILayout.Width(250)); - EditorGUI.EndDisabledGroup(); - } - GUILayout.EndHorizontal(); - - } else { - EditorGUILayout.LabelField(new GUIContent("Page missing material!", SpineEditorUtilities.Icons.warning)); - } + for (int i = 0; i < materials.arraySize; i++) { + SerializedProperty prop = materials.GetArrayElementAtIndex(i); + Material mat = (Material)prop.objectReferenceValue; + if (mat == null) { + EditorGUILayout.LabelField(new GUIContent("Error: Materials cannot be null", SpineEditorUtilities.Icons.warning)); + return; } - GUILayout.BeginHorizontal(); - { - //EditorGUILayout.ToggleLeft(baked[i] ? "" : regions[i].name, baked[i]); - bool result = baked[i] ? EditorGUILayout.ToggleLeft("", baked[i], GUILayout.Width(24)) : EditorGUILayout.ToggleLeft(" " + regions[i].name, baked[i]); - if(baked[i]){ - EditorGUILayout.ObjectField(bakedObjects[i], typeof(GameObject), false, GUILayout.Width(250)); + } + + if (atlasFile.objectReferenceValue != null) { + Atlas atlas = asset.GetAtlas(); + FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic); + List regions = (List)field.GetValue(atlas); + EditorGUILayout.LabelField(new GUIContent("Region Baking", SpineEditorUtilities.Icons.unityIcon)); + EditorGUI.indentLevel++; + AtlasPage lastPage = null; + for (int i = 0; i < regions.Count; i++) { + if (lastPage != regions[i].page) { + if (lastPage != null) { + EditorGUILayout.Separator(); + EditorGUILayout.Separator(); + } + lastPage = regions[i].page; + Material mat = ((Material)lastPage.rendererObject); + if (mat != null) { + GUILayout.BeginHorizontal(); + { + EditorGUI.BeginDisabledGroup(true); + EditorGUILayout.ObjectField(mat, typeof(Material), false, GUILayout.Width(250)); + EditorGUI.EndDisabledGroup(); + } + GUILayout.EndHorizontal(); + + } else { + EditorGUILayout.LabelField(new GUIContent("Page missing material!", SpineEditorUtilities.Icons.warning)); + } } - if (result && !baked[i]) { - //bake - baked[i] = true; - bakedObjects[i] = SpineEditorUtilities.BakeRegion(atlasAsset, regions[i]); - EditorGUIUtility.PingObject(bakedObjects[i]); - } else if (!result && baked[i]) { - //unbake - bool unbakeResult = EditorUtility.DisplayDialog("Delete Baked Region", "Do you want to delete the prefab for " + regions[i].name, "Yes", "Cancel"); - switch (unbakeResult) { + GUILayout.BeginHorizontal(); + { + //EditorGUILayout.ToggleLeft(baked[i] ? "" : regions[i].name, baked[i]); + bool result = baked[i] ? EditorGUILayout.ToggleLeft("", baked[i], GUILayout.Width(24)) : EditorGUILayout.ToggleLeft(" " + regions[i].name, baked[i]); + if(baked[i]){ + EditorGUILayout.ObjectField(bakedObjects[i], typeof(GameObject), false, GUILayout.Width(250)); + } + if (result && !baked[i]) { + //bake + baked[i] = true; + bakedObjects[i] = SpineEditorUtilities.BakeRegion(atlasAsset, regions[i]); + EditorGUIUtility.PingObject(bakedObjects[i]); + } else if (!result && baked[i]) { + //unbake + bool unbakeResult = EditorUtility.DisplayDialog("Delete Baked Region", "Do you want to delete the prefab for " + regions[i].name, "Yes", "Cancel"); + switch (unbakeResult) { case true: //delete string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset); @@ -160,18 +158,62 @@ public class AtlasAssetInspector : Editor { case false: //do nothing break; + } } } + GUILayout.EndHorizontal(); } - GUILayout.EndHorizontal(); - } - EditorGUI.indentLevel--; - } + EditorGUI.indentLevel--; - if (serializedObject.ApplyModifiedProperties() || - (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed") - ) { - asset.Reset(); + #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() || + (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed") + ) { + asset.Reset(); + } } } + } diff --git a/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs index 5784b6fc3..486315e57 100644 --- a/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs @@ -14,843 +14,844 @@ using UnityEditor.AnimatedValues; using UnityEngine; using Spine; -[CustomEditor(typeof(SkeletonDataAsset))] -public class SkeletonDataAssetInspector : Editor { - static bool showAnimationStateData = true; - static bool showAnimationList = true; - static bool showSlotList = false; - static bool showAttachments = false; - static bool showBaking = false; - static bool bakeAnimations = true; - static bool bakeIK = true; - static SendMessageOptions bakeEventOptions = SendMessageOptions.DontRequireReceiver; +namespace Spine.Unity { + [CustomEditor(typeof(SkeletonDataAsset))] + public class SkeletonDataAssetInspector : Editor { + static bool showAnimationStateData = true; + static bool showAnimationList = true; + static bool showSlotList = false; + static bool showAttachments = false; + static bool showBaking = false; + static bool bakeAnimations = true; + static bool bakeIK = true; + static SendMessageOptions bakeEventOptions = SendMessageOptions.DontRequireReceiver; - private SerializedProperty atlasAssets, skeletonJSON, scale, fromAnimation, toAnimation, duration, defaultMix; - #if SPINE_SKELETON_ANIMATOR - static bool showMecanim = false; - private SerializedProperty controller; - #endif + private SerializedProperty atlasAssets, skeletonJSON, scale, fromAnimation, toAnimation, duration, defaultMix; + #if SPINE_SKELETON_ANIMATOR + static bool showMecanim = false; + private SerializedProperty controller; + #endif -#if SPINE_TK2D - private SerializedProperty spriteCollection; -#endif + #if SPINE_TK2D + private SerializedProperty spriteCollection; + #endif - private bool m_initialized = false; - private SkeletonDataAsset m_skeletonDataAsset; - private SkeletonData m_skeletonData; - private string m_skeletonDataAssetGUID; - private bool needToSerialize; + private bool m_initialized = false; + private SkeletonDataAsset m_skeletonDataAsset; + private SkeletonData m_skeletonData; + private string m_skeletonDataAssetGUID; + private bool needToSerialize; - List warnings = new List(); - - void OnEnable () { + List warnings = new List(); - SpineEditorUtilities.ConfirmInitialization(); + void OnEnable () { - try { - atlasAssets = serializedObject.FindProperty("atlasAssets"); - skeletonJSON = serializedObject.FindProperty("skeletonJSON"); - scale = serializedObject.FindProperty("scale"); - fromAnimation = serializedObject.FindProperty("fromAnimation"); - toAnimation = serializedObject.FindProperty("toAnimation"); - duration = serializedObject.FindProperty("duration"); - defaultMix = serializedObject.FindProperty("defaultMix"); - #if SPINE_SKELETON_ANIMATOR - controller = serializedObject.FindProperty("controller"); - #endif - #if SPINE_TK2D - spriteCollection = serializedObject.FindProperty("spriteCollection"); - #endif + SpineEditorUtilities.ConfirmInitialization(); - m_skeletonDataAsset = (SkeletonDataAsset)target; - m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset)); + try { + atlasAssets = serializedObject.FindProperty("atlasAssets"); + skeletonJSON = serializedObject.FindProperty("skeletonJSON"); + scale = serializedObject.FindProperty("scale"); + fromAnimation = serializedObject.FindProperty("fromAnimation"); + toAnimation = serializedObject.FindProperty("toAnimation"); + duration = serializedObject.FindProperty("duration"); + defaultMix = serializedObject.FindProperty("defaultMix"); + #if SPINE_SKELETON_ANIMATOR + controller = serializedObject.FindProperty("controller"); + #endif + #if SPINE_TK2D + spriteCollection = serializedObject.FindProperty("spriteCollection"); + #endif - EditorApplication.update += Update; - } catch { - // TODO: WARNING: empty catch block supresses errors. + m_skeletonDataAsset = (SkeletonDataAsset)target; + m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset)); + EditorApplication.update += Update; + } catch { + // TODO: WARNING: empty catch block supresses errors. + + } + + m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true); + + showBaking = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", false); + + RepopulateWarnings(); } - m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true); - - showBaking = EditorPrefs.GetBool("SkeletonDataAssetInspector_showUnity", false); - - RepopulateWarnings(); - } - - void OnDestroy () { - m_initialized = false; - EditorApplication.update -= Update; - this.DestroyPreviewInstances(); - if (this.m_previewUtility != null) { - this.m_previewUtility.Cleanup(); - this.m_previewUtility = null; + void OnDestroy () { + m_initialized = false; + EditorApplication.update -= Update; + this.DestroyPreviewInstances(); + if (this.m_previewUtility != null) { + this.m_previewUtility.Cleanup(); + this.m_previewUtility = null; + } } - } - override public void OnInspectorGUI () { - serializedObject.Update(); + override public void OnInspectorGUI () { + serializedObject.Update(); - EditorGUI.BeginChangeCheck(); -#if !SPINE_TK2D - EditorGUILayout.PropertyField(atlasAssets, true); -#else - EditorGUI.BeginDisabledGroup(spriteCollection.objectReferenceValue != null); - EditorGUILayout.PropertyField(atlasAssets, true); - EditorGUI.EndDisabledGroup(); - EditorGUILayout.PropertyField(spriteCollection, true); -#endif - EditorGUILayout.PropertyField(skeletonJSON); - EditorGUILayout.PropertyField(scale); - if (EditorGUI.EndChangeCheck()) { - if (serializedObject.ApplyModifiedProperties()) { + EditorGUI.BeginChangeCheck(); + #if !SPINE_TK2D + EditorGUILayout.PropertyField(atlasAssets, true); + #else + EditorGUI.BeginDisabledGroup(spriteCollection.objectReferenceValue != null); + EditorGUILayout.PropertyField(atlasAssets, true); + EditorGUI.EndDisabledGroup(); + EditorGUILayout.PropertyField(spriteCollection, true); + #endif + EditorGUILayout.PropertyField(skeletonJSON); + EditorGUILayout.PropertyField(scale); + if (EditorGUI.EndChangeCheck()) { + if (serializedObject.ApplyModifiedProperties()) { - if (m_previewUtility != null) { - m_previewUtility.Cleanup(); - m_previewUtility = null; + if (m_previewUtility != null) { + m_previewUtility.Cleanup(); + m_previewUtility = null; + } + + RepopulateWarnings(); + OnEnable(); + return; } - RepopulateWarnings(); - OnEnable(); + } + + + if (m_skeletonData != null) { + DrawAnimationStateInfo(); + DrawAnimationList(); + DrawSlotList(); + DrawUnityTools(); + + } else { + + DrawReimportButton(); + //Show Warnings + foreach (var str in warnings) + EditorGUILayout.LabelField(new GUIContent(str, SpineEditorUtilities.Icons.warning)); + } + + if(!Application.isPlaying) + serializedObject.ApplyModifiedProperties(); + } + + void DrawUnityTools () { + #if SPINE_SKELETON_ANIMATOR + showMecanim = EditorGUILayout.Foldout(showMecanim, new GUIContent("SkeletonAnimator", SpineEditorUtilities.Icons.unityIcon)); + if (showMecanim) { + EditorGUI.indentLevel++; + EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon)); + if (controller.objectReferenceValue == null) { + GUILayout.BeginHorizontal(); + GUILayout.Space(32); + if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), GUILayout.Width(195), GUILayout.Height(20))) + SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset); + GUILayout.EndHorizontal(); + EditorGUILayout.LabelField("SkeletonAnimator is the Mecanim alternative to SkeletonAnimation. It is not required.", EditorStyles.miniLabel); + } else { + GUILayout.BeginHorizontal(); + GUILayout.Space(32); + if (GUILayout.Button(new GUIContent("Update Controller Animations"), GUILayout.Width(195), GUILayout.Height(20))) + SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset); + GUILayout.EndHorizontal(); + } + EditorGUI.indentLevel--; + } + #endif + + bool pre = showBaking; + showBaking = EditorGUILayout.Foldout(showBaking, new GUIContent("Baking", SpineEditorUtilities.Icons.unityIcon)); + if (pre != showBaking) + EditorPrefs.SetBool("SkeletonDataAssetInspector_showUnity", showBaking); + + if (showBaking) { + EditorGUI.indentLevel++; + EditorGUILayout.HelpBox("WARNING!\n\nBaking is NOT the same as SkeletonAnimator!\nDoes not support the following:\n\tFlipX or Y\n\tInheritScale\n\tColor Keys\n\tDraw Order Keys\n\tIK and Curves are sampled at 60fps and are not realtime.\n\tPlease read SkeletonBaker.cs comments for full details.\n\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)", MessageType.Warning, true); + EditorGUI.indentLevel++; + bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations); + EditorGUI.BeginDisabledGroup(!bakeAnimations); + { + EditorGUI.indentLevel++; + bakeIK = EditorGUILayout.Toggle("Bake IK", bakeIK); + bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions); + EditorGUI.indentLevel--; + } + EditorGUI.EndDisabledGroup(); + + EditorGUI.indentLevel++; + GUILayout.BeginHorizontal(); + { + + + if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150))) + SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions); + + string skinName = ""; + + if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null) { + + Skin bakeSkin = m_skeletonAnimation.skeleton.Skin; + if (bakeSkin == null) { + skinName = "Default"; + bakeSkin = m_skeletonData.Skins.Items[0]; + } else + skinName = m_skeletonAnimation.skeleton.Skin.Name; + + bool oops = false; + + try { + GUILayout.BeginVertical(); + if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250))) + SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions); + + GUILayout.BeginHorizontal(); + GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50)); + if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196))) { + SelectSkinContext(); + } + GUILayout.EndHorizontal(); + + + + } catch { + oops = true; + //GUILayout.BeginVertical(); + } + + + + if (!oops) + GUILayout.EndVertical(); + } + + } + GUILayout.EndHorizontal(); + EditorGUI.indentLevel--; + EditorGUI.indentLevel--; + } + + + } + + void DrawReimportButton () { + EditorGUI.BeginDisabledGroup(skeletonJSON.objectReferenceValue == null); + if (GUILayout.Button(new GUIContent("Attempt Reimport", SpineEditorUtilities.Icons.warning))) { + DoReimport(); + return; + } + EditorGUI.EndDisabledGroup(); + } + + void DoReimport () { + SpineEditorUtilities.ImportSpineContent(new string[] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true); + + if (m_previewUtility != null) { + m_previewUtility.Cleanup(); + m_previewUtility = null; + } + + RepopulateWarnings(); + OnEnable(); + + EditorUtility.SetDirty(m_skeletonDataAsset); + } + + void DrawAnimationStateInfo () { + showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data"); + if (!showAnimationStateData) + return; + + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(defaultMix); + + // Animation names + var animations = new string[m_skeletonData.Animations.Count]; + for (int i = 0; i < animations.Length; i++) + animations[i] = m_skeletonData.Animations.Items[i].Name; + + for (int i = 0; i < fromAnimation.arraySize; i++) { + SerializedProperty from = fromAnimation.GetArrayElementAtIndex(i); + SerializedProperty to = toAnimation.GetArrayElementAtIndex(i); + SerializedProperty durationProp = duration.GetArrayElementAtIndex(i); + EditorGUILayout.BeginHorizontal(); + from.stringValue = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, from.stringValue), 0), animations)]; + to.stringValue = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, to.stringValue), 0), animations)]; + durationProp.floatValue = EditorGUILayout.FloatField(durationProp.floatValue); + if (GUILayout.Button("Delete")) { + duration.DeleteArrayElementAtIndex(i); + toAnimation.DeleteArrayElementAtIndex(i); + fromAnimation.DeleteArrayElementAtIndex(i); + } + EditorGUILayout.EndHorizontal(); + } + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.Space(); + if (GUILayout.Button("Add Mix")) { + duration.arraySize++; + toAnimation.arraySize++; + fromAnimation.arraySize++; + } + EditorGUILayout.Space(); + EditorGUILayout.EndHorizontal(); + + if (EditorGUI.EndChangeCheck()) { + m_skeletonDataAsset.FillStateData(); + EditorUtility.SetDirty(m_skeletonDataAsset); + serializedObject.ApplyModifiedProperties(); + needToSerialize = true; + } + + } + void DrawAnimationList () { + showAnimationList = EditorGUILayout.Foldout(showAnimationList, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot)); + if (!showAnimationList) + return; + + if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) { + if (GUILayout.Button(new GUIContent("Setup Pose", SpineEditorUtilities.Icons.skeleton), GUILayout.Width(105), GUILayout.Height(18))) { + StopAnimation(); + m_skeletonAnimation.skeleton.SetToSetupPose(); + m_requireRefresh = true; + } + } else { + EditorGUILayout.HelpBox("Animations can be previewed if you expand the Preview window below.", MessageType.Info); + } + + EditorGUILayout.LabelField("Name", "Duration"); + foreach (Spine.Animation a in m_skeletonData.Animations) { + GUILayout.BeginHorizontal(); + + if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) { + if (m_skeletonAnimation.state.GetCurrent(0) != null && m_skeletonAnimation.state.GetCurrent(0).Animation == a) { + GUI.contentColor = Color.red; + if (GUILayout.Button("\u25BA", EditorStyles.toolbarButton, GUILayout.Width(24))) { + StopAnimation(); + } + GUI.contentColor = Color.white; + } else { + if (GUILayout.Button("\u25BA", EditorStyles.toolbarButton, GUILayout.Width(24))) { + PlayAnimation(a.Name, true); + } + } + } else { + GUILayout.Label("?", GUILayout.Width(24)); + } + EditorGUILayout.LabelField(new GUIContent(a.Name, SpineEditorUtilities.Icons.animation), new GUIContent(a.Duration.ToString("f3") + "s" + ("(" + (Mathf.RoundToInt(a.Duration * 30)) + ")").PadLeft(12, ' '))); + GUILayout.EndHorizontal(); + } + } + + + void DrawSlotList () { + showSlotList = EditorGUILayout.Foldout(showSlotList, new GUIContent("Slots", SpineEditorUtilities.Icons.slotRoot)); + + if (!showSlotList) + return; + + if (m_skeletonAnimation == null || m_skeletonAnimation.skeleton == null) + return; + + EditorGUI.indentLevel++; + try { + showAttachments = EditorGUILayout.ToggleLeft("Show Attachments", showAttachments); + } catch { return; } - } - - if (m_skeletonData != null) { - DrawAnimationStateInfo(); - DrawAnimationList(); - DrawSlotList(); - DrawUnityTools(); - - } else { - - DrawReimportButton(); - //Show Warnings - foreach (var str in warnings) - EditorGUILayout.LabelField(new GUIContent(str, SpineEditorUtilities.Icons.warning)); - } - - if(!Application.isPlaying) - serializedObject.ApplyModifiedProperties(); - } - - void DrawUnityTools () { - #if SPINE_SKELETON_ANIMATOR - showMecanim = EditorGUILayout.Foldout(showMecanim, new GUIContent("SkeletonAnimator", SpineEditorUtilities.Icons.unityIcon)); - if (showMecanim) { - EditorGUI.indentLevel++; - EditorGUILayout.PropertyField(controller, new GUIContent("Controller", SpineEditorUtilities.Icons.controllerIcon)); - if (controller.objectReferenceValue == null) { - GUILayout.BeginHorizontal(); - GUILayout.Space(32); - if (GUILayout.Button(new GUIContent("Generate Mecanim Controller"), GUILayout.Width(195), GUILayout.Height(20))) - SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset); - GUILayout.EndHorizontal(); - EditorGUILayout.LabelField("SkeletonAnimator is the Mecanim alternative to SkeletonAnimation. It is not required.", EditorStyles.miniLabel); - } else { - GUILayout.BeginHorizontal(); - GUILayout.Space(32); - if (GUILayout.Button(new GUIContent("Update Controller Animations"), GUILayout.Width(195), GUILayout.Height(20))) - SkeletonBaker.GenerateMecanimAnimationClips(m_skeletonDataAsset); - GUILayout.EndHorizontal(); + List slotAttachments = new List(); + List slotAttachmentNames = new List(); + List defaultSkinAttachmentNames = new List(); + var defaultSkin = m_skeletonData.Skins.Items[0]; + Skin skin = m_skeletonAnimation.skeleton.Skin; + if (skin == null) { + skin = defaultSkin; } - EditorGUI.indentLevel--; - } - #endif - bool pre = showBaking; - showBaking = EditorGUILayout.Foldout(showBaking, new GUIContent("Baking", SpineEditorUtilities.Icons.unityIcon)); - if (pre != showBaking) - EditorPrefs.SetBool("SkeletonDataAssetInspector_showUnity", showBaking); - - if (showBaking) { - EditorGUI.indentLevel++; - EditorGUILayout.HelpBox("WARNING!\n\nBaking is NOT the same as SkeletonAnimator!\nDoes not support the following:\n\tFlipX or Y\n\tInheritScale\n\tColor Keys\n\tDraw Order Keys\n\tIK and Curves are sampled at 60fps and are not realtime.\n\tPlease read SkeletonBaker.cs comments for full details.\n\nThe main use of Baking is to export Spine projects to be used without the Spine Runtime (ie: for sale on the Asset Store, or background objects that are animated only with a wind noise generator)", MessageType.Warning, true); - EditorGUI.indentLevel++; - bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations); - EditorGUI.BeginDisabledGroup(!bakeAnimations); - { - EditorGUI.indentLevel++; - bakeIK = EditorGUILayout.Toggle("Bake IK", bakeIK); - bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions); - EditorGUI.indentLevel--; - } - EditorGUI.EndDisabledGroup(); - - EditorGUI.indentLevel++; - GUILayout.BeginHorizontal(); - { + for (int i = m_skeletonAnimation.skeleton.Slots.Count - 1; i >= 0; i--) { + Slot slot = m_skeletonAnimation.skeleton.Slots.Items[i]; + EditorGUILayout.LabelField(new GUIContent(slot.Data.Name, SpineEditorUtilities.Icons.slot)); + if (showAttachments) { - if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150))) - SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions); + EditorGUI.indentLevel++; + slotAttachments.Clear(); + slotAttachmentNames.Clear(); + defaultSkinAttachmentNames.Clear(); - string skinName = ""; - - if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null) { - - Skin bakeSkin = m_skeletonAnimation.skeleton.Skin; - if (bakeSkin == null) { - skinName = "Default"; - bakeSkin = m_skeletonData.Skins.Items[0]; - } else - skinName = m_skeletonAnimation.skeleton.Skin.Name; - - bool oops = false; - - try { - GUILayout.BeginVertical(); - if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250))) - SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new ExposedList(new [] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions); - - GUILayout.BeginHorizontal(); - GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50)); - if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196))) { - SelectSkinContext(); - } - GUILayout.EndHorizontal(); + skin.FindNamesForSlot(i, slotAttachmentNames); + skin.FindAttachmentsForSlot(i, slotAttachments); - - } catch { - oops = true; - //GUILayout.BeginVertical(); - } - - - - if (!oops) - GUILayout.EndVertical(); - } - - } - GUILayout.EndHorizontal(); - EditorGUI.indentLevel--; - EditorGUI.indentLevel--; - } - - - } - - void DrawReimportButton () { - EditorGUI.BeginDisabledGroup(skeletonJSON.objectReferenceValue == null); - if (GUILayout.Button(new GUIContent("Attempt Reimport", SpineEditorUtilities.Icons.warning))) { - DoReimport(); - return; - } - EditorGUI.EndDisabledGroup(); - } - - void DoReimport () { - SpineEditorUtilities.ImportSpineContent(new string[] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true); - - if (m_previewUtility != null) { - m_previewUtility.Cleanup(); - m_previewUtility = null; - } - - RepopulateWarnings(); - OnEnable(); - - EditorUtility.SetDirty(m_skeletonDataAsset); - } - - void DrawAnimationStateInfo () { - showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data"); - if (!showAnimationStateData) - return; - - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(defaultMix); - - // Animation names - var animations = new string[m_skeletonData.Animations.Count]; - for (int i = 0; i < animations.Length; i++) - animations[i] = m_skeletonData.Animations.Items[i].Name; - - for (int i = 0; i < fromAnimation.arraySize; i++) { - SerializedProperty from = fromAnimation.GetArrayElementAtIndex(i); - SerializedProperty to = toAnimation.GetArrayElementAtIndex(i); - SerializedProperty durationProp = duration.GetArrayElementAtIndex(i); - EditorGUILayout.BeginHorizontal(); - from.stringValue = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, from.stringValue), 0), animations)]; - to.stringValue = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, to.stringValue), 0), animations)]; - durationProp.floatValue = EditorGUILayout.FloatField(durationProp.floatValue); - if (GUILayout.Button("Delete")) { - duration.DeleteArrayElementAtIndex(i); - toAnimation.DeleteArrayElementAtIndex(i); - fromAnimation.DeleteArrayElementAtIndex(i); - } - EditorGUILayout.EndHorizontal(); - } - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.Space(); - if (GUILayout.Button("Add Mix")) { - duration.arraySize++; - toAnimation.arraySize++; - fromAnimation.arraySize++; - } - EditorGUILayout.Space(); - EditorGUILayout.EndHorizontal(); - - if (EditorGUI.EndChangeCheck()) { - m_skeletonDataAsset.FillStateData(); - EditorUtility.SetDirty(m_skeletonDataAsset); - serializedObject.ApplyModifiedProperties(); - needToSerialize = true; - } - - } - void DrawAnimationList () { - showAnimationList = EditorGUILayout.Foldout(showAnimationList, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot)); - if (!showAnimationList) - return; - - if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) { - if (GUILayout.Button(new GUIContent("Setup Pose", SpineEditorUtilities.Icons.skeleton), GUILayout.Width(105), GUILayout.Height(18))) { - StopAnimation(); - m_skeletonAnimation.skeleton.SetToSetupPose(); - m_requireRefresh = true; - } - } else { - EditorGUILayout.HelpBox("Animations can be previewed if you expand the Preview window below.", MessageType.Info); - } - - EditorGUILayout.LabelField("Name", "Duration"); - foreach (Spine.Animation a in m_skeletonData.Animations) { - GUILayout.BeginHorizontal(); - - if (m_skeletonAnimation != null && m_skeletonAnimation.state != null) { - if (m_skeletonAnimation.state.GetCurrent(0) != null && m_skeletonAnimation.state.GetCurrent(0).Animation == a) { - GUI.contentColor = Color.red; - if (GUILayout.Button("\u25BA", EditorStyles.toolbarButton, GUILayout.Width(24))) { - StopAnimation(); - } - GUI.contentColor = Color.white; - } else { - if (GUILayout.Button("\u25BA", EditorStyles.toolbarButton, GUILayout.Width(24))) { - PlayAnimation(a.Name, true); - } - } - } else { - GUILayout.Label("?", GUILayout.Width(24)); - } - EditorGUILayout.LabelField(new GUIContent(a.Name, SpineEditorUtilities.Icons.animation), new GUIContent(a.Duration.ToString("f3") + "s" + ("(" + (Mathf.RoundToInt(a.Duration * 30)) + ")").PadLeft(12, ' '))); - GUILayout.EndHorizontal(); - } - } - - - void DrawSlotList () { - showSlotList = EditorGUILayout.Foldout(showSlotList, new GUIContent("Slots", SpineEditorUtilities.Icons.slotRoot)); - - if (!showSlotList) - return; - - if (m_skeletonAnimation == null || m_skeletonAnimation.skeleton == null) - return; - - EditorGUI.indentLevel++; - try { - showAttachments = EditorGUILayout.ToggleLeft("Show Attachments", showAttachments); - } catch { - return; - } - - - List slotAttachments = new List(); - List slotAttachmentNames = new List(); - List defaultSkinAttachmentNames = new List(); - var defaultSkin = m_skeletonData.Skins.Items[0]; - Skin skin = m_skeletonAnimation.skeleton.Skin; - if (skin == null) { - skin = defaultSkin; - } - - for (int i = m_skeletonAnimation.skeleton.Slots.Count - 1; i >= 0; i--) { - Slot slot = m_skeletonAnimation.skeleton.Slots.Items[i]; - EditorGUILayout.LabelField(new GUIContent(slot.Data.Name, SpineEditorUtilities.Icons.slot)); - if (showAttachments) { - - - EditorGUI.indentLevel++; - slotAttachments.Clear(); - slotAttachmentNames.Clear(); - defaultSkinAttachmentNames.Clear(); - - skin.FindNamesForSlot(i, slotAttachmentNames); - skin.FindAttachmentsForSlot(i, slotAttachments); - - - if (skin != defaultSkin) { - defaultSkin.FindNamesForSlot(i, defaultSkinAttachmentNames); - defaultSkin.FindNamesForSlot(i, slotAttachmentNames); - defaultSkin.FindAttachmentsForSlot(i, slotAttachments); - } else { - defaultSkin.FindNamesForSlot(i, defaultSkinAttachmentNames); - } - - - - for (int a = 0; a < slotAttachments.Count; a++) { - Attachment attachment = slotAttachments[a]; - string name = slotAttachmentNames[a]; - - Texture2D icon = null; - var type = attachment.GetType(); - - if (type == typeof(RegionAttachment)) - icon = SpineEditorUtilities.Icons.image; - else if (type == typeof(MeshAttachment)) - icon = SpineEditorUtilities.Icons.mesh; - else if (type == typeof(BoundingBoxAttachment)) - icon = SpineEditorUtilities.Icons.boundingBox; - else if (type == typeof(WeightedMeshAttachment)) - icon = SpineEditorUtilities.Icons.weights; - else - icon = SpineEditorUtilities.Icons.warning; - - //TODO: Waterboard Nate - //if (name != attachment.Name) - //icon = SpineEditorUtilities.Icons.skinPlaceholder; - - bool initialState = slot.Attachment == attachment; - - bool toggled = EditorGUILayout.ToggleLeft(new GUIContent(name, icon), slot.Attachment == attachment); - - if (!defaultSkinAttachmentNames.Contains(name)) { - Rect skinPlaceHolderIconRect = GUILayoutUtility.GetLastRect(); - skinPlaceHolderIconRect.width = SpineEditorUtilities.Icons.skinPlaceholder.width; - skinPlaceHolderIconRect.height = SpineEditorUtilities.Icons.skinPlaceholder.height; - GUI.DrawTexture(skinPlaceHolderIconRect, SpineEditorUtilities.Icons.skinPlaceholder); - } - - - if (toggled != initialState) { - if (toggled) { - slot.Attachment = attachment; - } else { - slot.Attachment = null; - } - m_requireRefresh = true; - } - } - - - EditorGUI.indentLevel--; - } - } - - EditorGUI.indentLevel--; - } - - - void RepopulateWarnings () { - warnings.Clear(); - - if (skeletonJSON.objectReferenceValue == null) - warnings.Add("Missing Skeleton JSON"); - else { - - if (SpineEditorUtilities.IsValidSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) { - warnings.Add("Skeleton data file is not a valid JSON or binary file."); - } else { - bool detectedNullAtlasEntry = false; - var atlasList = new List(); - for (int i = 0; i < atlasAssets.arraySize; i++) { - if (atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue == null) { - detectedNullAtlasEntry = true; - break; + if (skin != defaultSkin) { + defaultSkin.FindNamesForSlot(i, defaultSkinAttachmentNames); + defaultSkin.FindNamesForSlot(i, slotAttachmentNames); + defaultSkin.FindAttachmentsForSlot(i, slotAttachments); } else { - atlasList.Add(((AtlasAsset)atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue).GetAtlas()); + defaultSkin.FindNamesForSlot(i, defaultSkinAttachmentNames); } + + + + for (int a = 0; a < slotAttachments.Count; a++) { + Attachment attachment = slotAttachments[a]; + string name = slotAttachmentNames[a]; + + Texture2D icon = null; + var type = attachment.GetType(); + + if (type == typeof(RegionAttachment)) + icon = SpineEditorUtilities.Icons.image; + else if (type == typeof(MeshAttachment)) + icon = SpineEditorUtilities.Icons.mesh; + else if (type == typeof(BoundingBoxAttachment)) + icon = SpineEditorUtilities.Icons.boundingBox; + else if (type == typeof(WeightedMeshAttachment)) + icon = SpineEditorUtilities.Icons.weights; + else + icon = SpineEditorUtilities.Icons.warning; + + //TODO: Waterboard Nate + //if (name != attachment.Name) + //icon = SpineEditorUtilities.Icons.skinPlaceholder; + + bool initialState = slot.Attachment == attachment; + + bool toggled = EditorGUILayout.ToggleLeft(new GUIContent(name, icon), slot.Attachment == attachment); + + if (!defaultSkinAttachmentNames.Contains(name)) { + Rect skinPlaceHolderIconRect = GUILayoutUtility.GetLastRect(); + skinPlaceHolderIconRect.width = SpineEditorUtilities.Icons.skinPlaceholder.width; + skinPlaceHolderIconRect.height = SpineEditorUtilities.Icons.skinPlaceholder.height; + GUI.DrawTexture(skinPlaceHolderIconRect, SpineEditorUtilities.Icons.skinPlaceholder); + } + + + if (toggled != initialState) { + if (toggled) { + slot.Attachment = attachment; + } else { + slot.Attachment = null; + } + m_requireRefresh = true; + } + } + + + EditorGUI.indentLevel--; } + } - if (detectedNullAtlasEntry) - warnings.Add("AtlasAsset elements cannot be Null"); - else { - //get requirements - var missingPaths = SpineEditorUtilities.GetRequiredAtlasRegions(AssetDatabase.GetAssetPath((TextAsset)skeletonJSON.objectReferenceValue)); + EditorGUI.indentLevel--; + } - foreach (var atlas in atlasList) { - for (int i = 0; i < missingPaths.Count; i++) { - if (atlas.FindRegion(missingPaths[i]) != null) { - missingPaths.RemoveAt(i); - i--; + + void RepopulateWarnings () { + warnings.Clear(); + + if (skeletonJSON.objectReferenceValue == null) + warnings.Add("Missing Skeleton JSON"); + else { + + if (SpineEditorUtilities.IsValidSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) { + warnings.Add("Skeleton data file is not a valid JSON or binary file."); + } else { + bool detectedNullAtlasEntry = false; + var atlasList = new List(); + for (int i = 0; i < atlasAssets.arraySize; i++) { + if (atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue == null) { + detectedNullAtlasEntry = true; + break; + } else { + atlasList.Add(((AtlasAsset)atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue).GetAtlas()); + } + } + + if (detectedNullAtlasEntry) + warnings.Add("AtlasAsset elements cannot be Null"); + else { + //get requirements + var missingPaths = SpineEditorUtilities.GetRequiredAtlasRegions(AssetDatabase.GetAssetPath((TextAsset)skeletonJSON.objectReferenceValue)); + + foreach (var atlas in atlasList) { + for (int i = 0; i < missingPaths.Count; i++) { + if (atlas.FindRegion(missingPaths[i]) != null) { + missingPaths.RemoveAt(i); + i--; + } } } + + foreach (var str in missingPaths) + warnings.Add("Missing Region: '" + str + "'"); + + + + } + } + + + } + } + + //preview window stuff + private PreviewRenderUtility m_previewUtility; + private GameObject m_previewInstance; + private Vector2 previewDir; + private SkeletonAnimation m_skeletonAnimation; + //private SkeletonData m_skeletonData; + private static int sliderHash = "Slider".GetHashCode(); + private float m_lastTime; + private bool m_playing; + private bool m_requireRefresh; + private Color m_originColor = new Color(0.3f, 0.3f, 0.3f, 1); + + private void StopAnimation () { + if (m_skeletonAnimation == null) { + Debug.LogWarning("Animation was stopped but preview doesn't exist. It's possible that the Preview Panel is closed."); + } + + m_skeletonAnimation.state.ClearTrack(0); + m_playing = false; + } + + List m_animEvents = new List(); + List m_animEventFrames = new List(); + + private void PlayAnimation (string animName, bool loop) { + m_animEvents.Clear(); + m_animEventFrames.Clear(); + + m_skeletonAnimation.state.SetAnimation(0, animName, loop); + + Spine.Animation a = m_skeletonAnimation.state.GetCurrent(0).Animation; + foreach (Timeline t in a.Timelines) { + if (t.GetType() == typeof(EventTimeline)) { + EventTimeline et = (EventTimeline)t; + + for (int i = 0; i < et.Events.Length; i++) { + m_animEvents.Add(et.Events[i]); + m_animEventFrames.Add(et.Frames[i]); } - foreach (var str in missingPaths) - warnings.Add("Missing Region: '" + str + "'"); + } + } + + m_playing = true; + } + + private void InitPreview () { + if (this.m_previewUtility == null) { + this.m_lastTime = Time.realtimeSinceStartup; + this.m_previewUtility = new PreviewRenderUtility(true); + this.m_previewUtility.m_Camera.orthographic = true; + this.m_previewUtility.m_Camera.orthographicSize = 1; + this.m_previewUtility.m_Camera.cullingMask = -2147483648; + this.m_previewUtility.m_Camera.nearClipPlane = 0.01f; + this.m_previewUtility.m_Camera.farClipPlane = 1000f; + this.CreatePreviewInstances(); + } + } + + private void CreatePreviewInstances () { + this.DestroyPreviewInstances(); + if (this.m_previewInstance == null) { + try { + string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", ""); + + m_previewInstance = SpineEditorUtilities.InstantiateSkeletonAnimation((SkeletonDataAsset)target, skinName).gameObject; + m_previewInstance.hideFlags = HideFlags.HideAndDontSave; + m_previewInstance.layer = 0x1f; + m_skeletonAnimation = m_previewInstance.GetComponent(); + m_skeletonAnimation.initialSkinName = skinName; + m_skeletonAnimation.LateUpdate(); + m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true); + + m_previewInstance.GetComponent().enabled = false; + + m_initialized = true; + AdjustCameraGoals(true); + } catch { + // WARNING: Suppresses errors. + } + } + } + + private void DestroyPreviewInstances () { + if (this.m_previewInstance != null) { + DestroyImmediate(this.m_previewInstance); + m_previewInstance = null; + } + m_initialized = false; + } + + public override bool HasPreviewGUI () { + //TODO: validate json data + + for (int i = 0; i < atlasAssets.arraySize; i++) { + var prop = atlasAssets.GetArrayElementAtIndex(i); + if (prop.objectReferenceValue == null) + return false; + } + + return skeletonJSON.objectReferenceValue != null; + } + + Texture m_previewTex = new Texture(); + + public override void OnInteractivePreviewGUI (Rect r, GUIStyle background) { + this.InitPreview(); + + if (UnityEngine.Event.current.type == EventType.Repaint) { + if (m_requireRefresh) { + this.m_previewUtility.BeginPreview(r, background); + this.DoRenderPreview(true); + this.m_previewTex = this.m_previewUtility.EndPreview(); + m_requireRefresh = false; + } + if (this.m_previewTex != null) + GUI.DrawTexture(r, m_previewTex, ScaleMode.StretchToFill, false); + } + + DrawSkinToolbar(r); + NormalizedTimeBar(r); + //TODO: implement panning + // this.previewDir = Drag2D(this.previewDir, r); + MouseScroll(r); + } + + float m_orthoGoal = 1; + Vector3 m_posGoal = new Vector3(0, 0, -10); + double m_adjustFrameEndTime = 0; + + private void AdjustCameraGoals (bool calculateMixTime) { + if (this.m_previewInstance == null) + return; + + if (calculateMixTime) { + if (m_skeletonAnimation.state.GetCurrent(0) != null) { + m_adjustFrameEndTime = EditorApplication.timeSinceStartup + m_skeletonAnimation.state.GetCurrent(0).Mix; } } - } - } + GameObject go = this.m_previewInstance; - //preview window stuff - private PreviewRenderUtility m_previewUtility; - private GameObject m_previewInstance; - private Vector2 previewDir; - private SkeletonAnimation m_skeletonAnimation; - //private SkeletonData m_skeletonData; - private static int sliderHash = "Slider".GetHashCode(); - private float m_lastTime; - private bool m_playing; - private bool m_requireRefresh; - private Color m_originColor = new Color(0.3f, 0.3f, 0.3f, 1); + Bounds bounds = go.GetComponent().bounds; + m_orthoGoal = bounds.size.y; - private void StopAnimation () { - if (m_skeletonAnimation == null) { - Debug.LogWarning("Animation was stopped but preview doesn't exist. It's possible that the Preview Panel is closed."); + m_posGoal = bounds.center + new Vector3(0, 0, -10); } - m_skeletonAnimation.state.ClearTrack(0); - m_playing = false; - } + private void AdjustCameraGoals () { + AdjustCameraGoals(false); + } - List m_animEvents = new List(); - List m_animEventFrames = new List(); + private void AdjustCamera () { + if (m_previewUtility == null) + return; - private void PlayAnimation (string animName, bool loop) { - m_animEvents.Clear(); - m_animEventFrames.Clear(); - m_skeletonAnimation.state.SetAnimation(0, animName, loop); + if (EditorApplication.timeSinceStartup < m_adjustFrameEndTime) { + AdjustCameraGoals(); + } - Spine.Animation a = m_skeletonAnimation.state.GetCurrent(0).Animation; - foreach (Timeline t in a.Timelines) { - if (t.GetType() == typeof(EventTimeline)) { - EventTimeline et = (EventTimeline)t; + float orthoSet = Mathf.Lerp(this.m_previewUtility.m_Camera.orthographicSize, m_orthoGoal, 0.1f); - for (int i = 0; i < et.Events.Length; i++) { - m_animEvents.Add(et.Events[i]); - m_animEventFrames.Add(et.Frames[i]); + this.m_previewUtility.m_Camera.orthographicSize = orthoSet; + + float dist = Vector3.Distance(m_previewUtility.m_Camera.transform.position, m_posGoal); + if(dist > 0f) { + Vector3 pos = Vector3.Lerp(this.m_previewUtility.m_Camera.transform.position, m_posGoal, 0.1f); + pos.x = 0; + this.m_previewUtility.m_Camera.transform.position = pos; + this.m_previewUtility.m_Camera.transform.rotation = Quaternion.identity; + m_requireRefresh = true; + } + } + + private void DoRenderPreview (bool drawHandles) { + GameObject go = this.m_previewInstance; + + if (m_requireRefresh && go != null) { + go.GetComponent().enabled = true; + + if (EditorApplication.isPlaying) { + //do nothing + } else { + m_skeletonAnimation.Update((Time.realtimeSinceStartup - m_lastTime)); } + m_lastTime = Time.realtimeSinceStartup; + + if (!EditorApplication.isPlaying) + m_skeletonAnimation.LateUpdate(); + + + + if (drawHandles) { + Handles.SetCamera(m_previewUtility.m_Camera); + Handles.color = m_originColor; + + Handles.DrawLine(new Vector3(-1000 * m_skeletonDataAsset.scale, 0, 0), new Vector3(1000 * m_skeletonDataAsset.scale, 0, 0)); + Handles.DrawLine(new Vector3(0, 1000 * m_skeletonDataAsset.scale, 0), new Vector3(0, -1000 * m_skeletonDataAsset.scale, 0)); + } + + this.m_previewUtility.m_Camera.Render(); + + if (drawHandles) { + Handles.SetCamera(m_previewUtility.m_Camera); + foreach (var slot in m_skeletonAnimation.skeleton.Slots) { + var boundingBoxAttachment = slot.Attachment as BoundingBoxAttachment; + + if (boundingBoxAttachment != null) { + DrawBoundingBox (slot.Bone, boundingBoxAttachment); + } + } + } + + go.GetComponent().enabled = false; } + + } - m_playing = true; - } + static void DrawBoundingBox (Bone bone, BoundingBoxAttachment box) { + if (box.Vertices.Length <= 0) return; // Handle cases where user creates a BoundingBoxAttachment but doesn't actually define it. - private void InitPreview () { - if (this.m_previewUtility == null) { - this.m_lastTime = Time.realtimeSinceStartup; - this.m_previewUtility = new PreviewRenderUtility(true); - this.m_previewUtility.m_Camera.orthographic = true; - this.m_previewUtility.m_Camera.orthographicSize = 1; - this.m_previewUtility.m_Camera.cullingMask = -2147483648; - this.m_previewUtility.m_Camera.nearClipPlane = 0.01f; - this.m_previewUtility.m_Camera.farClipPlane = 1000f; - this.CreatePreviewInstances(); - } - } + var worldVerts = new float[box.Vertices.Length]; + box.ComputeWorldVertices(bone, worldVerts); - private void CreatePreviewInstances () { - this.DestroyPreviewInstances(); - if (this.m_previewInstance == null) { - try { - string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", ""); + Handles.color = Color.green; + Vector3 lastVert = Vector3.back; + Vector3 vert = Vector3.back; + Vector3 firstVert = new Vector3(worldVerts[0], worldVerts[1], -1); + for (int i = 0; i < worldVerts.Length; i += 2) { + vert.x = worldVerts[i]; + vert.y = worldVerts[i + 1]; - m_previewInstance = SpineEditorUtilities.InstantiateSkeletonAnimation((SkeletonDataAsset)target, skinName).gameObject; - m_previewInstance.hideFlags = HideFlags.HideAndDontSave; - m_previewInstance.layer = 0x1f; + if (i > 0) { + Handles.DrawLine(lastVert, vert); + } - - m_skeletonAnimation = m_previewInstance.GetComponent(); - m_skeletonAnimation.initialSkinName = skinName; - m_skeletonAnimation.LateUpdate(); - - m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true); - - m_previewInstance.GetComponent().enabled = false; - - m_initialized = true; - AdjustCameraGoals(true); - } catch { - // WARNING: Suppresses errors. + lastVert = vert; } - } - } - private void DestroyPreviewInstances () { - if (this.m_previewInstance != null) { - DestroyImmediate(this.m_previewInstance); - m_previewInstance = null; - } - m_initialized = false; - } + Handles.DrawLine(lastVert, firstVert); - public override bool HasPreviewGUI () { - //TODO: validate json data - - for (int i = 0; i < atlasAssets.arraySize; i++) { - var prop = atlasAssets.GetArrayElementAtIndex(i); - if (prop.objectReferenceValue == null) - return false; } - return skeletonJSON.objectReferenceValue != null; - } + void Update () { + AdjustCamera(); - Texture m_previewTex = new Texture(); - - public override void OnInteractivePreviewGUI (Rect r, GUIStyle background) { - this.InitPreview(); - - if (UnityEngine.Event.current.type == EventType.Repaint) { - if (m_requireRefresh) { - this.m_previewUtility.BeginPreview(r, background); - this.DoRenderPreview(true); - this.m_previewTex = this.m_previewUtility.EndPreview(); - m_requireRefresh = false; - } - if (this.m_previewTex != null) - GUI.DrawTexture(r, m_previewTex, ScaleMode.StretchToFill, false); - } - - DrawSkinToolbar(r); - NormalizedTimeBar(r); - //TODO: implement panning - // this.previewDir = Drag2D(this.previewDir, r); - MouseScroll(r); - } - - float m_orthoGoal = 1; - Vector3 m_posGoal = new Vector3(0, 0, -10); - double m_adjustFrameEndTime = 0; - - private void AdjustCameraGoals (bool calculateMixTime) { - if (this.m_previewInstance == null) - return; - - if (calculateMixTime) { - if (m_skeletonAnimation.state.GetCurrent(0) != null) { - m_adjustFrameEndTime = EditorApplication.timeSinceStartup + m_skeletonAnimation.state.GetCurrent(0).Mix; - } - } - - - GameObject go = this.m_previewInstance; - - Bounds bounds = go.GetComponent().bounds; - m_orthoGoal = bounds.size.y; - - m_posGoal = bounds.center + new Vector3(0, 0, -10); - } - - private void AdjustCameraGoals () { - AdjustCameraGoals(false); - } - - private void AdjustCamera () { - if (m_previewUtility == null) - return; - - - if (EditorApplication.timeSinceStartup < m_adjustFrameEndTime) { - AdjustCameraGoals(); - } - - float orthoSet = Mathf.Lerp(this.m_previewUtility.m_Camera.orthographicSize, m_orthoGoal, 0.1f); - - this.m_previewUtility.m_Camera.orthographicSize = orthoSet; - - float dist = Vector3.Distance(m_previewUtility.m_Camera.transform.position, m_posGoal); - if(dist > 0f) { - Vector3 pos = Vector3.Lerp(this.m_previewUtility.m_Camera.transform.position, m_posGoal, 0.1f); - pos.x = 0; - this.m_previewUtility.m_Camera.transform.position = pos; - this.m_previewUtility.m_Camera.transform.rotation = Quaternion.identity; - m_requireRefresh = true; - } - } - - private void DoRenderPreview (bool drawHandles) { - GameObject go = this.m_previewInstance; - - if (m_requireRefresh && go != null) { - go.GetComponent().enabled = true; - - if (EditorApplication.isPlaying) { - //do nothing + if (m_playing) { + m_requireRefresh = true; + Repaint(); + } else if (m_requireRefresh) { + Repaint(); } else { - m_skeletonAnimation.Update((Time.realtimeSinceStartup - m_lastTime)); + //only needed if using smooth menus } - m_lastTime = Time.realtimeSinceStartup; - - if (!EditorApplication.isPlaying) - m_skeletonAnimation.LateUpdate(); - - - - if (drawHandles) { - Handles.SetCamera(m_previewUtility.m_Camera); - Handles.color = m_originColor; - - Handles.DrawLine(new Vector3(-1000 * m_skeletonDataAsset.scale, 0, 0), new Vector3(1000 * m_skeletonDataAsset.scale, 0, 0)); - Handles.DrawLine(new Vector3(0, 1000 * m_skeletonDataAsset.scale, 0), new Vector3(0, -1000 * m_skeletonDataAsset.scale, 0)); + if (needToSerialize) { + needToSerialize = false; + serializedObject.ApplyModifiedProperties(); } + } - this.m_previewUtility.m_Camera.Render(); + void DrawSkinToolbar (Rect r) { + if (m_skeletonAnimation == null) + return; - if (drawHandles) { - Handles.SetCamera(m_previewUtility.m_Camera); - foreach (var slot in m_skeletonAnimation.skeleton.Slots) { - var boundingBoxAttachment = slot.Attachment as BoundingBoxAttachment; + if (m_skeletonAnimation.skeleton != null) { + string label = (m_skeletonAnimation.skeleton != null && m_skeletonAnimation.skeleton.Skin != null) ? m_skeletonAnimation.skeleton.Skin.Name : "default"; - if (boundingBoxAttachment != null) { - DrawBoundingBox (slot.Bone, boundingBoxAttachment); - } + Rect popRect = new Rect(r); + popRect.y += 32; + popRect.x += 4; + popRect.height = 24; + popRect.width = 40; + EditorGUI.DropShadowLabel(popRect, new GUIContent("Skin", SpineEditorUtilities.Icons.skinsRoot)); + + popRect.y += 11; + popRect.width = 150; + popRect.x += 44; + + if (GUI.Button(popRect, label, EditorStyles.popup)) { + SelectSkinContext(); } } - - go.GetComponent().enabled = false; } + void SelectSkinContext () { + GenericMenu menu = new GenericMenu(); - } - - static void DrawBoundingBox (Bone bone, BoundingBoxAttachment box) { - if (box.Vertices.Length <= 0) return; // Handle cases where user creates a BoundingBoxAttachment but doesn't actually define it. - - var worldVerts = new float[box.Vertices.Length]; - box.ComputeWorldVertices(bone, worldVerts); - - Handles.color = Color.green; - Vector3 lastVert = Vector3.back; - Vector3 vert = Vector3.back; - Vector3 firstVert = new Vector3(worldVerts[0], worldVerts[1], -1); - for (int i = 0; i < worldVerts.Length; i += 2) { - vert.x = worldVerts[i]; - vert.y = worldVerts[i + 1]; - - if (i > 0) { - Handles.DrawLine(lastVert, vert); + foreach (Skin s in m_skeletonData.Skins) { + menu.AddItem(new GUIContent(s.Name), this.m_skeletonAnimation.skeleton.Skin == s, SetSkin, (object)s); } - - lastVert = vert; + + menu.ShowAsContext(); } - Handles.DrawLine(lastVert, firstVert); - - } + void SetSkin (object o) { + Skin skin = (Skin)o; - void Update () { - AdjustCamera(); - - if (m_playing) { + m_skeletonAnimation.initialSkinName = skin.Name; + m_skeletonAnimation.Initialize(true); m_requireRefresh = true; - Repaint(); - } else if (m_requireRefresh) { - Repaint(); - } else { - //only needed if using smooth menus + + EditorPrefs.SetString(m_skeletonDataAssetGUID + "_lastSkin", skin.Name); } - if (needToSerialize) { - needToSerialize = false; - serializedObject.ApplyModifiedProperties(); - } - } + void NormalizedTimeBar (Rect r) { + if (m_skeletonAnimation == null) + return; - void DrawSkinToolbar (Rect r) { - if (m_skeletonAnimation == null) - return; + Rect barRect = new Rect(r); + barRect.height = 32; + barRect.x += 4; + barRect.width -= 4; - if (m_skeletonAnimation.skeleton != null) { - string label = (m_skeletonAnimation.skeleton != null && m_skeletonAnimation.skeleton.Skin != null) ? m_skeletonAnimation.skeleton.Skin.Name : "default"; + GUI.Box(barRect, ""); - Rect popRect = new Rect(r); - popRect.y += 32; - popRect.x += 4; - popRect.height = 24; - popRect.width = 40; - EditorGUI.DropShadowLabel(popRect, new GUIContent("Skin", SpineEditorUtilities.Icons.skinsRoot)); + Rect lineRect = new Rect(barRect); + float width = lineRect.width; + TrackEntry t = m_skeletonAnimation.state.GetCurrent(0); - popRect.y += 11; - popRect.width = 150; - popRect.x += 44; + if (t != null) { + int loopCount = (int)(t.Time / t.EndTime); + float currentTime = t.Time - (t.EndTime * loopCount); - if (GUI.Button(popRect, label, EditorStyles.popup)) { - SelectSkinContext(); - } - } - } + float normalizedTime = currentTime / t.Animation.Duration; - void SelectSkinContext () { - GenericMenu menu = new GenericMenu(); + lineRect.x = barRect.x + (width * normalizedTime) - 0.5f; + lineRect.width = 2; - foreach (Skin s in m_skeletonData.Skins) { - menu.AddItem(new GUIContent(s.Name), this.m_skeletonAnimation.skeleton.Skin == s, SetSkin, (object)s); - } + GUI.color = Color.red; + GUI.DrawTexture(lineRect, EditorGUIUtility.whiteTexture); + GUI.color = Color.white; - menu.ShowAsContext(); - } + for (int i = 0; i < m_animEvents.Count; i++) { + //TODO: Tooltip + //Spine.Event spev = animEvents[i]; - void SetSkin (object o) { - Skin skin = (Skin)o; + float fr = m_animEventFrames[i]; - m_skeletonAnimation.initialSkinName = skin.Name; - m_skeletonAnimation.Initialize(true); - m_requireRefresh = true; - - EditorPrefs.SetString(m_skeletonDataAssetGUID + "_lastSkin", skin.Name); - } - - void NormalizedTimeBar (Rect r) { - if (m_skeletonAnimation == null) - return; - - Rect barRect = new Rect(r); - barRect.height = 32; - barRect.x += 4; - barRect.width -= 4; - - GUI.Box(barRect, ""); - - Rect lineRect = new Rect(barRect); - float width = lineRect.width; - TrackEntry t = m_skeletonAnimation.state.GetCurrent(0); - - if (t != null) { - int loopCount = (int)(t.Time / t.EndTime); - float currentTime = t.Time - (t.EndTime * loopCount); - - float normalizedTime = currentTime / t.Animation.Duration; - - lineRect.x = barRect.x + (width * normalizedTime) - 0.5f; - lineRect.width = 2; - - GUI.color = Color.red; - GUI.DrawTexture(lineRect, EditorGUIUtility.whiteTexture); - GUI.color = Color.white; - - for (int i = 0; i < m_animEvents.Count; i++) { - //TODO: Tooltip - //Spine.Event spev = animEvents[i]; - - float fr = m_animEventFrames[i]; - - var evRect = new Rect(barRect); - evRect.x = Mathf.Clamp(((fr / t.Animation.Duration) * width) - (SpineEditorUtilities.Icons._event.width / 2), barRect.x, float.MaxValue); - evRect.width = SpineEditorUtilities.Icons._event.width; - evRect.height = SpineEditorUtilities.Icons._event.height; - evRect.y += SpineEditorUtilities.Icons._event.height; - GUI.DrawTexture(evRect, SpineEditorUtilities.Icons._event); + var evRect = new Rect(barRect); + evRect.x = Mathf.Clamp(((fr / t.Animation.Duration) * width) - (SpineEditorUtilities.Icons._event.width / 2), barRect.x, float.MaxValue); + evRect.width = SpineEditorUtilities.Icons._event.width; + evRect.height = SpineEditorUtilities.Icons._event.height; + evRect.y += SpineEditorUtilities.Icons._event.height; + GUI.DrawTexture(evRect, SpineEditorUtilities.Icons._event); - //TODO: Tooltip - /* + //TODO: Tooltip + /* UnityEngine.Event ev = UnityEngine.Event.current; if(ev.isMouse){ if(evRect.Contains(ev.mousePosition)){ @@ -862,15 +863,15 @@ public class SkeletonDataAssetInspector : Editor { } } */ + } } } - } - void MouseScroll (Rect position) { - UnityEngine.Event current = UnityEngine.Event.current; - int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive); + void MouseScroll (Rect position) { + UnityEngine.Event current = UnityEngine.Event.current; + int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive); - switch (current.GetTypeForControl(controlID)) { + switch (current.GetTypeForControl(controlID)) { case EventType.ScrollWheel: if (position.Contains(current.mousePosition)) { @@ -880,12 +881,12 @@ public class SkeletonDataAssetInspector : Editor { current.Use(); } break; + } + } - } - - //TODO: Implement preview panning - /* + //TODO: Implement preview panning + /* static Vector2 Drag2D(Vector2 scrollPosition, Rect position) { int controlID = GUIUtility.GetControlID(sliderHash, FocusType.Passive); @@ -926,52 +927,54 @@ public class SkeletonDataAssetInspector : Editor { } */ - public override GUIContent GetPreviewTitle () { - return new GUIContent("Preview"); - } + public override GUIContent GetPreviewTitle () { + return new GUIContent("Preview"); + } - public override void OnPreviewSettings () { - if (!m_initialized) { - GUILayout.HorizontalSlider(0, 0, 2, GUILayout.MaxWidth(64)); - } else { - float speed = GUILayout.HorizontalSlider(m_skeletonAnimation.timeScale, 0, 2, GUILayout.MaxWidth(64)); + public override void OnPreviewSettings () { + if (!m_initialized) { + GUILayout.HorizontalSlider(0, 0, 2, GUILayout.MaxWidth(64)); + } else { + float speed = GUILayout.HorizontalSlider(m_skeletonAnimation.timeScale, 0, 2, GUILayout.MaxWidth(64)); - //snap to nearest 0.25 - float y = speed / 0.25f; - int q = Mathf.RoundToInt(y); - speed = q * 0.25f; + //snap to nearest 0.25 + float y = speed / 0.25f; + int q = Mathf.RoundToInt(y); + speed = q * 0.25f; - m_skeletonAnimation.timeScale = speed; + m_skeletonAnimation.timeScale = speed; + } + } + + //TODO: Fix first-import error + //TODO: Update preview without thumbnail + public override Texture2D RenderStaticPreview (string assetPath, UnityEngine.Object[] subAssets, int width, int height) { + var tex = new Texture2D(width, height, TextureFormat.ARGB32, false); + + this.InitPreview(); + + if (this.m_previewUtility.m_Camera == null) + return null; + + m_requireRefresh = true; + this.DoRenderPreview(false); + AdjustCameraGoals(false); + + this.m_previewUtility.m_Camera.orthographicSize = m_orthoGoal / 2; + this.m_previewUtility.m_Camera.transform.position = m_posGoal; + this.m_previewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); + this.DoRenderPreview(false); + + //TODO: Figure out why this is throwing errors on first attempt + // if(m_previewUtility != null){ + // Handles.SetCamera(this.m_previewUtility.m_Camera); + // Handles.BeginGUI(); + // GUI.DrawTexture(new Rect(40,60,width,height), SpineEditorUtilities.Icons.spine, ScaleMode.StretchToFill); + // Handles.EndGUI(); + // } + tex = this.m_previewUtility.EndStaticPreview(); + return tex; } } - - //TODO: Fix first-import error - //TODO: Update preview without thumbnail - public override Texture2D RenderStaticPreview (string assetPath, UnityEngine.Object[] subAssets, int width, int height) { - var tex = new Texture2D(width, height, TextureFormat.ARGB32, false); - - this.InitPreview(); - - if (this.m_previewUtility.m_Camera == null) - return null; - - m_requireRefresh = true; - this.DoRenderPreview(false); - AdjustCameraGoals(false); - - this.m_previewUtility.m_Camera.orthographicSize = m_orthoGoal / 2; - this.m_previewUtility.m_Camera.transform.position = m_posGoal; - this.m_previewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); - this.DoRenderPreview(false); - - //TODO: Figure out why this is throwing errors on first attempt - // if(m_previewUtility != null){ - // Handles.SetCamera(this.m_previewUtility.m_Camera); - // Handles.BeginGUI(); - // GUI.DrawTexture(new Rect(40,60,width,height), SpineEditorUtilities.Icons.spine, ScaleMode.StretchToFill); - // Handles.EndGUI(); - // } - tex = this.m_previewUtility.EndStaticPreview(); - return tex; - } -} + +} \ No newline at end of file diff --git a/spine-unity/Assets/spine-unity/Editor/Menus.cs b/spine-unity/Assets/spine-unity/Editor/Menus.cs index 5e4def1d5..95685419e 100644 --- a/spine-unity/Assets/spine-unity/Editor/Menus.cs +++ b/spine-unity/Assets/spine-unity/Editor/Menus.cs @@ -28,57 +28,57 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ - using System; using System.IO; using UnityEditor; using UnityEngine; -using Spine; -public class Menus { - [MenuItem("Assets/Create/Spine Atlas")] - static public void CreateAtlas () { - CreateAsset("New Atlas"); - } - - [MenuItem("Assets/Create/Spine SkeletonData")] - static public void CreateSkeletonData () { - CreateAsset("New SkeletonData"); - } - - static private void CreateAsset (String name) where T : ScriptableObject { - var dir = "Assets/"; - var selected = Selection.activeObject; - if (selected != null) { - var assetDir = AssetDatabase.GetAssetPath(selected.GetInstanceID()); - if (assetDir.Length > 0 && Directory.Exists(assetDir)) - dir = assetDir + "/"; +namespace Spine.Unity { + public static class Menus { + [MenuItem("Assets/Create/Spine Atlas")] + static public void CreateAtlas () { + CreateAsset("New Atlas"); } - ScriptableObject asset = ScriptableObject.CreateInstance(); - AssetDatabase.CreateAsset(asset, dir + name + ".asset"); - AssetDatabase.SaveAssets(); - EditorUtility.FocusProjectWindow(); - Selection.activeObject = asset; - } - [MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)] - static public void CreateSkeletonRendererGameObject () { - CreateSpineGameObject("New SkeletonRenderer"); - } + [MenuItem("Assets/Create/Spine SkeletonData")] + static public void CreateSkeletonData () { + CreateAsset("New SkeletonData"); + } - [MenuItem("GameObject/Spine/SkeletonAnimation", false, 10)] - static public void CreateSkeletonAnimationGameObject () { - CreateSpineGameObject("New SkeletonAnimation"); - } + static private void CreateAsset (String name) where T : ScriptableObject { + var dir = "Assets/"; + var selected = Selection.activeObject; + if (selected != null) { + var assetDir = AssetDatabase.GetAssetPath(selected.GetInstanceID()); + if (assetDir.Length > 0 && Directory.Exists(assetDir)) + dir = assetDir + "/"; + } + ScriptableObject asset = ScriptableObject.CreateInstance(); + AssetDatabase.CreateAsset(asset, dir + name + ".asset"); + AssetDatabase.SaveAssets(); + EditorUtility.FocusProjectWindow(); + Selection.activeObject = asset; + } - static public void CreateSpineGameObject (string name) where T : MonoBehaviour { - var parentGameObject = Selection.activeObject as GameObject; - var parentTransform = parentGameObject == null ? null : parentGameObject.transform; + [MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)] + static public void CreateSkeletonRendererGameObject () { + CreateSpineGameObject("New SkeletonRenderer"); + } - var gameObject = new GameObject("New SkeletonRenderer", typeof(T)); - gameObject.transform.SetParent(parentTransform, false); - EditorUtility.FocusProjectWindow(); - Selection.activeObject = gameObject; - EditorGUIUtility.PingObject(Selection.activeObject); + [MenuItem("GameObject/Spine/SkeletonAnimation", false, 10)] + static public void CreateSkeletonAnimationGameObject () { + CreateSpineGameObject("New SkeletonAnimation"); + } + + static public void CreateSpineGameObject (string name) where T : MonoBehaviour { + var parentGameObject = Selection.activeObject as GameObject; + var parentTransform = parentGameObject == null ? null : parentGameObject.transform; + + var gameObject = new GameObject("New SkeletonRenderer", typeof(T)); + gameObject.transform.SetParent(parentTransform, false); + EditorUtility.FocusProjectWindow(); + Selection.activeObject = gameObject; + EditorGUIUtility.PingObject(Selection.activeObject); + } } } diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs index 90b935b36..33c59c65c 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimationInspector.cs @@ -28,83 +28,85 @@ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ - using System; using UnityEditor; using UnityEngine; using Spine; -[CustomEditor(typeof(SkeletonAnimation))] -public class SkeletonAnimationInspector : SkeletonRendererInspector { - protected SerializedProperty animationName, loop, timeScale, autoReset; - protected bool m_isPrefab; - protected bool wasAnimationNameChanged; +namespace Spine.Unity { + + [CustomEditor(typeof(SkeletonAnimation))] + public class SkeletonAnimationInspector : SkeletonRendererInspector { + protected SerializedProperty animationName, loop, timeScale, autoReset; + protected bool m_isPrefab; + protected bool wasAnimationNameChanged; - protected override void OnEnable () { - base.OnEnable(); - animationName = serializedObject.FindProperty("_animationName"); - loop = serializedObject.FindProperty("loop"); - timeScale = serializedObject.FindProperty("timeScale"); + protected override void OnEnable () { + base.OnEnable(); + animationName = serializedObject.FindProperty("_animationName"); + loop = serializedObject.FindProperty("loop"); + timeScale = serializedObject.FindProperty("timeScale"); - if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) - m_isPrefab = true; - } - - protected override void DrawInspectorGUI () { - base.DrawInspectorGUI(); - - SkeletonAnimation component = (SkeletonAnimation)target; - if (!component.valid) - return; - - if (wasAnimationNameChanged) { - if (!Application.isPlaying) { - if (component.state != null) component.state.ClearTrack(0); - component.skeleton.SetToSetupPose(); - } - - Spine.Animation animationToUse = component.skeleton.Data.FindAnimation(animationName.stringValue); - - if (!Application.isPlaying) { - if (animationToUse != null) animationToUse.Apply(component.skeleton, 0f, 0f, false, null); - component.Update(); - component.LateUpdate(); - SceneView.RepaintAll(); - } else { - if (animationToUse != null) - component.state.SetAnimation(0, animationToUse, loop.boolValue); - else - component.state.ClearTrack(0); - } - - wasAnimationNameChanged = false; + if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) + m_isPrefab = true; } - // Reflect animationName serialized property in the inspector even if SetAnimation API was used. - if (Application.isPlaying) { - TrackEntry current = component.state.GetCurrent(0); - if (current != null) { - if (component.AnimationName != animationName.stringValue) { - animationName.stringValue = current.Animation.Name; + protected override void DrawInspectorGUI () { + base.DrawInspectorGUI(); + + SkeletonAnimation component = (SkeletonAnimation)target; + if (!component.valid) + return; + + if (wasAnimationNameChanged) { + if (!Application.isPlaying) { + if (component.state != null) component.state.ClearTrack(0); + component.skeleton.SetToSetupPose(); + } + + Spine.Animation animationToUse = component.skeleton.Data.FindAnimation(animationName.stringValue); + + if (!Application.isPlaying) { + if (animationToUse != null) animationToUse.Apply(component.skeleton, 0f, 0f, false, null); + component.Update(); + component.LateUpdate(); + SceneView.RepaintAll(); + } else { + if (animationToUse != null) + component.state.SetAnimation(0, animationToUse, loop.boolValue); + else + component.state.ClearTrack(0); + } + + wasAnimationNameChanged = false; + } + + // Reflect animationName serialized property in the inspector even if SetAnimation API was used. + if (Application.isPlaying) { + TrackEntry current = component.state.GetCurrent(0); + if (current != null) { + if (component.AnimationName != animationName.stringValue) { + animationName.stringValue = current.Animation.Name; + } } } - } - EditorGUILayout.Space(); - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(animationName); - wasAnimationNameChanged |= EditorGUI.EndChangeCheck(); - - EditorGUILayout.PropertyField(loop); - EditorGUILayout.PropertyField(timeScale); - component.timeScale = Math.Max(component.timeScale, 0); + EditorGUILayout.Space(); + EditorGUI.BeginChangeCheck(); + EditorGUILayout.PropertyField(animationName); + wasAnimationNameChanged |= EditorGUI.EndChangeCheck(); - EditorGUILayout.Space(); + EditorGUILayout.PropertyField(loop); + EditorGUILayout.PropertyField(timeScale); + component.timeScale = Math.Max(component.timeScale, 0); - if (!m_isPrefab) { - if (component.GetComponent() == null) { - if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) { - component.gameObject.AddComponent(); + EditorGUILayout.Space(); + + if (!m_isPrefab) { + if (component.GetComponent() == null) { + if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) { + component.gameObject.AddComponent(); + } } } } diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs index bf6df6729..ce6118f67 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonAnimatorInspector.cs @@ -1,5 +1,3 @@ - - /***************************************************************************** * SkeletonAnimatorInspector created by Mitch Thompson * Full irrevocable rights and permissions granted to Esoteric Software @@ -7,37 +5,38 @@ using System; using UnityEditor; using UnityEngine; -using Spine; -[CustomEditor(typeof(SkeletonAnimator))] -public class SkeletonAnimatorInspector : SkeletonRendererInspector { - protected SerializedProperty layerMixModes; - protected bool isPrefab; - protected override void OnEnable () { - base.OnEnable(); - layerMixModes = serializedObject.FindProperty("layerMixModes"); +namespace Spine.Unity { + [CustomEditor(typeof(SkeletonAnimator))] + public class SkeletonAnimatorInspector : SkeletonRendererInspector { + protected SerializedProperty layerMixModes; + protected bool isPrefab; + protected override void OnEnable () { + base.OnEnable(); + layerMixModes = serializedObject.FindProperty("layerMixModes"); - if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) - isPrefab = true; - } + if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab) + isPrefab = true; + } - protected override void DrawInspectorGUI () { - base.DrawInspectorGUI(); + protected override void DrawInspectorGUI () { + base.DrawInspectorGUI(); - EditorGUILayout.PropertyField(layerMixModes, true); + EditorGUILayout.PropertyField(layerMixModes, true); - SkeletonAnimator component = (SkeletonAnimator)target; - if (!component.valid) - return; + SkeletonAnimator component = (SkeletonAnimator)target; + if (!component.valid) + return; - EditorGUILayout.Space(); + EditorGUILayout.Space(); - if (!isPrefab) { - if (component.GetComponent() == null) { - if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) { - component.gameObject.AddComponent(); + if (!isPrefab) { + if (component.GetComponent() == null) { + if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) { + component.gameObject.AddComponent(); + } } } } } -} \ No newline at end of file +} diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs index 874dc6aaa..7ebbb865c 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs @@ -33,118 +33,121 @@ using System; using UnityEditor; using UnityEngine; -[CustomEditor(typeof(SkeletonRenderer))] -public class SkeletonRendererInspector : Editor { - protected static bool advancedFoldout; +namespace Spine.Unity { + + [CustomEditor(typeof(SkeletonRenderer))] + public class SkeletonRendererInspector : Editor { + 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; - protected SpineInspectorUtility.SerializedSortingProperties sortingProperties; + protected SpineInspectorUtility.SerializedSortingProperties sortingProperties; - protected virtual void OnEnable () { - SpineEditorUtilities.ConfirmInitialization(); - skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); - initialSkinName = serializedObject.FindProperty("initialSkinName"); - normals = serializedObject.FindProperty("calculateNormals"); - tangents = serializedObject.FindProperty("calculateTangents"); - meshes = serializedObject.FindProperty("renderMeshes"); - immutableTriangles = serializedObject.FindProperty("immutableTriangles"); - submeshSeparators = serializedObject.FindProperty("submeshSeparators"); - front = serializedObject.FindProperty("frontFacing"); - zSpacing = serializedObject.FindProperty("zSpacing"); + protected virtual void OnEnable () { + SpineEditorUtilities.ConfirmInitialization(); + skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset"); + initialSkinName = serializedObject.FindProperty("initialSkinName"); + normals = serializedObject.FindProperty("calculateNormals"); + tangents = serializedObject.FindProperty("calculateTangents"); + meshes = serializedObject.FindProperty("renderMeshes"); + immutableTriangles = serializedObject.FindProperty("immutableTriangles"); + submeshSeparators = serializedObject.FindProperty("submeshSeparators"); + front = serializedObject.FindProperty("frontFacing"); + zSpacing = serializedObject.FindProperty("zSpacing"); - var renderer = ((SkeletonRenderer)target).GetComponent(); - sortingProperties = new SpineInspectorUtility.SerializedSortingProperties(renderer); - } + var renderer = ((SkeletonRenderer)target).GetComponent(); + sortingProperties = new SpineInspectorUtility.SerializedSortingProperties(renderer); + } - protected virtual void DrawInspectorGUI () { - 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) { - foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) { - if (aa != null) - aa.Reset(); + protected virtual void DrawInspectorGUI () { + 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) { + foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) { + if (aa != null) + aa.Reset(); + } + + component.skeletonDataAsset.Reset(); } - - component.skeletonDataAsset.Reset(); + component.Initialize(true); } - component.Initialize(true); - } - EditorGUILayout.EndHorizontal(); + EditorGUILayout.EndHorizontal(); - if (!component.valid) { - component.Initialize(true); - component.LateUpdate(); - if (!component.valid) - return; - } - - // Initial skin name. - { - String[] skins = new String[component.skeleton.Data.Skins.Count]; - int skinIndex = 0; - for (int i = 0; i < skins.Length; i++) { - String skinNameString = component.skeleton.Data.Skins.Items[i].Name; - skins[i] = skinNameString; - if (skinNameString == initialSkinName.stringValue) - skinIndex = i; + if (!component.valid) { + component.Initialize(true); + component.LateUpdate(); + if (!component.valid) + return; } - skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins); - initialSkinName.stringValue = skins[skinIndex]; - } - - EditorGUILayout.Space(); - - // Sorting Layers - { - SpineInspectorUtility.SortingPropertyFields(sortingProperties, applyModifiedProperties: true); - } - - // More Render Options... - { - advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced"); - if(advancedFoldout) { - EditorGUI.indentLevel++; - EditorGUILayout.PropertyField(submeshSeparators, true); - EditorGUILayout.Space(); - EditorGUILayout.PropertyField(meshes, - new GUIContent("Render Mesh Attachments", "Disable to optimize rendering for skeletons that don't use Mesh Attachments")); - EditorGUILayout.PropertyField(immutableTriangles, - new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility")); - EditorGUILayout.Space(); - - const float MinZSpacing = -0.1f; - const float MaxZSpacing = 0f; - EditorGUILayout.Slider(zSpacing, MinZSpacing, MaxZSpacing); - - if (normals != null) { - EditorGUILayout.PropertyField(normals); - EditorGUILayout.PropertyField(tangents); + // Initial skin name. + { + String[] skins = new String[component.skeleton.Data.Skins.Count]; + int skinIndex = 0; + for (int i = 0; i < skins.Length; i++) { + String skinNameString = component.skeleton.Data.Skins.Items[i].Name; + skins[i] = skinNameString; + if (skinNameString == initialSkinName.stringValue) + skinIndex = i; } - if (front != null) { - EditorGUILayout.PropertyField(front); - } + skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins); + initialSkinName.stringValue = skins[skinIndex]; + } - EditorGUILayout.Separator(); - EditorGUI.indentLevel--; + EditorGUILayout.Space(); + + // Sorting Layers + { + SpineInspectorUtility.SortingPropertyFields(sortingProperties, applyModifiedProperties: true); + } + + // More Render Options... + { + advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced"); + if(advancedFoldout) { + EditorGUI.indentLevel++; + EditorGUILayout.PropertyField(submeshSeparators, true); + EditorGUILayout.Space(); + EditorGUILayout.PropertyField(meshes, + new GUIContent("Render Mesh Attachments", "Disable to optimize rendering for skeletons that don't use Mesh Attachments")); + EditorGUILayout.PropertyField(immutableTriangles, + new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility")); + EditorGUILayout.Space(); + + const float MinZSpacing = -0.1f; + const float MaxZSpacing = 0f; + EditorGUILayout.Slider(zSpacing, MinZSpacing, MaxZSpacing); + + if (normals != null) { + EditorGUILayout.PropertyField(normals); + EditorGUILayout.PropertyField(tangents); + } + + if (front != null) { + EditorGUILayout.PropertyField(front); + } + + EditorGUILayout.Separator(); + EditorGUI.indentLevel--; + } } } - } - override public void OnInspectorGUI () { - serializedObject.Update(); - DrawInspectorGUI(); - if (serializedObject.ApplyModifiedProperties() || - (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed") - ) { - if (!Application.isPlaying) - ((SkeletonRenderer)target).Initialize(true); + override public void OnInspectorGUI () { + serializedObject.Update(); + DrawInspectorGUI(); + if (serializedObject.ApplyModifiedProperties() || + (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed") + ) { + if (!Application.isPlaying) + ((SkeletonRenderer)target).Initialize(true); + } } - } -} + } +} \ No newline at end of file diff --git a/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs b/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs index 17ac9551a..ec670431a 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineInspectorUtility.cs @@ -34,59 +34,62 @@ using System.Collections; using UnityEditor; using System.Reflection; -public static class SpineInspectorUtility { - - #region Sorting Layer Field Helpers - static readonly GUIContent SortingLayerLabel = new GUIContent("Sorting Layer"); - static readonly GUIContent OrderInLayerLabel = new GUIContent("Order in Layer"); +namespace Spine.Unity { + public static class SpineInspectorUtility { - static MethodInfo m_SortingLayerFieldMethod; - static MethodInfo SortingLayerFieldMethod { - get { - if (m_SortingLayerFieldMethod == null) - m_SortingLayerFieldMethod = typeof(EditorGUILayout).GetMethod("SortingLayerField", BindingFlags.Static | BindingFlags.NonPublic, null, new System.Type[] { typeof(GUIContent), typeof(SerializedProperty), typeof(GUIStyle) }, null); + #region Sorting Layer Field Helpers + static readonly GUIContent SortingLayerLabel = new GUIContent("Sorting Layer"); + static readonly GUIContent OrderInLayerLabel = new GUIContent("Order in Layer"); - return m_SortingLayerFieldMethod; - } - } + static MethodInfo m_SortingLayerFieldMethod; + static MethodInfo SortingLayerFieldMethod { + get { + if (m_SortingLayerFieldMethod == null) + m_SortingLayerFieldMethod = typeof(EditorGUILayout).GetMethod("SortingLayerField", BindingFlags.Static | BindingFlags.NonPublic, null, new System.Type[] { typeof(GUIContent), typeof(SerializedProperty), typeof(GUIStyle) }, null); - public struct SerializedSortingProperties { - public SerializedObject renderer; - public SerializedProperty sortingLayerID; - public SerializedProperty sortingOrder; - - public SerializedSortingProperties (Renderer r) { - renderer = new SerializedObject(r); - sortingLayerID = renderer.FindProperty("m_SortingLayerID"); - sortingOrder = renderer.FindProperty("m_SortingOrder"); - } - - public void ApplyModifiedProperties () { - renderer.ApplyModifiedProperties(); - } - } - - public static void SortingPropertyFields (SerializedSortingProperties prop, bool applyModifiedProperties) { - if (applyModifiedProperties) { - EditorGUI.BeginChangeCheck(); - SortingPropertyFields(prop.sortingLayerID, prop.sortingOrder); - if(EditorGUI.EndChangeCheck()) { - prop.ApplyModifiedProperties(); - EditorUtility.SetDirty(prop.renderer.targetObject); + return m_SortingLayerFieldMethod; } - } else { - SortingPropertyFields(prop.sortingLayerID, prop.sortingOrder); - } - } - - public static void SortingPropertyFields (SerializedProperty m_SortingLayerID, SerializedProperty m_SortingOrder) { - if (SpineInspectorUtility.SortingLayerFieldMethod != null && m_SortingLayerID != null) { - SpineInspectorUtility.SortingLayerFieldMethod.Invoke(null, new object[] { SortingLayerLabel, m_SortingLayerID, EditorStyles.popup } ); - } else { - EditorGUILayout.PropertyField(m_SortingLayerID); } - EditorGUILayout.PropertyField(m_SortingOrder, OrderInLayerLabel); + public struct SerializedSortingProperties { + public SerializedObject renderer; + public SerializedProperty sortingLayerID; + public SerializedProperty sortingOrder; + + public SerializedSortingProperties (Renderer r) { + renderer = new SerializedObject(r); + sortingLayerID = renderer.FindProperty("m_SortingLayerID"); + sortingOrder = renderer.FindProperty("m_SortingOrder"); + } + + public void ApplyModifiedProperties () { + renderer.ApplyModifiedProperties(); + } + } + + public static void SortingPropertyFields (SerializedSortingProperties prop, bool applyModifiedProperties) { + if (applyModifiedProperties) { + EditorGUI.BeginChangeCheck(); + SortingPropertyFields(prop.sortingLayerID, prop.sortingOrder); + if(EditorGUI.EndChangeCheck()) { + prop.ApplyModifiedProperties(); + EditorUtility.SetDirty(prop.renderer.targetObject); + } + } else { + SortingPropertyFields(prop.sortingLayerID, prop.sortingOrder); + } + } + + public static void SortingPropertyFields (SerializedProperty m_SortingLayerID, SerializedProperty m_SortingOrder) { + if (SpineInspectorUtility.SortingLayerFieldMethod != null && m_SortingLayerID != null) { + SpineInspectorUtility.SortingLayerFieldMethod.Invoke(null, new object[] { SortingLayerLabel, m_SortingLayerID, EditorStyles.popup } ); + } else { + EditorGUILayout.PropertyField(m_SortingLayerID); + } + + EditorGUILayout.PropertyField(m_SortingOrder, OrderInLayerLabel); + } + #endregion } - #endregion + } diff --git a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs index 5ea33c939..639b9af05 100644 --- a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs +++ b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs @@ -149,7 +149,7 @@ namespace Spine.Unity { EditorGUIUtility.PingObject(Selection.activeObject); } - [MenuItem("Assets/Spine/Instantiate (UnityUI)", false, 0)] + [MenuItem("Assets/Spine/Instantiate (UnityUI)", false, 10)] static void InstantiateSkeletonGraphic () { Object[] arr = Selection.objects; 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 () { Object[] arr = Selection.objects; diff --git a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs index 39c101b35..552f5987e 100644 --- a/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs +++ b/spine-unity/Assets/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs @@ -212,7 +212,7 @@ namespace Spine.Unity { spineMeshGenerator.Scale = canvas.referencePixelsPerUnit; // TODO: move this to a listener to of the canvas? canvasRenderer.SetMesh(spineMeshGenerator.GenerateMesh(skeleton)); - this.UpdateMaterial(); + //this.UpdateMaterial(); // TODO: This allocates memory. } } #endregion