mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-07 19:26:54 +08:00
Merge pull request #397 from Fenrisul/master
Implemented SkeletonBinary for spine-unity runtimes.
This commit is contained in:
commit
d5c68c5d7b
@ -34,6 +34,7 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
#if !UNITY_4_3
|
#if !UNITY_4_3
|
||||||
@ -123,6 +124,10 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
EditorGUILayout.PropertyField(spriteCollection, true);
|
EditorGUILayout.PropertyField(spriteCollection, true);
|
||||||
#endif
|
#endif
|
||||||
EditorGUILayout.PropertyField(skeletonJSON);
|
EditorGUILayout.PropertyField(skeletonJSON);
|
||||||
|
GUILayout.Label("Load Time: " + m_skeletonDataAsset.LoadTime + "ms");
|
||||||
|
if (IsBinary) {
|
||||||
|
GUILayout.Label(new GUIContent("Binary Mode Engaged! Hold on to your pants!", SpineEditorUtilities.Icons.warning));
|
||||||
|
}
|
||||||
EditorGUILayout.PropertyField(scale);
|
EditorGUILayout.PropertyField(scale);
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
if (serializedObject.ApplyModifiedProperties()) {
|
if (serializedObject.ApplyModifiedProperties()) {
|
||||||
@ -256,6 +261,18 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
m_previewUtility = null;
|
m_previewUtility = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Temporary Binary atlas name-match reimport
|
||||||
|
if (IsBinary && m_skeletonData == null) {
|
||||||
|
string dirPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(m_skeletonDataAsset));
|
||||||
|
string maybeAtlasPath = Path.Combine(dirPath, m_skeletonDataAsset.skeletonJSON.name.Replace(".skel", "_Atlas.asset"));
|
||||||
|
if (File.Exists(maybeAtlasPath)) {
|
||||||
|
var atlas = (AtlasAsset)AssetDatabase.LoadAssetAtPath(maybeAtlasPath, typeof(AtlasAsset));
|
||||||
|
if (atlas != null) {
|
||||||
|
m_skeletonDataAsset.atlasAssets = new AtlasAsset[1] { atlas };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RepopulateWarnings();
|
RepopulateWarnings();
|
||||||
OnEnable();
|
OnEnable();
|
||||||
|
|
||||||
@ -447,6 +464,14 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsBinary {
|
||||||
|
get {
|
||||||
|
if (skeletonJSON.objectReferenceValue == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return skeletonJSON.objectReferenceValue.name.EndsWith(".skel");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void RepopulateWarnings () {
|
void RepopulateWarnings () {
|
||||||
warnings.Clear();
|
warnings.Clear();
|
||||||
@ -455,7 +480,12 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
warnings.Add("Missing Skeleton JSON");
|
warnings.Add("Missing Skeleton JSON");
|
||||||
else {
|
else {
|
||||||
|
|
||||||
if (SpineEditorUtilities.IsSpineJSON((TextAsset)skeletonJSON.objectReferenceValue) == false) {
|
if (IsBinary) {
|
||||||
|
//can't pre process binary yet
|
||||||
|
warnings.Add("Cannot analyze Skeleton Binary for errors!");
|
||||||
|
warnings.Add("Probably can't attempt reimport yet either :)");
|
||||||
|
}
|
||||||
|
else if (SpineEditorUtilities.IsSpineJSON((TextAsset)skeletonJSON.objectReferenceValue) == false) {
|
||||||
warnings.Add("Skeleton JSON is not a Valid JSON file");
|
warnings.Add("Skeleton JSON is not a Valid JSON file");
|
||||||
} else {
|
} else {
|
||||||
bool detectedNullAtlasEntry = false;
|
bool detectedNullAtlasEntry = false;
|
||||||
@ -486,9 +516,6 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
|
|
||||||
foreach (var str in missingPaths)
|
foreach (var str in missingPaths)
|
||||||
warnings.Add("Missing Region: '" + str + "'");
|
warnings.Add("Missing Region: '" + str + "'");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,15 @@ public class SkeletonDataAsset : ScriptableObject {
|
|||||||
public RuntimeAnimatorController controller;
|
public RuntimeAnimatorController controller;
|
||||||
private SkeletonData skeletonData;
|
private SkeletonData skeletonData;
|
||||||
private AnimationStateData stateData;
|
private AnimationStateData stateData;
|
||||||
|
private double loadTime = -1;
|
||||||
|
|
||||||
|
public double LoadTime {
|
||||||
|
get {
|
||||||
|
return loadTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Reset() {
|
public void Reset() {
|
||||||
skeletonData = null;
|
skeletonData = null;
|
||||||
@ -55,6 +64,13 @@ public class SkeletonDataAsset : ScriptableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SkeletonData GetSkeletonData(bool quiet) {
|
public SkeletonData GetSkeletonData(bool quiet) {
|
||||||
|
if (skeletonData == null) {
|
||||||
|
loadTime = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DateTime startLoadTime = DateTime.Now;
|
||||||
|
|
||||||
if (atlasAssets == null) {
|
if (atlasAssets == null) {
|
||||||
atlasAssets = new AtlasAsset[0];
|
atlasAssets = new AtlasAsset[0];
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
@ -98,11 +114,43 @@ public class SkeletonDataAsset : ScriptableObject {
|
|||||||
if (skeletonData != null)
|
if (skeletonData != null)
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
|
|
||||||
SkeletonJson json;
|
bool isBinary = skeletonJSON.name.EndsWith(".skel");
|
||||||
|
|
||||||
|
if (isBinary) {
|
||||||
|
SkeletonBinary binary;
|
||||||
|
|
||||||
#if !SPINE_TK2D
|
#if !SPINE_TK2D
|
||||||
json = new SkeletonJson(atlasArr);
|
binary = new SkeletonBinary(atlasArr);
|
||||||
json.Scale = scale;
|
binary.Scale = scale;
|
||||||
|
#else
|
||||||
|
if (spriteCollection != null) {
|
||||||
|
binary = new SkeletonBinary(new SpriteCollectionAttachmentLoader(spriteCollection));
|
||||||
|
binary.Scale = (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);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
binary = new SkeletonBinary(atlasArr);
|
||||||
|
binary.Scale = scale;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
try {
|
||||||
|
skeletonData = binary.ReadSkeletonData(new BufferedStream(new MemoryStream(skeletonJSON.bytes)));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (!quiet)
|
||||||
|
Debug.LogError("Error reading skeleton binary file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
SkeletonJson json;
|
||||||
|
|
||||||
|
#if !SPINE_TK2D
|
||||||
|
json = new SkeletonJson(atlasArr);
|
||||||
|
json.Scale = scale;
|
||||||
#else
|
#else
|
||||||
if (spriteCollection != null) {
|
if (spriteCollection != null) {
|
||||||
json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection));
|
json = new SkeletonJson(new SpriteCollectionAttachmentLoader(spriteCollection));
|
||||||
@ -119,18 +167,21 @@ public class SkeletonDataAsset : ScriptableObject {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
|
skeletonData = json.ReadSkeletonData(new StringReader(skeletonJSON.text));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
|
Debug.LogError("Error reading skeleton JSON file for SkeletonData asset: " + name + "\n" + ex.Message + "\n" + ex.StackTrace, this);
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stateData = new AnimationStateData(skeletonData);
|
stateData = new AnimationStateData(skeletonData);
|
||||||
FillStateData();
|
FillStateData();
|
||||||
|
|
||||||
|
loadTime = (DateTime.Now - startLoadTime).TotalMilliseconds;
|
||||||
|
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user