[unity] New AtlasAssetBase base class.

This commit is contained in:
pharan 2018-05-30 13:24:17 +08:00
parent d44ee5ec2f
commit 41359c12de
19 changed files with 105 additions and 94 deletions

View File

@ -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<AtlasAsset>("New Atlas");
}
[MenuItem("Assets/Create/Spine/SkeletonData Asset")]
static public void CreateSkeletonData () {
CreateAsset<SkeletonDataAsset>("New SkeletonData");
}
static void CreateAsset<T> (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<T>();
AssetDatabase.CreateAsset(asset, dir + name + ".asset");
AssetDatabase.SaveAssets();
EditorUtility.FocusProjectWindow();
Selection.activeObject = asset;
}
[MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)]
static public void CreateSkeletonRendererGameObject () {
CreateSpineGameObject<SkeletonRenderer>("New SkeletonRenderer");

View File

@ -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<AtlasAsset>();
var trimmedAtlasAssets = new List<AtlasAssetBase>();
foreach (var a in targetSkeletonDataAsset.atlasAssets) {
if (a != null)
trimmedAtlasAssets.Add(a);

View File

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

View File

@ -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<SpriteMetaData>(spriteSheet);
var regions = AtlasAssetInspector.GetRegions(atlas);
var regions = SpineAtlasAssetInspector.GetRegions(atlas);
char[] FilenameDelimiter = {'.'};
int updatedCount = 0;
int addedCount = 0;

View File

@ -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<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas);

View File

@ -657,10 +657,10 @@ namespace Spine.Unity.Editor {
}
// Import atlases first.
var atlases = new List<AtlasAsset>();
var atlases = new List<AtlasAssetBase>();
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<AtlasAsset> MultiAtlasDialog (List<string> requiredPaths, string initialDirectory, string filename = "") {
List<AtlasAsset> atlasAssets = new List<AtlasAsset>();
static List<AtlasAssetBase> MultiAtlasDialog (List<string> requiredPaths, string initialDirectory, string filename = "") {
List<AtlasAssetBase> atlasAssets = new List<AtlasAssetBase>();
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<string> requiredPaths) {
@ -945,10 +945,10 @@ namespace Spine.Unity.Editor {
return requiredPaths;
}
static AtlasAsset GetMatchingAtlas (List<string> requiredPaths, List<AtlasAsset> atlasAssets) {
AtlasAsset atlasAssetMatch = null;
static AtlasAssetBase GetMatchingAtlas (List<string> requiredPaths, List<AtlasAssetBase> 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<AtlasAsset> FindAtlasesAtPath (string path) {
List<AtlasAsset> arr = new List<AtlasAsset>();
static List<AtlasAssetBase> FindAtlasesAtPath (string path) {
List<AtlasAssetBase> arr = new List<AtlasAssetBase>();
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<Material> vestigialMaterials = new List<Material>();
if (atlasAsset == null)
atlasAsset = AtlasAsset.CreateInstance<AtlasAsset>();
atlasAsset = SpineAtlasAsset.CreateInstance<SpineAtlasAsset>();
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);
}

View File

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

View File

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

View File

@ -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<Material> Materials { get; }
public abstract int MaterialCount { get; }
public abstract bool IsLoaded { get; }
public abstract void Clear ();
public abstract Atlas GetAtlas ();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 787a36933c1c6e14db2104c01ed92dcb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -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
/// <summary>
/// Creates a runtime SkeletonDataAsset.</summary>
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);
}
/// <summary>
/// Creates a runtime SkeletonDataAsset.</summary>
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>();
skeletonDataAsset.Clear();
skeletonDataAsset.skeletonJSON = skeletonDataFile;

View File

@ -36,18 +36,23 @@ using Spine;
namespace Spine.Unity {
/// <summary>Loads and stores a Spine atlas and list of materials.</summary>
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<Material> 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
/// <summary>
/// Creates a runtime AtlasAsset</summary>
public static AtlasAsset CreateRuntimeInstance (TextAsset atlasText, Material[] materials, bool initialize) {
AtlasAsset atlasAsset = ScriptableObject.CreateInstance<AtlasAsset>();
public static SpineAtlasAsset CreateRuntimeInstance (TextAsset atlasText, Material[] materials, bool initialize) {
SpineAtlasAsset atlasAsset = ScriptableObject.CreateInstance<SpineAtlasAsset>();
atlasAsset.Reset();
atlasAsset.atlasFile = atlasText;
atlasAsset.materials = materials;
@ -59,8 +64,8 @@ namespace Spine.Unity {
}
/// <summary>
/// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches. <seealso cref="Spine.Unity.AtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool)"/></summary>
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. <seealso cref="Spine.Unity.SpineAtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool)"/></summary>
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 {
}
/// <summary>
/// Creates a runtime AtlasAsset. Only providing the textures is slower because it has to search for atlas page matches. <seealso cref="Spine.Unity.AtlasAsset.CreateRuntimeInstance(TextAsset, Material[], bool)"/></summary>
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. <seealso cref="Spine.Unity.AtlasAssetBase.CreateRuntimeInstance(TextAsset, Material[], bool)"/></summary>
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;
}
/// <returns>The atlas or null if it could not be loaded.</returns>
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;
}

View File

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

View File

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

View File

@ -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) {

View File

@ -141,7 +141,7 @@ namespace Spine.Unity.Modules {
var sr = GetComponent<SkeletonRenderer>(); 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;
}
}