[tk2d] Allow Spine.AtlasAsset fallback for TK2D in inspector.

This commit is contained in:
pharan 2017-06-26 14:16:14 +08:00
parent f62e2e12b8
commit 83d45b5492
2 changed files with 49 additions and 36 deletions

View File

@ -74,7 +74,8 @@ namespace Spine.Unity.Editor {
SpineEditorUtilities.ConfirmInitialization(); SpineEditorUtilities.ConfirmInitialization();
m_skeletonDataAsset = (SkeletonDataAsset)target; m_skeletonDataAsset = (SkeletonDataAsset)target;
atlasAssets = serializedObject.FindProperty("atlasAssets"); bool newAtlasAssets = atlasAssets == null;
if (newAtlasAssets) atlasAssets = serializedObject.FindProperty("atlasAssets");
skeletonJSON = serializedObject.FindProperty("skeletonJSON"); skeletonJSON = serializedObject.FindProperty("skeletonJSON");
scale = serializedObject.FindProperty("scale"); scale = serializedObject.FindProperty("scale");
fromAnimation = serializedObject.FindProperty("fromAnimation"); fromAnimation = serializedObject.FindProperty("fromAnimation");
@ -87,10 +88,10 @@ namespace Spine.Unity.Editor {
#endif #endif
#if SPINE_TK2D #if SPINE_TK2D
atlasAssets.isExpanded = false; if (newAtlasAssets) atlasAssets.isExpanded = false;
spriteCollection = serializedObject.FindProperty("spriteCollection"); spriteCollection = serializedObject.FindProperty("spriteCollection");
#else #else
atlasAssets.isExpanded = true; if (newAtlasAssets) atlasAssets.isExpanded = true;
#endif #endif
m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset)); m_skeletonDataAssetGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
@ -470,44 +471,56 @@ namespace Spine.Unity.Editor {
if (SpineEditorUtilities.IsSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) { if (SpineEditorUtilities.IsSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) {
warnings.Add("Skeleton data file is not a valid JSON or binary file."); warnings.Add("Skeleton data file is not a valid JSON or binary file.");
} else { } else {
#if !SPINE_TK2D #if SPINE_TK2D
bool detectedNullAtlasEntry = false; bool searchForSpineAtlasAssets = true;
var atlasList = new List<Atlas>(); bool isSpriteCollectionNull = spriteCollection.objectReferenceValue == null;
var actualAtlasAssets = m_skeletonDataAsset.atlasAssets; if (!isSpriteCollectionNull) searchForSpineAtlasAssets = false;
for (int i = 0; i < actualAtlasAssets.Length; i++) { //else
if (m_skeletonDataAsset.atlasAssets[i] == null) { // warnings.Add("Your sprite collection may have missing images.");
detectedNullAtlasEntry = true; #else
break; const bool searchForSpineAtlasAssets = true;
} else { #endif
atlasList.Add(actualAtlasAssets[i].GetAtlas());
}
}
if (detectedNullAtlasEntry) if (searchForSpineAtlasAssets) {
warnings.Add("AtlasAsset elements should not be null."); bool detectedNullAtlasEntry = false;
else { var atlasList = new List<Atlas>();
// Get requirements. var actualAtlasAssets = m_skeletonDataAsset.atlasAssets;
var missingPaths = SpineEditorUtilities.GetRequiredAtlasRegions(AssetDatabase.GetAssetPath((TextAsset)skeletonJSON.objectReferenceValue));
foreach (var atlas in atlasList) { for (int i = 0; i < actualAtlasAssets.Length; i++) {
for (int i = 0; i < missingPaths.Count; i++) { if (m_skeletonDataAsset.atlasAssets[i] == null) {
if (atlas.FindRegion(missingPaths[i]) != null) { detectedNullAtlasEntry = true;
missingPaths.RemoveAt(i); break;
i--; } else {
} atlasList.Add(actualAtlasAssets[i].GetAtlas());
} }
} }
foreach (var str in missingPaths) if (detectedNullAtlasEntry) {
warnings.Add("Missing Region: '" + str + "'"); warnings.Add("AtlasAsset elements should not 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--;
}
}
}
#if SPINE_TK2D
if (missingPaths.Count > 0)
warnings.Add("Missing regions. SkeletonDataAsset requires tk2DSpriteCollectionData or Spine AtlasAssets.");
#endif
foreach (var str in missingPaths)
warnings.Add("Missing Region: '" + str + "'");
}
} }
#else
if (spriteCollection.objectReferenceValue == null)
warnings.Add("SkeletonDataAsset requires tk2DSpriteCollectionData.");
// else
// warnings.Add("Your sprite collection may have missing images.");
#endif
} }
} }
} }

View File

@ -357,7 +357,7 @@ namespace Spine.Unity {
material = (Material)((AtlasRegion)rendererObject).page.rendererObject; material = (Material)((AtlasRegion)rendererObject).page.rendererObject;
} }
#else #else
Material material = (rendererObject.GetType() == typeof(Material)) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject; Material material = (rendererObject is Material) ? (Material)rendererObject : (Material)((AtlasRegion)rendererObject).page.rendererObject;
#endif #endif
if (current.forceSeparate || (current.rawVertexCount > 0 && !System.Object.ReferenceEquals(current.material, material))) { // Material changed. Add the previous submesh. if (current.forceSeparate || (current.rawVertexCount > 0 && !System.Object.ReferenceEquals(current.material, material))) { // Material changed. Add the previous submesh.