mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[unity] Fixed errors upon "Reimport All" and related import problems, closes #1248.
This commit is contained in:
parent
e95fca696f
commit
0003e88698
@ -512,9 +512,16 @@ namespace Spine.Unity.Editor {
|
|||||||
return requiredPaths;
|
return requiredPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonDataPath, typeof(TextAsset));
|
TextReader reader = null;
|
||||||
|
TextAsset spineJson = AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonDataPath);
|
||||||
StringReader reader = new StringReader(spineJson.text);
|
if (spineJson != null) {
|
||||||
|
reader = new StringReader(spineJson.text);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// On a "Reimport All" the order of imports can be wrong, thus LoadAssetAtPath() above could return null.
|
||||||
|
// as a workaround, we provide a fallback reader.
|
||||||
|
reader = new StreamReader(skeletonDataPath);
|
||||||
|
}
|
||||||
var root = Json.Deserialize(reader) as Dictionary<string, object>;
|
var root = Json.Deserialize(reader) as Dictionary<string, object>;
|
||||||
|
|
||||||
if (!root.ContainsKey("skins"))
|
if (!root.ContainsKey("skins"))
|
||||||
@ -557,8 +564,16 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
internal static void AddRequiredAtlasRegionsFromBinary (string skeletonDataPath, List<string> requiredPaths) {
|
internal static void AddRequiredAtlasRegionsFromBinary (string skeletonDataPath, List<string> requiredPaths) {
|
||||||
SkeletonBinary binary = new SkeletonBinary(new AtlasRequirementLoader(requiredPaths));
|
SkeletonBinary binary = new SkeletonBinary(new AtlasRequirementLoader(requiredPaths));
|
||||||
TextAsset data = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonDataPath, typeof(TextAsset));
|
Stream input = null;
|
||||||
MemoryStream input = new MemoryStream(data.bytes);
|
TextAsset data = AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonDataPath);
|
||||||
|
if (data != null) {
|
||||||
|
// On a "Reimport All" the order of imports can be wrong, thus LoadAssetAtPath() above could return null.
|
||||||
|
// as a workaround, we provide a fallback reader.
|
||||||
|
input = File.Open(skeletonDataPath, FileMode.Open);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
input = new MemoryStream(data.bytes);
|
||||||
|
}
|
||||||
binary.ReadSkeletonData(input);
|
binary.ReadSkeletonData(input);
|
||||||
binary = null;
|
binary = null;
|
||||||
}
|
}
|
||||||
@ -642,13 +657,13 @@ namespace Spine.Unity.Editor {
|
|||||||
imagePaths.Add(str);
|
imagePaths.Add(str);
|
||||||
break;
|
break;
|
||||||
case ".json":
|
case ".json":
|
||||||
var jsonAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset));
|
var jsonAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(str);
|
||||||
if (jsonAsset != null && IsSpineData(jsonAsset))
|
if (jsonAsset != null && IsSpineData(jsonAsset))
|
||||||
skeletonPaths.Add(str);
|
skeletonPaths.Add(str);
|
||||||
break;
|
break;
|
||||||
case ".bytes":
|
case ".bytes":
|
||||||
if (str.ToLower().EndsWith(".skel.bytes", System.StringComparison.Ordinal)) {
|
if (str.ToLower().EndsWith(".skel.bytes", System.StringComparison.Ordinal)) {
|
||||||
if (IsSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset))))
|
if (IsSpineData(AssetDatabase.LoadAssetAtPath<TextAsset>(str)))
|
||||||
skeletonPaths.Add(str);
|
skeletonPaths.Add(str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -658,7 +673,7 @@ namespace Spine.Unity.Editor {
|
|||||||
// Import atlases first.
|
// Import atlases first.
|
||||||
var atlases = new List<AtlasAssetBase>();
|
var atlases = new List<AtlasAssetBase>();
|
||||||
foreach (string ap in atlasPaths) {
|
foreach (string ap in atlasPaths) {
|
||||||
TextAsset atlasText = (TextAsset)AssetDatabase.LoadAssetAtPath(ap, typeof(TextAsset));
|
TextAsset atlasText = AssetDatabase.LoadAssetAtPath<TextAsset>(ap);
|
||||||
AtlasAssetBase atlas = IngestSpineAtlas(atlasText);
|
AtlasAssetBase atlas = IngestSpineAtlas(atlasText);
|
||||||
atlases.Add(atlas);
|
atlases.Add(atlas);
|
||||||
}
|
}
|
||||||
@ -674,13 +689,13 @@ namespace Spine.Unity.Editor {
|
|||||||
string dir = Path.GetDirectoryName(skeletonPath);
|
string dir = Path.GetDirectoryName(skeletonPath);
|
||||||
|
|
||||||
#if SPINE_TK2D
|
#if SPINE_TK2D
|
||||||
IngestSpineProject(AssetDatabase.LoadAssetAtPath(sp, typeof(TextAsset)) as TextAsset, null);
|
IngestSpineProject(AssetDatabase.LoadAssetAtPath<TextAsset>(sp), null);
|
||||||
#else
|
#else
|
||||||
var localAtlases = FindAtlasesAtPath(dir);
|
var localAtlases = FindAtlasesAtPath(dir);
|
||||||
var requiredPaths = GetRequiredAtlasRegions(skeletonPath);
|
var requiredPaths = GetRequiredAtlasRegions(skeletonPath);
|
||||||
var atlasMatch = GetMatchingAtlas(requiredPaths, localAtlases);
|
var atlasMatch = GetMatchingAtlas(requiredPaths, localAtlases);
|
||||||
if (atlasMatch != null || requiredPaths.Count == 0) {
|
if (atlasMatch != null || requiredPaths.Count == 0) {
|
||||||
IngestSpineProject(AssetDatabase.LoadAssetAtPath(skeletonPath, typeof(TextAsset)) as TextAsset, atlasMatch);
|
IngestSpineProject(AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonPath), atlasMatch);
|
||||||
} else {
|
} else {
|
||||||
SkeletonImportDialog(skeletonPath, localAtlases, requiredPaths, ref abortSkeletonImport);
|
SkeletonImportDialog(skeletonPath, localAtlases, requiredPaths, ref abortSkeletonImport);
|
||||||
}
|
}
|
||||||
@ -694,7 +709,7 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
static void ReloadSkeletonData (string skeletonJSONPath) {
|
static void ReloadSkeletonData (string skeletonJSONPath) {
|
||||||
string dir = Path.GetDirectoryName(skeletonJSONPath);
|
string dir = Path.GetDirectoryName(skeletonJSONPath);
|
||||||
TextAsset textAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonJSONPath, typeof(TextAsset));
|
TextAsset textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonJSONPath);
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(dir);
|
DirectoryInfo dirInfo = new DirectoryInfo(dir);
|
||||||
FileInfo[] files = dirInfo.GetFiles("*.asset");
|
FileInfo[] files = dirInfo.GetFiles("*.asset");
|
||||||
|
|
||||||
@ -960,7 +975,7 @@ namespace Spine.Unity.Editor {
|
|||||||
#region Spine Skeleton Data File Validation
|
#region Spine Skeleton Data File Validation
|
||||||
public static bool CheckForValidSkeletonData (string skeletonJSONPath) {
|
public static bool CheckForValidSkeletonData (string skeletonJSONPath) {
|
||||||
string dir = Path.GetDirectoryName(skeletonJSONPath);
|
string dir = Path.GetDirectoryName(skeletonJSONPath);
|
||||||
TextAsset textAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonJSONPath, typeof(TextAsset));
|
TextAsset textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonJSONPath);
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(dir);
|
DirectoryInfo dirInfo = new DirectoryInfo(dir);
|
||||||
FileInfo[] files = dirInfo.GetFiles("*.asset");
|
FileInfo[] files = dirInfo.GetFiles("*.asset");
|
||||||
|
|
||||||
@ -1068,20 +1083,20 @@ namespace Spine.Unity.Editor {
|
|||||||
var atlasMatch = AssetUtility.GetMatchingAtlas(requiredPaths, localAtlases);
|
var atlasMatch = AssetUtility.GetMatchingAtlas(requiredPaths, localAtlases);
|
||||||
if (atlasMatch != null) {
|
if (atlasMatch != null) {
|
||||||
resolved = true;
|
resolved = true;
|
||||||
AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath(skeletonPath, typeof(TextAsset)) as TextAsset, atlasMatch);
|
AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonPath), atlasMatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0: // Resolve AtlasAssets...
|
case 0: // Resolve AtlasAssets...
|
||||||
var atlasList = MultiAtlasDialog(requiredPaths, Path.GetDirectoryName(skeletonPath), Path.GetFileNameWithoutExtension(skeletonPath));
|
var atlasList = MultiAtlasDialog(requiredPaths, Path.GetDirectoryName(skeletonPath), Path.GetFileNameWithoutExtension(skeletonPath));
|
||||||
if (atlasList != null)
|
if (atlasList != null)
|
||||||
AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath(skeletonPath, typeof(TextAsset)) as TextAsset, atlasList.ToArray());
|
AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonPath), atlasList.ToArray());
|
||||||
|
|
||||||
resolved = true;
|
resolved = true;
|
||||||
break;
|
break;
|
||||||
case 1: // Import without atlas
|
case 1: // Import without atlas
|
||||||
Debug.LogWarning("Imported with missing atlases. Skeleton will not render: " + Path.GetFileName(skeletonPath));
|
Debug.LogWarning("Imported with missing atlases. Skeleton will not render: " + Path.GetFileName(skeletonPath));
|
||||||
AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath(skeletonPath, typeof(TextAsset)) as TextAsset, new AtlasAssetBase[] { });
|
AssetUtility.IngestSpineProject(AssetDatabase.LoadAssetAtPath<TextAsset>(skeletonPath), new AtlasAssetBase[] { });
|
||||||
resolved = true;
|
resolved = true;
|
||||||
break;
|
break;
|
||||||
case 2: // Stop importing all
|
case 2: // Stop importing all
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user