diff --git a/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs b/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs index 24c24764b..a7506f198 100644 --- a/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs +++ b/spine-unity/Assets/spine-unity/Asset Types/AtlasAsset.cs @@ -100,7 +100,11 @@ namespace Spine.Unity { } #endregion - public virtual void Reset () { + void Reset () { + Clear(); + } + + public virtual void Clear () { atlas = null; } @@ -108,13 +112,13 @@ namespace Spine.Unity { public virtual Atlas GetAtlas () { if (atlasFile == null) { Debug.LogError("Atlas file not set for atlas asset: " + name, this); - Reset(); + Clear(); return null; } if (materials == null || materials.Length == 0) { Debug.LogError("Materials not set for atlas asset: " + name, this); - Reset(); + Clear(); return null; } @@ -142,8 +146,8 @@ namespace Spine.Unity { Vector3[] verts = new Vector3[4]; Vector2[] uvs = new Vector2[4]; - Color[] colors = new Color[4] { Color.white, Color.white, Color.white, Color.white }; - int[] triangles = new int[6] { 0, 1, 2, 2, 3, 0 }; + Color[] colors = { Color.white, Color.white, Color.white, Color.white }; + int[] triangles = { 0, 1, 2, 2, 3, 0 }; float left, right, top, bottom; left = region.width / -2f; 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 0ce52b403..3fb88332d 100644 --- a/spine-unity/Assets/spine-unity/Asset Types/Editor/AtlasAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Asset Types/Editor/AtlasAssetInspector.cs @@ -43,16 +43,24 @@ namespace Spine.Unity.Editor { [CustomEditor(typeof(AtlasAsset))] public class AtlasAssetInspector : UnityEditor.Editor { - private SerializedProperty atlasFile, materials; - private AtlasAsset atlasAsset; + SerializedProperty atlasFile, materials; + AtlasAsset atlasAsset; - readonly GUIContent SpriteSlicesLabel = new GUIContent( - "Apply Regions as Texture Sprite Slices", - SpineEditorUtilities.Icons.unityIcon, - "Adds Sprite slices to atlas texture(s). " + - "Updates existing slices if ones with matching names exist. \n\n" + - "If your atlas was exported with Premultiply Alpha, " + - "your SpriteRenderer should use the generated Spine _Material asset (or any Material with a PMA shader) instead of Sprites-Default."); + GUIContent spriteSlicesLabel; + GUIContent SpriteSlicesLabel { + get { + if (spriteSlicesLabel == null) { + spriteSlicesLabel = new GUIContent( + "Apply Regions as Texture Sprite Slices", + SpineEditorUtilities.Icons.unityIcon, + "Adds Sprite slices to atlas texture(s). " + + "Updates existing slices if ones with matching names exist. \n\n" + + "If your atlas was exported with Premultiply Alpha, " + + "your SpriteRenderer should use the generated Spine _Material asset (or any Material with a PMA shader) instead of Sprites-Default."); + } + return spriteSlicesLabel; + } + } static List GetRegions (Atlas atlas) { FieldInfo regionsField = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.NonPublic); @@ -100,8 +108,12 @@ namespace Spine.Unity.Editor { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(atlasFile); EditorGUILayout.PropertyField(materials, true); - if (EditorGUI.EndChangeCheck()) + if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); + atlasAsset.Clear(); + atlasAsset.GetAtlas(); + } + if (materials.arraySize == 0) { EditorGUILayout.LabelField(new GUIContent("Error: Missing materials", SpineEditorUtilities.Icons.warning)); @@ -235,6 +247,7 @@ namespace Spine.Unity.Editor { #else if (atlasFile.objectReferenceValue != null) { EditorGUILayout.LabelField("Atlas Regions", EditorStyles.boldLabel); + int baseIndent = EditorGUI.indentLevel; var regions = AtlasAssetInspector.GetRegions(atlasAsset.GetAtlas()); AtlasPage lastPage = null; @@ -247,29 +260,24 @@ namespace Spine.Unity.Editor { lastPage = regions[i].page; Material mat = ((Material)lastPage.rendererObject); if (mat != null) { - - GUILayout.BeginHorizontal(); - { - EditorGUI.BeginDisabledGroup(true); + EditorGUI.indentLevel = baseIndent; + using (new GUILayout.HorizontalScope()) + using (new EditorGUI.DisabledGroupScope(true)) EditorGUILayout.ObjectField(mat, typeof(Material), false, GUILayout.Width(250)); - EditorGUI.EndDisabledGroup(); - EditorGUI.indentLevel++; - } - GUILayout.EndHorizontal(); - + EditorGUI.indentLevel = baseIndent + 1; } else { EditorGUILayout.HelpBox("Page missing material!", MessageType.Warning); } } + EditorGUILayout.LabelField(new GUIContent(regions[i].name, SpineEditorUtilities.Icons.image)); } - EditorGUI.indentLevel--; + EditorGUI.indentLevel = baseIndent; } #endif - if (serializedObject.ApplyModifiedProperties() || SpineInspectorUtility.UndoRedoPerformed(Event.current)) { - atlasAsset.Reset(); - } + if (serializedObject.ApplyModifiedProperties() || SpineInspectorUtility.UndoRedoPerformed(Event.current)) + atlasAsset.Clear(); } static public void UpdateSpriteSlices (Texture texture, Atlas atlas) { diff --git a/spine-unity/Assets/spine-unity/Asset Types/SkeletonDataAsset.cs b/spine-unity/Assets/spine-unity/Asset Types/SkeletonDataAsset.cs index d953ddce1..cb5d5e8a2 100644 --- a/spine-unity/Assets/spine-unity/Asset Types/SkeletonDataAsset.cs +++ b/spine-unity/Assets/spine-unity/Asset Types/SkeletonDataAsset.cs @@ -35,7 +35,8 @@ using Spine; namespace Spine.Unity { public class SkeletonDataAsset : ScriptableObject { - public AtlasAsset[] atlasAssets; + #region Inspector + public AtlasAsset[] atlasAssets = new AtlasAsset[0]; #if SPINE_TK2D public tk2dSpriteCollectionData spriteCollection; public float scale = 1f; @@ -43,13 +44,19 @@ namespace Spine.Unity { public float scale = 0.01f; #endif public TextAsset skeletonJSON; - public String[] fromAnimation; - public String[] toAnimation; - public float[] duration; + public string[] fromAnimation = new string[0]; + public string[] toAnimation = new string[0]; + public float[] duration = new float[0]; public float defaultMix; public RuntimeAnimatorController controller; - private SkeletonData skeletonData; - private AnimationStateData stateData; + + void Reset () { + Clear(); + } + #endregion + + SkeletonData skeletonData; + AnimationStateData stateData; #region Runtime Instantiation /// @@ -62,7 +69,7 @@ namespace Spine.Unity { /// Creates a runtime SkeletonDataAsset. public static SkeletonDataAsset CreateRuntimeInstance (TextAsset skeletonDataFile, AtlasAsset[] atlasAssets, bool initialize, float scale = 0.01f) { SkeletonDataAsset skeletonDataAsset = ScriptableObject.CreateInstance(); - skeletonDataAsset.Reset(); + skeletonDataAsset.Clear(); skeletonDataAsset.skeletonJSON = skeletonDataFile; skeletonDataAsset.atlasAssets = atlasAssets; skeletonDataAsset.scale = scale; @@ -74,12 +81,7 @@ namespace Spine.Unity { } #endregion - void OnEnable () { - if (atlasAssets == null) - atlasAssets = new AtlasAsset[0]; - } - - public void Reset () { + public void Clear () { skeletonData = null; stateData = null; } @@ -89,20 +91,20 @@ namespace Spine.Unity { atlasAssets = new AtlasAsset[0]; if (!quiet) Debug.LogError("Atlas not set for SkeletonData asset: " + name, this); - Reset(); + Clear(); return null; } if (skeletonJSON == null) { if (!quiet) Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this); - Reset(); + Clear(); return null; } #if !SPINE_TK2D if (atlasAssets.Length == 0) { - Reset(); + Clear(); return null; } #else @@ -115,12 +117,12 @@ namespace Spine.Unity { Atlas[] atlasArr = new Atlas[atlasAssets.Length]; for (int i = 0; i < atlasAssets.Length; i++) { if (atlasAssets[i] == null) { - Reset(); + Clear(); return null; } atlasArr[i] = atlasAssets[i].GetAtlas(); if (atlasArr[i] == null) { - Reset(); + Clear(); return null; } } @@ -179,19 +181,14 @@ namespace Spine.Unity { } public void FillStateData () { - if (stateData == null) - return; + if (stateData != null) { + stateData.defaultMix = defaultMix; - stateData.DefaultMix = defaultMix; - - // For compatibility with runtime-instantiated SkeletonDataAsset. - if (fromAnimation == null || toAnimation == null) - return; - - for (int i = 0, n = fromAnimation.Length; i < n; i++) { - if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) - continue; - stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]); + for (int i = 0, n = fromAnimation.Length; i < n; i++) { + if (fromAnimation[i].Length == 0 || toAnimation[i].Length == 0) + continue; + stateData.SetMix(fromAnimation[i], toAnimation[i], duration[i]); + } } } diff --git a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs index 326f0aebd..66a2d9572 100644 --- a/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/SkeletonRendererInspector.cs @@ -134,9 +134,9 @@ namespace Spine.Unity.Editor { if (component.skeletonDataAsset != null) { foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) { if (aa != null) - aa.Reset(); + aa.Clear(); } - component.skeletonDataAsset.Reset(); + component.skeletonDataAsset.Clear(); } component.Initialize(true); } @@ -180,9 +180,9 @@ namespace Spine.Unity.Editor { if (component.skeletonDataAsset != null) { foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) { if (aa != null) - aa.Reset(); + aa.Clear(); } - component.skeletonDataAsset.Reset(); + component.skeletonDataAsset.Clear(); } component.Initialize(true); } diff --git a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs index d117e4c4a..440d3db09 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs @@ -545,7 +545,7 @@ namespace Spine.Unity.Editor { bool abortSkeletonImport = false; foreach (string sp in skeletonPaths) { if (!reimport && CheckForValidSkeletonData(sp)) { - ResetExistingSkeletonData(sp); + ClearExistingSkeletonData(sp); continue; } @@ -610,7 +610,7 @@ namespace Spine.Unity.Editor { // Any post processing of images } - static void ResetExistingSkeletonData (string skeletonJSONPath) { + static void ClearExistingSkeletonData (string skeletonJSONPath) { string dir = Path.GetDirectoryName(skeletonJSONPath); TextAsset textAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonJSONPath, typeof(TextAsset)); DirectoryInfo dirInfo = new DirectoryInfo(dir); @@ -625,7 +625,7 @@ namespace Spine.Unity.Editor { if (Selection.activeObject == skeletonDataAsset) Selection.activeObject = null; - skeletonDataAsset.Reset(); + skeletonDataAsset.Clear(); string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(skeletonDataAsset)); string lastHash = EditorPrefs.GetString(guid + "_hash"); @@ -970,7 +970,7 @@ namespace Spine.Unity.Editor { if (AssetDatabase.GetAssetPath(atlasAsset) == "") AssetDatabase.CreateAsset(atlasAsset, atlasPath); else - atlasAsset.Reset(); + atlasAsset.Clear(); EditorUtility.SetDirty(atlasAsset); AssetDatabase.SaveAssets(); @@ -1098,7 +1098,7 @@ namespace Spine.Unity.Editor { AssetDatabase.SaveAssets(); } else { skeletonDataAsset.atlasAssets = atlasAssets; - skeletonDataAsset.Reset(); + skeletonDataAsset.Clear(); skeletonDataAsset.GetSkeletonData(true); }