From 41359c12de75bc5fa0f90a05d045791a98c46051 Mon Sep 17 00:00:00 2001 From: pharan Date: Wed, 30 May 2018 13:24:17 +0800 Subject: [PATCH] [unity] New AtlasAssetBase base class. --- .../Spine/Editor/spine-unity/Editor/Menus.cs | 25 --------- .../Editor/SkeletonDataAssetInspector.cs | 2 +- .../Editor/SkeletonRendererInspector.cs | 4 +- ...spector.cs => SpineAtlasAssetInspector.cs} | 14 ++--- ....meta => SpineAtlasAssetInspector.cs.meta} | 0 .../Editor/SpineAttributeDrawers.cs | 4 +- .../Editor/SpineEditorUtilities.cs | 56 +++++++++---------- .../Editor/SkeletonGraphicInspector.cs | 2 +- .../Asset Types/AnimationReferenceAsset.cs | 2 +- .../spine-unity/Asset Types/AtlasAssetBase.cs | 15 +++++ .../Asset Types/AtlasAssetBase.cs.meta | 11 ++++ .../Asset Types/EventDataReferenceAsset.cs | 2 +- .../Asset Types/SkeletonDataAsset.cs | 8 ++- .../{AtlasAsset.cs => SpineAtlasAsset.cs} | 31 ++++++---- ...sAsset.cs.meta => SpineAtlasAsset.cs.meta} | 0 .../Components/SkeletonRenderer.cs | 2 +- .../SkeletonRendererCustomMaterials.cs | 13 +++-- .../SkeletonGraphic/SkeletonGraphic.cs | 6 +- .../Modules/SlotBlendModes/SlotBlendModes.cs | 2 +- 19 files changed, 105 insertions(+), 94 deletions(-) rename spine-unity/Assets/Spine/Editor/spine-unity/Editor/{AtlasAssetInspector.cs => SpineAtlasAssetInspector.cs} (97%) rename spine-unity/Assets/Spine/Editor/spine-unity/Editor/{AtlasAssetInspector.cs.meta => SpineAtlasAssetInspector.cs.meta} (100%) create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs create mode 100644 spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs.meta rename spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/{AtlasAsset.cs => SpineAtlasAsset.cs} (84%) rename spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/{AtlasAsset.cs.meta => SpineAtlasAsset.cs.meta} (100%) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Menus.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Menus.cs index 64cfa4f37..8859fecb1 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Menus.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Menus.cs @@ -35,31 +35,6 @@ using UnityEngine; namespace Spine.Unity.Editor { public static class Menus { - [MenuItem("Assets/Create/Spine/Atlas Asset")] - static public void CreateAtlas () { - CreateAsset("New Atlas"); - } - - [MenuItem("Assets/Create/Spine/SkeletonData Asset")] - static public void CreateSkeletonData () { - CreateAsset("New SkeletonData"); - } - - static 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; - } - [MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)] static public void CreateSkeletonRendererGameObject () { CreateSpineGameObject("New SkeletonRenderer"); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs index ee2c2945d..ba50f5848 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonDataAssetInspector.cs @@ -332,7 +332,7 @@ namespace Spine.Unity.Editor { else { EditorGUILayout.HelpBox("Atlas array should not have null entries!", MessageType.Error); if (SpineInspectorUtility.CenteredButton(SpineInspectorUtility.TempContent("Remove null entries"))) { - var trimmedAtlasAssets = new List(); + var trimmedAtlasAssets = new List(); foreach (var a in targetSkeletonDataAsset.atlasAssets) { if (a != null) trimmedAtlasAssets.Add(a); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonRendererInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonRendererInspector.cs index 9d50b0aab..631550222 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonRendererInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonRendererInspector.cs @@ -145,7 +145,7 @@ namespace Spine.Unity.Editor { foreach (var c in targets) { var component = c as SkeletonRenderer; if (component.skeletonDataAsset != null) { - foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) { + foreach (AtlasAssetBase aa in component.skeletonDataAsset.atlasAssets) { if (aa != null) aa.Clear(); } @@ -192,7 +192,7 @@ namespace Spine.Unity.Editor { if (component.valid) { if (GUILayout.Button(ReloadButtonLabel, reloadButtonStyle, reloadWidth)) { if (component.skeletonDataAsset != null) { - foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) { + foreach (AtlasAssetBase aa in component.skeletonDataAsset.atlasAssets) { if (aa != null) aa.Clear(); } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/AtlasAssetInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAtlasAssetInspector.cs similarity index 97% rename from spine-unity/Assets/Spine/Editor/spine-unity/Editor/AtlasAssetInspector.cs rename to spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAtlasAssetInspector.cs index 7b7349351..798392f86 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/AtlasAssetInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAtlasAssetInspector.cs @@ -41,10 +41,10 @@ using Spine; namespace Spine.Unity.Editor { using Event = UnityEngine.Event; - [CustomEditor(typeof(AtlasAsset)), CanEditMultipleObjects] - public class AtlasAssetInspector : UnityEditor.Editor { + [CustomEditor(typeof(SpineAtlasAsset)), CanEditMultipleObjects] + public class SpineAtlasAssetInspector : UnityEditor.Editor { SerializedProperty atlasFile, materials; - AtlasAsset atlasAsset; + SpineAtlasAsset atlasAsset; GUIContent spriteSlicesLabel; GUIContent SpriteSlicesLabel { @@ -72,7 +72,7 @@ namespace Spine.Unity.Editor { atlasFile = serializedObject.FindProperty("atlasFile"); materials = serializedObject.FindProperty("materials"); materials.isExpanded = true; - atlasAsset = (AtlasAsset)target; + atlasAsset = (SpineAtlasAsset)target; #if REGION_BAKING_MESH UpdateBakedList(); #endif @@ -109,7 +109,7 @@ namespace Spine.Unity.Editor { } serializedObject.Update(); - atlasAsset = atlasAsset ?? (AtlasAsset)target; + atlasAsset = atlasAsset ?? (SpineAtlasAsset)target; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(atlasFile); EditorGUILayout.PropertyField(materials, true); @@ -264,7 +264,7 @@ namespace Spine.Unity.Editor { EditorGUILayout.LabelField("Atlas Regions", EditorStyles.boldLabel); int baseIndent = EditorGUI.indentLevel; - var regions = AtlasAssetInspector.GetRegions(atlasAsset.GetAtlas()); + var regions = SpineAtlasAssetInspector.GetRegions(atlasAsset.GetAtlas()); AtlasPage lastPage = null; for (int i = 0; i < regions.Count; i++) { if (lastPage != regions[i].page) { @@ -302,7 +302,7 @@ namespace Spine.Unity.Editor { var spriteSheet = t.spritesheet; var sprites = new List(spriteSheet); - var regions = AtlasAssetInspector.GetRegions(atlas); + var regions = SpineAtlasAssetInspector.GetRegions(atlas); char[] FilenameDelimiter = {'.'}; int updatedCount = 0; int addedCount = 0; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/AtlasAssetInspector.cs.meta b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAtlasAssetInspector.cs.meta similarity index 100% rename from spine-unity/Assets/Spine/Editor/spine-unity/Editor/AtlasAssetInspector.cs.meta rename to spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAtlasAssetInspector.cs.meta diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs index 20b6ff602..f66134ec7 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineAttributeDrawers.cs @@ -520,7 +520,7 @@ namespace Spine.Unity.Editor { } else if (atlasProp.objectReferenceValue == null) { EditorGUI.LabelField(position, "ERROR:", "Atlas variable must not be null!"); return; - } else if (atlasProp.objectReferenceValue.GetType() != typeof(AtlasAsset)) { + } else if (atlasProp.objectReferenceValue.GetType() != typeof(AtlasAssetBase)) { EditorGUI.LabelField(position, "ERROR:", "Atlas variable must be of type AtlasAsset!"); } @@ -533,7 +533,7 @@ namespace Spine.Unity.Editor { void Selector (SerializedProperty property) { GenericMenu menu = new GenericMenu(); - AtlasAsset atlasAsset = (AtlasAsset)atlasProp.objectReferenceValue; + AtlasAssetBase atlasAsset = (AtlasAssetBase)atlasProp.objectReferenceValue; Atlas atlas = atlasAsset.GetAtlas(); FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); List regions = (List)field.GetValue(atlas); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs index 1fa281c20..4c0ef5919 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs @@ -657,10 +657,10 @@ namespace Spine.Unity.Editor { } // Import atlases first. - var atlases = new List(); + var atlases = new List(); foreach (string ap in atlasPaths) { TextAsset atlasText = (TextAsset)AssetDatabase.LoadAssetAtPath(ap, typeof(TextAsset)); - AtlasAsset atlas = IngestSpineAtlas(atlasText); + AtlasAssetBase atlas = IngestSpineAtlas(atlasText); atlases.Add(atlas); } @@ -696,7 +696,7 @@ namespace Spine.Unity.Editor { switch (result) { case -1: //Debug.Log("Select Atlas"); - AtlasAsset selectedAtlas = GetAtlasDialog(Path.GetDirectoryName(sp)); + AtlasAssetBase selectedAtlas = GetAtlasDialog(Path.GetDirectoryName(sp)); if (selectedAtlas != null) { localAtlases.Clear(); localAtlases.Add(selectedAtlas); @@ -758,14 +758,14 @@ namespace Spine.Unity.Editor { // and as a result, all comparisons with null returns true. // But the C# wrapper is still alive, so we can "restore" the object // by reloading it from its Instance ID. - AtlasAsset[] skeletonDataAtlasAssets = skeletonDataAsset.atlasAssets; + AtlasAssetBase[] skeletonDataAtlasAssets = skeletonDataAsset.atlasAssets; if (skeletonDataAtlasAssets != null) { for (int i = 0; i < skeletonDataAtlasAssets.Length; i++) { if (!ReferenceEquals(null, skeletonDataAtlasAssets[i]) && skeletonDataAtlasAssets[i].Equals(null) && skeletonDataAtlasAssets[i].GetInstanceID() != 0 ) { - skeletonDataAtlasAssets[i] = EditorUtility.InstanceIDToObject(skeletonDataAtlasAssets[i].GetInstanceID()) as AtlasAsset; + skeletonDataAtlasAssets[i] = EditorUtility.InstanceIDToObject(skeletonDataAtlasAssets[i].GetInstanceID()) as AtlasAssetBase; } } } @@ -792,8 +792,8 @@ namespace Spine.Unity.Editor { #region Match SkeletonData with Atlases static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh }; - static List MultiAtlasDialog (List requiredPaths, string initialDirectory, string filename = "") { - List atlasAssets = new List(); + static List MultiAtlasDialog (List requiredPaths, string initialDirectory, string filename = "") { + List atlasAssets = new List(); bool resolved = false; string lastAtlasPath = initialDirectory; while (!resolved) { @@ -845,7 +845,7 @@ namespace Spine.Unity.Editor { switch (result) { case 0: // Browse... - AtlasAsset selectedAtlasAsset = GetAtlasDialog(lastAtlasPath); + AtlasAssetBase selectedAtlasAsset = GetAtlasDialog(lastAtlasPath); if (selectedAtlasAsset != null) { var atlas = selectedAtlasAsset.GetAtlas(); bool hasValidRegion = false; @@ -871,19 +871,19 @@ namespace Spine.Unity.Editor { return atlasAssets; } - static AtlasAsset GetAtlasDialog (string dirPath) { + static AtlasAssetBase GetAtlasDialog (string dirPath) { string path = EditorUtility.OpenFilePanel("Select AtlasAsset...", dirPath, "asset"); if (path == "") return null; // Canceled or closed by user. int subLen = Application.dataPath.Length - 6; string assetRelativePath = path.Substring(subLen, path.Length - subLen).Replace("\\", "/"); - Object obj = AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(AtlasAsset)); + Object obj = AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(AtlasAssetBase)); - if (obj == null || obj.GetType() != typeof(AtlasAsset)) + if (obj == null || obj.GetType() != typeof(AtlasAssetBase)) return null; - return (AtlasAsset)obj; + return (AtlasAssetBase)obj; } static void AddRequiredAtlasRegionsFromBinary (string skeletonDataPath, List requiredPaths) { @@ -945,10 +945,10 @@ namespace Spine.Unity.Editor { return requiredPaths; } - static AtlasAsset GetMatchingAtlas (List requiredPaths, List atlasAssets) { - AtlasAsset atlasAssetMatch = null; + static AtlasAssetBase GetMatchingAtlas (List requiredPaths, List atlasAssets) { + AtlasAssetBase atlasAssetMatch = null; - foreach (AtlasAsset a in atlasAssets) { + foreach (AtlasAssetBase a in atlasAssets) { Atlas atlas = a.GetAtlas(); bool failed = false; foreach (string regionPath in requiredPaths) { @@ -1003,23 +1003,23 @@ namespace Spine.Unity.Editor { #endregion #region Import Atlases - static List FindAtlasesAtPath (string path) { - List arr = new List(); + static List FindAtlasesAtPath (string path) { + List arr = new List(); DirectoryInfo dir = new DirectoryInfo(path); FileInfo[] assetInfoArr = dir.GetFiles("*.asset"); int subLen = Application.dataPath.Length - 6; foreach (var f in assetInfoArr) { string assetRelativePath = f.FullName.Substring(subLen, f.FullName.Length - subLen).Replace("\\", "/"); - Object obj = AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(AtlasAsset)); + Object obj = AssetDatabase.LoadAssetAtPath(assetRelativePath, typeof(AtlasAssetBase)); if (obj != null) - arr.Add(obj as AtlasAsset); + arr.Add(obj as AtlasAssetBase); } return arr; } - static AtlasAsset IngestSpineAtlas (TextAsset atlasText) { + static AtlasAssetBase IngestSpineAtlas (TextAsset atlasText) { if (atlasText == null) { Debug.LogWarning("Atlas source cannot be null!"); return null; @@ -1030,12 +1030,12 @@ namespace Spine.Unity.Editor { string atlasPath = assetPath + "/" + primaryName + "_Atlas.asset"; - AtlasAsset atlasAsset = (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset)); + SpineAtlasAsset atlasAsset = (SpineAtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(SpineAtlasAsset)); List vestigialMaterials = new List(); if (atlasAsset == null) - atlasAsset = AtlasAsset.CreateInstance(); + atlasAsset = SpineAtlasAsset.CreateInstance(); else { foreach (Material m in atlasAsset.materials) vestigialMaterials.Add(m); @@ -1146,12 +1146,12 @@ namespace Spine.Unity.Editor { } protectFromStackGarbageCollection.Remove(atlasAsset); - return (AtlasAsset)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAsset)); + return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase)); } #endregion #region Bake Atlas Region - public static GameObject BakeRegion (AtlasAsset atlasAsset, AtlasRegion region, bool autoSave = true) { + public static GameObject BakeRegion (SpineAtlasAsset atlasAsset, AtlasRegion region, bool autoSave = true) { Atlas atlas = atlasAsset.GetAtlas(); string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset); string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath); @@ -1198,7 +1198,7 @@ namespace Spine.Unity.Editor { #region Import SkeletonData (json or binary) public const string SkeletonDataSuffix = "_SkeletonData"; - static SkeletonDataAsset IngestSpineProject (TextAsset spineJson, params AtlasAsset[] atlasAssets) { + static SkeletonDataAsset IngestSpineProject (TextAsset spineJson, params AtlasAssetBase[] atlasAssets) { string primaryName = Path.GetFileNameWithoutExtension(spineJson.name); string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson)); string filePath = assetPath + "/" + primaryName + SkeletonDataSuffix + ".asset"; @@ -1363,7 +1363,7 @@ namespace Spine.Unity.Editor { bool pmaVertexColors = false; bool tintBlack = false; - foreach (AtlasAsset atlasAsset in skeletonDataAsset.atlasAssets) { + foreach (SpineAtlasAsset atlasAsset in skeletonDataAsset.atlasAssets) { if (!pmaVertexColors) { foreach (Material m in atlasAsset.materials) { if (m.shader.name.Contains(PMAShaderQuery)) { @@ -1399,7 +1399,7 @@ namespace Spine.Unity.Editor { if (data == null) { for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) { string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]); - skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset)); + skeletonDataAsset.atlasAssets[i] = (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAssetBase)); } data = skeletonDataAsset.GetSkeletonData(false); } @@ -1476,7 +1476,7 @@ namespace Spine.Unity.Editor { if (data == null) { for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) { string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]); - skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset)); + skeletonDataAsset.atlasAssets[i] = (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAssetBase)); } data = skeletonDataAsset.GetSkeletonData(true); } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs index acf9bbf5a..bf6bda947 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs @@ -186,7 +186,7 @@ namespace Spine.Unity.Editor { if (data == null) { for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) { string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]); - skeletonDataAsset.atlasAssets[i] = (AtlasAsset)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAsset)); + skeletonDataAsset.atlasAssets[i] = (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAssetBase)); } data = skeletonDataAsset.GetSkeletonData(true); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AnimationReferenceAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AnimationReferenceAsset.cs index e7305cdcd..b44565f82 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AnimationReferenceAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AnimationReferenceAsset.cs @@ -33,7 +33,7 @@ using UnityEngine; namespace Spine.Unity { - [CreateAssetMenu(menuName = "Spine/Animation Reference Asset")] + [CreateAssetMenu(menuName = "Spine/Animation Reference Asset", order = 100)] public class AnimationReferenceAsset : ScriptableObject, IHasSkeletonDataAsset { const bool QuietSkeletonData = true; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs new file mode 100644 index 000000000..69026dcfb --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Spine.Unity { + public abstract class AtlasAssetBase : ScriptableObject { + public abstract Material PrimaryMaterial { get; } + public abstract IEnumerable Materials { get; } + public abstract int MaterialCount { get; } + + public abstract bool IsLoaded { get; } + public abstract void Clear (); + public abstract Atlas GetAtlas (); + } +} diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs.meta new file mode 100644 index 000000000..5469af612 --- /dev/null +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAssetBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 787a36933c1c6e14db2104c01ed92dcb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/EventDataReferenceAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/EventDataReferenceAsset.cs index 6cee80bd9..d758981fc 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/EventDataReferenceAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/EventDataReferenceAsset.cs @@ -33,7 +33,7 @@ using UnityEngine; namespace Spine.Unity { - [CreateAssetMenu(menuName = "Spine/EventData Reference Asset")] + [CreateAssetMenu(menuName = "Spine/EventData Reference Asset", order = 100)] public class EventDataReferenceAsset : ScriptableObject { const bool QuietSkeletonData = true; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs index 8891ee3b8..eef3c6ade 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SkeletonDataAsset.cs @@ -34,9 +34,11 @@ using UnityEngine; using Spine; namespace Spine.Unity { + + [CreateAssetMenu(fileName = "New SkeletonDataAsset", menuName = "Spine/SkeletonData Asset")] public class SkeletonDataAsset : ScriptableObject { #region Inspector - public AtlasAsset[] atlasAssets = new AtlasAsset[0]; + public AtlasAssetBase[] atlasAssets = new AtlasAssetBase[0]; #if SPINE_TK2D public tk2dSpriteCollectionData spriteCollection; public float scale = 1f; @@ -65,13 +67,13 @@ namespace Spine.Unity { #region Runtime Instantiation /// /// Creates a runtime SkeletonDataAsset. - public static SkeletonDataAsset CreateRuntimeInstance (TextAsset skeletonDataFile, AtlasAsset atlasAsset, bool initialize, float scale = 0.01f) { + public static SkeletonDataAsset CreateRuntimeInstance (TextAsset skeletonDataFile, AtlasAssetBase atlasAsset, bool initialize, float scale = 0.01f) { return CreateRuntimeInstance(skeletonDataFile, new [] {atlasAsset}, initialize, scale); } /// /// Creates a runtime SkeletonDataAsset. - public static SkeletonDataAsset CreateRuntimeInstance (TextAsset skeletonDataFile, AtlasAsset[] atlasAssets, bool initialize, float scale = 0.01f) { + public static SkeletonDataAsset CreateRuntimeInstance (TextAsset skeletonDataFile, AtlasAssetBase[] atlasAssets, bool initialize, float scale = 0.01f) { SkeletonDataAsset skeletonDataAsset = ScriptableObject.CreateInstance(); skeletonDataAsset.Clear(); skeletonDataAsset.skeletonJSON = skeletonDataFile; diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAsset.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs similarity index 84% rename from spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAsset.cs rename to spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs index 824e500f9..a7d88979a 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAsset.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs @@ -36,18 +36,23 @@ using Spine; namespace Spine.Unity { /// Loads and stores a Spine atlas and list of materials. - public class AtlasAsset : ScriptableObject { + [CreateAssetMenu(fileName = "New Spine Atlas Asset", menuName = "Spine/Spine Atlas Asset")] + public class SpineAtlasAsset : AtlasAssetBase { public TextAsset atlasFile; public Material[] materials; protected Atlas atlas; - public bool IsLoaded { get { return this.atlas != null; } } + public override bool IsLoaded { get { return this.atlas != null; } } + public override IEnumerable Materials { get { return materials; } } + public override int MaterialCount { get { return materials == null ? 0 : materials.Length; } } + public override Material PrimaryMaterial { get { return materials[0]; } } + #region Runtime Instantiation /// /// Creates a runtime AtlasAsset - public static AtlasAsset CreateRuntimeInstance (TextAsset atlasText, Material[] materials, bool initialize) { - AtlasAsset atlasAsset = ScriptableObject.CreateInstance(); + public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Material[] materials, bool initialize) { + SpineAtlasAsset atlasAsset = ScriptableObject.CreateInstance(); atlasAsset.Reset(); atlasAsset.atlasFile = atlasText; atlasAsset.materials = materials; @@ -59,8 +64,8 @@ namespace Spine.Unity { } /// - /// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches. - public static AtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Material materialPropertySource, bool initialize) { + /// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches. + public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Material materialPropertySource, bool initialize) { // Get atlas page names. string atlasString = atlasText.text; atlasString = atlasString.Replace("\r", ""); @@ -98,8 +103,8 @@ namespace Spine.Unity { } /// - /// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches. - public static AtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Shader shader, bool initialize) { + /// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches. + public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Texture2D[] textures, Shader shader, bool initialize) { if (shader == null) shader = Shader.Find("Spine/Skeleton"); @@ -110,16 +115,18 @@ namespace Spine.Unity { } #endregion + + void Reset () { Clear(); } - public virtual void Clear () { + public override void Clear () { atlas = null; } /// The atlas or null if it could not be loaded. - public virtual Atlas GetAtlas () { + public override Atlas GetAtlas () { if (atlasFile == null) { Debug.LogError("Atlas file not set for atlas asset: " + name, this); Clear(); @@ -204,9 +211,9 @@ namespace Spine.Unity { } public class MaterialsTextureLoader : TextureLoader { - AtlasAsset atlasAsset; + SpineAtlasAsset atlasAsset; - public MaterialsTextureLoader (AtlasAsset atlasAsset) { + public MaterialsTextureLoader (SpineAtlasAsset atlasAsset) { this.atlasAsset = atlasAsset; } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAsset.cs.meta b/spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs.meta similarity index 100% rename from spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/AtlasAsset.cs.meta rename to spine-unity/Assets/Spine/Runtime/spine-unity/Asset Types/SpineAtlasAsset.cs.meta diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs index 811cfcb92..21907bb7f 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonRenderer.cs @@ -244,7 +244,7 @@ namespace Spine.Unity { if (this.singleSubmesh) { // STEP 1. Determine a SmartMesh.Instruction. Split up instructions into submeshes. ============================================= - MeshGenerator.GenerateSingleSubmeshInstruction(currentInstructions, skeleton, skeletonDataAsset.atlasAssets[0].materials[0]); + MeshGenerator.GenerateSingleSubmeshInstruction(currentInstructions, skeleton, skeletonDataAsset.atlasAssets[0].PrimaryMaterial); // STEP 1.9. Post-process workingInstructions. ================================================================================== #if SPINE_OPTIONAL_MATERIALOVERRIDE diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/CustomMaterials/SkeletonRendererCustomMaterials.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/CustomMaterials/SkeletonRendererCustomMaterials.cs index a8d8a714e..ba8ce0f89 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/CustomMaterials/SkeletonRendererCustomMaterials.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/CustomMaterials/SkeletonRendererCustomMaterials.cs @@ -51,14 +51,15 @@ namespace Spine.Unity.Modules { // Populate atlas list if (skeletonRenderer != null && skeletonRenderer.skeletonDataAsset != null) { - AtlasAsset[] atlasAssets = skeletonRenderer.skeletonDataAsset.atlasAssets; + var atlasAssets = skeletonRenderer.skeletonDataAsset.atlasAssets; var initialAtlasMaterialOverrides = new List(); - foreach (AtlasAsset atlasAsset in atlasAssets) { - foreach (Material atlasMaterial in atlasAsset.materials) { - var atlasMaterialOverride = new AtlasMaterialOverride(); - atlasMaterialOverride.overrideDisabled = true; - atlasMaterialOverride.originalMaterial = atlasMaterial; + foreach (AtlasAssetBase atlasAsset in atlasAssets) { + foreach (Material atlasMaterial in atlasAsset.Materials) { + var atlasMaterialOverride = new AtlasMaterialOverride { + overrideDisabled = true, + originalMaterial = atlasMaterial + }; initialAtlasMaterialOverrides.Add(atlasMaterialOverride); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs index f0665c17e..43519c3d2 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs @@ -64,7 +64,7 @@ namespace Spine.Unity { Clear(); Initialize(true); startingAnimation = ""; - if (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].materials.Length > 1) + if (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].MaterialCount > 1) Debug.LogError("Unity UI does not support multiple textures per Renderer. Your skeleton will not be rendered correctly. Recommend using SkeletonAnimation instead. This requires the use of a Screen space camera canvas."); } else { if (freeze) return; @@ -136,7 +136,7 @@ namespace Spine.Unity { get { // Fail loudly when incorrectly set up. if (overrideTexture != null) return overrideTexture; - return skeletonDataAsset == null ? null : skeletonDataAsset.atlasAssets[0].materials[0].mainTexture; + return skeletonDataAsset == null ? null : skeletonDataAsset.atlasAssets[0].PrimaryMaterial.mainTexture; } } @@ -224,7 +224,7 @@ namespace Spine.Unity { var skeletonData = this.skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) return; - if (skeletonDataAsset.atlasAssets.Length <= 0 || skeletonDataAsset.atlasAssets[0].materials.Length <= 0) return; + if (skeletonDataAsset.atlasAssets.Length <= 0 || skeletonDataAsset.atlasAssets[0].MaterialCount <= 0) return; this.state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData()); if (state == null) { diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/SlotBlendModes.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/SlotBlendModes.cs index 44177f04d..567b0625d 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/SlotBlendModes.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SlotBlendModes/SlotBlendModes.cs @@ -141,7 +141,7 @@ namespace Spine.Unity.Modules { var sr = GetComponent(); if (sr == null) return; var sda = sr.skeletonDataAsset; if (sda == null) return; var aa = sda.atlasAssets[0]; if (aa == null) return; - var am = aa.materials[0]; if (am == null) return; + var am = aa.PrimaryMaterial; if (am == null) return; texture = am.mainTexture as Texture2D; } }