mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
SkeletonDataAsset can now parse binary files.
Left benchmark code commented out.
This commit is contained in:
parent
d0625e06a0
commit
1ccef4f1cf
BIN
spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes
Normal file
BIN
spine-unity/Assets/Examples/Spine/Raptor/raptor.skel.bytes
Normal file
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d6edb328bfcef44a9d1bf852e5724bc
|
||||
timeCreated: 1427642224
|
||||
licenseType: Free
|
||||
TextScriptImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -455,8 +455,8 @@ public class SkeletonDataAssetInspector : Editor {
|
||||
warnings.Add("Missing Skeleton JSON");
|
||||
else {
|
||||
|
||||
if (SpineEditorUtilities.IsSpineJSON((TextAsset)skeletonJSON.objectReferenceValue) == false) {
|
||||
warnings.Add("Skeleton JSON is not a Valid JSON file");
|
||||
if (SpineEditorUtilities.IsValidSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) {
|
||||
warnings.Add("Skeleton data file is not a valid JSON or binary file.");
|
||||
} else {
|
||||
bool detectedNullAtlasEntry = false;
|
||||
List<Atlas> atlasList = new List<Atlas>();
|
||||
|
||||
@ -251,8 +251,8 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
imagePaths.Add(str);
|
||||
break;
|
||||
case ".json":
|
||||
TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset));
|
||||
if (IsSpineJSON(spineJson)) {
|
||||
TextAsset spineDataFile = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset));
|
||||
if (IsValidSpineData(spineDataFile)) {
|
||||
skeletonPaths.Add(str);
|
||||
}
|
||||
break;
|
||||
@ -518,6 +518,9 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
public static List<string> GetRequiredAtlasRegions (string jsonPath) {
|
||||
List<string> requiredPaths = new List<string>();
|
||||
|
||||
// FIXME - This doesn't work for a binary skeleton file!
|
||||
if (jsonPath.Contains(".skel")) return requiredPaths;
|
||||
|
||||
TextAsset spineJson = (TextAsset)AssetDatabase.LoadAssetAtPath(jsonPath, typeof(TextAsset));
|
||||
|
||||
StringReader reader = new StringReader(spineJson.text);
|
||||
@ -592,8 +595,14 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static bool IsSpineJSON (TextAsset asset) {
|
||||
object obj = Json.Deserialize(new StringReader(asset.text));
|
||||
public static bool IsValidSpineData (TextAsset asset) {
|
||||
if (asset.name.Contains(".skel")) return true;
|
||||
|
||||
object obj = null;
|
||||
try {
|
||||
obj = Json.Deserialize(new StringReader(asset.text));
|
||||
} catch (System.Exception) {
|
||||
}
|
||||
if (obj == null) {
|
||||
Debug.LogError("Is not valid JSON");
|
||||
return false;
|
||||
|
||||
@ -97,31 +97,45 @@ public class SkeletonDataAsset : ScriptableObject {
|
||||
|
||||
if (skeletonData != null)
|
||||
return skeletonData;
|
||||
|
||||
SkeletonJson json;
|
||||
|
||||
AttachmentLoader attachmentLoader;
|
||||
float skeletonDataScale;
|
||||
|
||||
#if !SPINE_TK2D
|
||||
json = new SkeletonJson(atlasArr);
|
||||
json.Scale = scale;
|
||||
attachmentLoader = new AtlasAttachmentLoader(atlasArr);
|
||||
skeletonDataScale = scale;
|
||||
#else
|
||||
if (spriteCollection != null) {
|
||||
json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection));
|
||||
json.Scale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f;
|
||||
attachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection)
|
||||
skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale) * 100f;
|
||||
} else {
|
||||
if (atlasArr.Length == 0) {
|
||||
Reset();
|
||||
if (!quiet)
|
||||
Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
|
||||
if (!quiet) Debug.LogError("Atlas not set for SkeletonData asset: " + name, this);
|
||||
return null;
|
||||
}
|
||||
json = new SkeletonJson(atlasArr);
|
||||
json.Scale = scale;
|
||||
attachmentLoader = new AtlasAttachmentLoader(atlasArr);
|
||||
skeletonDataScale = scale;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
try {
|
||||
skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
|
||||
//var stopwatch = new System.Diagnostics.Stopwatch();
|
||||
if (skeletonJSON.name.ToLower().Contains(".skel")) {
|
||||
var input = new MemoryStream(skeletonJSON.bytes);
|
||||
var binary = new SkeletonBinary(attachmentLoader);
|
||||
binary.Scale = skeletonDataScale;
|
||||
//stopwatch.Start();
|
||||
skeletonData = binary.ReadSkeletonData(input);
|
||||
} else {
|
||||
var input = new StringReader(skeletonJSON.text);
|
||||
var json = new SkeletonJson(attachmentLoader);
|
||||
json.Scale = skeletonDataScale;
|
||||
//stopwatch.Start();
|
||||
skeletonData = json.ReadSkeletonData(input);
|
||||
}
|
||||
//stopwatch.Stop();
|
||||
//Debug.Log(stopwatch.Elapsed);
|
||||
} catch (Exception ex) {
|
||||
if (!quiet)
|
||||
Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user