mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Support attachmentless/skinless skeletons.
This commit is contained in:
parent
80a0bc90ab
commit
04cabf7f3c
@ -83,24 +83,6 @@ namespace Spine.Unity.Editor {
|
|||||||
SpineEditorUtilities.ConfirmInitialization();
|
SpineEditorUtilities.ConfirmInitialization();
|
||||||
m_skeletonDataAsset = (SkeletonDataAsset)target;
|
m_skeletonDataAsset = (SkeletonDataAsset)target;
|
||||||
|
|
||||||
// Clear empty atlas array items.
|
|
||||||
{
|
|
||||||
bool hasNulls = false;
|
|
||||||
foreach (var a in m_skeletonDataAsset.atlasAssets) {
|
|
||||||
if (a == null) {
|
|
||||||
hasNulls = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasNulls) {
|
|
||||||
var trimmedAtlasAssets = new List<AtlasAsset>();
|
|
||||||
foreach (var a in m_skeletonDataAsset.atlasAssets) {
|
|
||||||
if (a != null) trimmedAtlasAssets.Add(a);
|
|
||||||
}
|
|
||||||
m_skeletonDataAsset.atlasAssets = trimmedAtlasAssets.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
atlasAssets = serializedObject.FindProperty("atlasAssets");
|
atlasAssets = serializedObject.FindProperty("atlasAssets");
|
||||||
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
|
skeletonJSON = serializedObject.FindProperty("skeletonJSON");
|
||||||
scale = serializedObject.FindProperty("scale");
|
scale = serializedObject.FindProperty("scale");
|
||||||
@ -126,8 +108,8 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
|
m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
|
||||||
EditorApplication.update += EditorUpdate;
|
EditorApplication.update += EditorUpdate;
|
||||||
m_skeletonData = m_skeletonDataAsset.GetSkeletonData(false);
|
|
||||||
RepopulateWarnings();
|
RepopulateWarnings();
|
||||||
|
m_skeletonData = warnings.Count == 0 ? m_skeletonDataAsset.GetSkeletonData(false) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnDestroy () {
|
void OnDestroy () {
|
||||||
@ -228,8 +210,9 @@ namespace Spine.Unity.Editor {
|
|||||||
m_previewUtility.Cleanup();
|
m_previewUtility.Cleanup();
|
||||||
m_previewUtility = null;
|
m_previewUtility = null;
|
||||||
}
|
}
|
||||||
RepopulateWarnings();
|
m_skeletonDataAsset.Clear();
|
||||||
OnEnable();
|
m_skeletonData = null;
|
||||||
|
OnEnable(); // Should call RepopulateWarnings.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,7 +241,6 @@ namespace Spine.Unity.Editor {
|
|||||||
using (new EditorGUI.DisabledGroupScope(skeletonJSON.objectReferenceValue == null)) {
|
using (new EditorGUI.DisabledGroupScope(skeletonJSON.objectReferenceValue == null)) {
|
||||||
if (GUILayout.Button(new GUIContent("Attempt Reimport", Icons.warning))) {
|
if (GUILayout.Button(new GUIContent("Attempt Reimport", Icons.warning))) {
|
||||||
DoReimport();
|
DoReimport();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -376,15 +358,12 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
void DoReimport () {
|
void DoReimport () {
|
||||||
SpineEditorUtilities.ImportSpineContent(new string[] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
|
SpineEditorUtilities.ImportSpineContent(new string[] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
|
||||||
|
|
||||||
if (m_previewUtility != null) {
|
if (m_previewUtility != null) {
|
||||||
m_previewUtility.Cleanup();
|
m_previewUtility.Cleanup();
|
||||||
m_previewUtility = null;
|
m_previewUtility = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
RepopulateWarnings();
|
OnEnable(); // Should call RepopulateWarnings.
|
||||||
OnEnable();
|
|
||||||
|
|
||||||
EditorUtility.SetDirty(m_skeletonDataAsset);
|
EditorUtility.SetDirty(m_skeletonDataAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,6 +514,25 @@ namespace Spine.Unity.Editor {
|
|||||||
void RepopulateWarnings () {
|
void RepopulateWarnings () {
|
||||||
warnings.Clear();
|
warnings.Clear();
|
||||||
|
|
||||||
|
// Clear null entries.
|
||||||
|
{
|
||||||
|
bool hasNulls = false;
|
||||||
|
foreach (var a in m_skeletonDataAsset.atlasAssets) {
|
||||||
|
if (a == null) {
|
||||||
|
hasNulls = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasNulls) {
|
||||||
|
var trimmedAtlasAssets = new List<AtlasAsset>();
|
||||||
|
foreach (var a in m_skeletonDataAsset.atlasAssets) {
|
||||||
|
if (a != null) trimmedAtlasAssets.Add(a);
|
||||||
|
}
|
||||||
|
m_skeletonDataAsset.atlasAssets = trimmedAtlasAssets.ToArray();
|
||||||
|
}
|
||||||
|
serializedObject.Update();
|
||||||
|
}
|
||||||
|
|
||||||
if (skeletonJSON.objectReferenceValue == null) {
|
if (skeletonJSON.objectReferenceValue == null) {
|
||||||
warnings.Add("Missing Skeleton JSON");
|
warnings.Add("Missing Skeleton JSON");
|
||||||
} else {
|
} else {
|
||||||
@ -544,12 +542,13 @@ namespace Spine.Unity.Editor {
|
|||||||
#if !SPINE_TK2D
|
#if !SPINE_TK2D
|
||||||
bool detectedNullAtlasEntry = false;
|
bool detectedNullAtlasEntry = false;
|
||||||
var atlasList = new List<Atlas>();
|
var atlasList = new List<Atlas>();
|
||||||
for (int i = 0; i < atlasAssets.arraySize; i++) {
|
var actualAtlasAssets = m_skeletonDataAsset.atlasAssets;
|
||||||
if (atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue == null) {
|
for (int i = 0; i < actualAtlasAssets.Length; i++) {
|
||||||
|
if (m_skeletonDataAsset.atlasAssets[i] == null) {
|
||||||
detectedNullAtlasEntry = true;
|
detectedNullAtlasEntry = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
atlasList.Add(((AtlasAsset)atlasAssets.GetArrayElementAtIndex(i).objectReferenceValue).GetAtlas());
|
atlasList.Add(actualAtlasAssets[i].GetAtlas());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,26 +641,37 @@ namespace Spine.Unity.Editor {
|
|||||||
void CreatePreviewInstances () {
|
void CreatePreviewInstances () {
|
||||||
this.DestroyPreviewInstances();
|
this.DestroyPreviewInstances();
|
||||||
|
|
||||||
|
if (warnings.Count > 0) {
|
||||||
|
m_skeletonDataAsset.Clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var skeletonDataAsset = (SkeletonDataAsset)target;
|
var skeletonDataAsset = (SkeletonDataAsset)target;
|
||||||
if (skeletonDataAsset.GetSkeletonData(false) == null)
|
if (skeletonDataAsset.GetSkeletonData(false) == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this.m_previewInstance == null) {
|
if (this.m_previewInstance == null) {
|
||||||
string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", "");
|
string skinName = EditorPrefs.GetString(m_skeletonDataAssetGUID + "_lastSkin", "");
|
||||||
m_previewInstance = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;
|
|
||||||
|
|
||||||
if (m_previewInstance != null) {
|
try {
|
||||||
m_previewInstance.hideFlags = HideFlags.HideAndDontSave;
|
m_previewInstance = SpineEditorUtilities.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;
|
||||||
m_previewInstance.layer = 0x1f;
|
|
||||||
m_skeletonAnimation = m_previewInstance.GetComponent<SkeletonAnimation>();
|
if (m_previewInstance != null) {
|
||||||
m_skeletonAnimation.initialSkinName = skinName;
|
m_previewInstance.hideFlags = HideFlags.HideAndDontSave;
|
||||||
m_skeletonAnimation.LateUpdate();
|
m_previewInstance.layer = 0x1f;
|
||||||
m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true);
|
m_skeletonAnimation = m_previewInstance.GetComponent<SkeletonAnimation>();
|
||||||
m_previewInstance.GetComponent<Renderer>().enabled = false;
|
m_skeletonAnimation.initialSkinName = skinName;
|
||||||
m_initialized = true;
|
m_skeletonAnimation.LateUpdate();
|
||||||
|
m_skeletonData = m_skeletonAnimation.skeletonDataAsset.GetSkeletonData(true);
|
||||||
|
m_previewInstance.GetComponent<Renderer>().enabled = false;
|
||||||
|
m_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
AdjustCameraGoals(true);
|
||||||
|
} catch {
|
||||||
|
DestroyPreviewInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
AdjustCameraGoals(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -89,14 +89,6 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SkeletonData GetSkeletonData (bool quiet) {
|
public SkeletonData GetSkeletonData (bool quiet) {
|
||||||
if (atlasAssets == null) {
|
|
||||||
atlasAssets = new AtlasAsset[0];
|
|
||||||
if (!quiet)
|
|
||||||
Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
|
|
||||||
Clear();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skeletonJSON == null) {
|
if (skeletonJSON == null) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
|
Debug.LogError("Skeleton JSON file not set for SkeletonData asset: " + name, this);
|
||||||
@ -104,17 +96,26 @@ namespace Spine.Unity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !SPINE_TK2D
|
// Support attachmentless/skinless SkeletonData.
|
||||||
if (atlasAssets.Length == 0) {
|
// if (atlasAssets == null) {
|
||||||
Clear();
|
// atlasAssets = new AtlasAsset[0];
|
||||||
return null;
|
// if (!quiet)
|
||||||
}
|
// Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
|
||||||
#else
|
// Clear();
|
||||||
if (atlasAssets.Length == 0 && spriteCollection == null) {
|
// return null;
|
||||||
Clear();
|
// }
|
||||||
return null;
|
// #if !SPINE_TK2D
|
||||||
}
|
// if (atlasAssets.Length == 0) {
|
||||||
#endif
|
// Clear();
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// #else
|
||||||
|
// if (atlasAssets.Length == 0 && spriteCollection == null) {
|
||||||
|
// Clear();
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
|
||||||
if (skeletonData != null)
|
if (skeletonData != null)
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
|
|
||||||
|
|||||||
@ -215,7 +215,8 @@ namespace Spine.Unity.Editor {
|
|||||||
skinIndex = i;
|
skinIndex = i;
|
||||||
}
|
}
|
||||||
skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins);
|
skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins);
|
||||||
initialSkinName.stringValue = skins[skinIndex];
|
if (skins.Length > 0) // Support attachmentless/skinless SkeletonData.
|
||||||
|
initialSkinName.stringValue = skins[skinIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -603,7 +603,7 @@ namespace Spine.Unity.Editor {
|
|||||||
var localAtlases = FindAtlasesAtPath(dir);
|
var localAtlases = FindAtlasesAtPath(dir);
|
||||||
var requiredPaths = GetRequiredAtlasRegions(sp);
|
var requiredPaths = GetRequiredAtlasRegions(sp);
|
||||||
var atlasMatch = GetMatchingAtlas(requiredPaths, localAtlases);
|
var atlasMatch = GetMatchingAtlas(requiredPaths, localAtlases);
|
||||||
if (atlasMatch != null) {
|
if (atlasMatch != null || requiredPaths.Count == 0) {
|
||||||
IngestSpineProject(AssetDatabase.LoadAssetAtPath(sp, typeof(TextAsset)) as TextAsset, atlasMatch);
|
IngestSpineProject(AssetDatabase.LoadAssetAtPath(sp, typeof(TextAsset)) as TextAsset, atlasMatch);
|
||||||
} else {
|
} else {
|
||||||
bool resolved = false;
|
bool resolved = false;
|
||||||
@ -830,6 +830,8 @@ namespace Spine.Unity.Editor {
|
|||||||
StringReader reader = new StringReader(spineJson.text);
|
StringReader reader = new StringReader(spineJson.text);
|
||||||
var root = Json.Deserialize(reader) as Dictionary<string, object>;
|
var root = Json.Deserialize(reader) as Dictionary<string, object>;
|
||||||
|
|
||||||
|
if (!root.ContainsKey("skins"))
|
||||||
|
return requiredPaths;
|
||||||
|
|
||||||
foreach (KeyValuePair<string, object> entry in (Dictionary<string, object>)root["skins"]) {
|
foreach (KeyValuePair<string, object> entry in (Dictionary<string, object>)root["skins"]) {
|
||||||
foreach (KeyValuePair<string, object> slotEntry in (Dictionary<string, object>)entry.Value) {
|
foreach (KeyValuePair<string, object> slotEntry in (Dictionary<string, object>)entry.Value) {
|
||||||
@ -1326,9 +1328,12 @@ namespace Spine.Unity.Editor {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
skin = skin ?? data.DefaultSkin ?? data.Skins.Items[0];
|
bool noSkins = data.DefaultSkin == null && (data.Skins == null || data.Skins.Count == 0); // Support attachmentless/skinless SkeletonData.
|
||||||
newSkeletonAnimation.skeleton.SetSkin(skin);
|
skin = skin ?? data.DefaultSkin ?? (noSkins ? null : data.Skins.Items[0]);
|
||||||
newSkeletonAnimation.initialSkinName = skin.Name;
|
if (skin != null) {
|
||||||
|
newSkeletonAnimation.initialSkinName = skin.Name;
|
||||||
|
newSkeletonAnimation.skeleton.SetSkin(skin);
|
||||||
|
}
|
||||||
|
|
||||||
newSkeletonAnimation.skeleton.Update(0);
|
newSkeletonAnimation.skeleton.Update(0);
|
||||||
newSkeletonAnimation.state.Update(0);
|
newSkeletonAnimation.state.Update(0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user