mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Updates to asset types for custom loading.
This commit is contained in:
parent
2e086ff11c
commit
c54cb820fe
@ -41,6 +41,8 @@ namespace Spine.Unity {
|
|||||||
public Material[] materials;
|
public Material[] materials;
|
||||||
protected Atlas atlas;
|
protected Atlas atlas;
|
||||||
|
|
||||||
|
public bool IsLoaded { get { return this.atlas != null; } }
|
||||||
|
|
||||||
#region Runtime Instantiation
|
#region Runtime Instantiation
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a runtime AtlasAsset</summary>
|
/// Creates a runtime AtlasAsset</summary>
|
||||||
@ -122,8 +124,7 @@ namespace Spine.Unity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atlas != null)
|
if (atlas != null) return atlas;
|
||||||
return atlas;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
atlas = new Atlas(new StringReader(atlasFile.text), "", new MaterialsTextureLoader(this));
|
atlas = new Atlas(new StringReader(atlasFile.text), "", new MaterialsTextureLoader(this));
|
||||||
@ -201,7 +202,7 @@ namespace Spine.Unity {
|
|||||||
this.atlasAsset = atlasAsset;
|
this.atlasAsset = atlasAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load (AtlasPage page, String path) {
|
public void Load (AtlasPage page, string path) {
|
||||||
String name = Path.GetFileNameWithoutExtension(path);
|
String name = Path.GetFileNameWithoutExtension(path);
|
||||||
Material material = null;
|
Material material = null;
|
||||||
foreach (Material other in atlasAsset.materials) {
|
foreach (Material other in atlasAsset.materials) {
|
||||||
@ -227,7 +228,6 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unload (object texture) {
|
public void Unload (object texture) { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -79,9 +79,27 @@ namespace Spine.Unity.Editor {
|
|||||||
GUIStyle activePlayButtonStyle, idlePlayButtonStyle;
|
GUIStyle activePlayButtonStyle, idlePlayButtonStyle;
|
||||||
readonly GUIContent DefaultMixLabel = new GUIContent("Default Mix Duration", "Sets 'SkeletonDataAsset.defaultMix' in the asset and 'AnimationState.data.defaultMix' at runtime load time.");
|
readonly GUIContent DefaultMixLabel = new GUIContent("Default Mix Duration", "Sets 'SkeletonDataAsset.defaultMix' in the asset and 'AnimationState.data.defaultMix' at runtime load time.");
|
||||||
|
|
||||||
|
|
||||||
void OnEnable () {
|
void OnEnable () {
|
||||||
SpineEditorUtilities.ConfirmInitialization();
|
SpineEditorUtilities.ConfirmInitialization();
|
||||||
|
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");
|
||||||
@ -106,7 +124,6 @@ namespace Spine.Unity.Editor {
|
|||||||
isBakingExpanded = EditorPrefs.GetBool(ShowBakingPrefsKey, false);
|
isBakingExpanded = EditorPrefs.GetBool(ShowBakingPrefsKey, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_skeletonDataAsset = (SkeletonDataAsset)target;
|
|
||||||
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);
|
m_skeletonData = m_skeletonDataAsset.GetSkeletonData(false);
|
||||||
@ -125,7 +142,6 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
override public void OnInspectorGUI () {
|
override public void OnInspectorGUI () {
|
||||||
{
|
{
|
||||||
|
|
||||||
// Lazy initialization because accessing EditorStyles values in OnEnable during a recompile causes UnityEditor to throw null exceptions. (Unity 5.3.5)
|
// Lazy initialization because accessing EditorStyles values in OnEnable during a recompile causes UnityEditor to throw null exceptions. (Unity 5.3.5)
|
||||||
idlePlayButtonStyle = idlePlayButtonStyle ?? new GUIStyle(EditorStyles.miniButton);
|
idlePlayButtonStyle = idlePlayButtonStyle ?? new GUIStyle(EditorStyles.miniButton);
|
||||||
if (activePlayButtonStyle == null) {
|
if (activePlayButtonStyle == null) {
|
||||||
@ -207,7 +223,6 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
DrawSlotList();
|
DrawSlotList();
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
DrawUnityTools();
|
DrawUnityTools();
|
||||||
} else {
|
} else {
|
||||||
#if !SPINE_TK2D
|
#if !SPINE_TK2D
|
||||||
@ -483,10 +498,6 @@ namespace Spine.Unity.Editor {
|
|||||||
icon = Icons.warning;
|
icon = Icons.warning;
|
||||||
//JOHN: left todo: Icon for paths. Generic icon for unidentified attachments.
|
//JOHN: left todo: Icon for paths. Generic icon for unidentified attachments.
|
||||||
|
|
||||||
// MITCH: left todo: Waterboard Nate
|
|
||||||
//if (name != attachment.Name)
|
|
||||||
//icon = SpineEditorUtilities.Icons.skinPlaceholder;
|
|
||||||
|
|
||||||
bool initialState = slot.Attachment == attachment;
|
bool initialState = slot.Attachment == attachment;
|
||||||
|
|
||||||
bool toggled = EditorGUILayout.ToggleLeft(new GUIContent(attachmentName, icon), slot.Attachment == attachment);
|
bool toggled = EditorGUILayout.ToggleLeft(new GUIContent(attachmentName, icon), slot.Attachment == attachment);
|
||||||
@ -606,11 +617,12 @@ namespace Spine.Unity.Editor {
|
|||||||
if (this.m_previewUtility == null) {
|
if (this.m_previewUtility == null) {
|
||||||
this.m_lastTime = Time.realtimeSinceStartup;
|
this.m_lastTime = Time.realtimeSinceStartup;
|
||||||
this.m_previewUtility = new PreviewRenderUtility(true);
|
this.m_previewUtility = new PreviewRenderUtility(true);
|
||||||
this.m_previewUtility.m_Camera.orthographic = true;
|
var c = this.m_previewUtility.m_Camera;
|
||||||
this.m_previewUtility.m_Camera.orthographicSize = 1;
|
c.orthographic = true;
|
||||||
this.m_previewUtility.m_Camera.cullingMask = -2147483648;
|
c.orthographicSize = 1;
|
||||||
this.m_previewUtility.m_Camera.nearClipPlane = 0.01f;
|
c.cullingMask = -2147483648;
|
||||||
this.m_previewUtility.m_Camera.farClipPlane = 1000f;
|
c.nearClipPlane = 0.01f;
|
||||||
|
c.farClipPlane = 1000f;
|
||||||
this.CreatePreviewInstances();
|
this.CreatePreviewInstances();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,8 @@ namespace Spine.Unity {
|
|||||||
public float defaultMix;
|
public float defaultMix;
|
||||||
public RuntimeAnimatorController controller;
|
public RuntimeAnimatorController controller;
|
||||||
|
|
||||||
|
public bool IsLoaded { get { return this.skeletonData != null; } }
|
||||||
|
|
||||||
void Reset () {
|
void Reset () {
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
@ -109,77 +111,90 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (atlasAssets.Length == 0 && spriteCollection == null) {
|
if (atlasAssets.Length == 0 && spriteCollection == null) {
|
||||||
Reset();
|
Clear();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Atlas[] atlasArr = new Atlas[atlasAssets.Length];
|
|
||||||
for (int i = 0; i < atlasAssets.Length; i++) {
|
|
||||||
if (atlasAssets[i] == null) {
|
|
||||||
Clear();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
atlasArr[i] = atlasAssets[i].GetAtlas();
|
|
||||||
if (atlasArr[i] == null) {
|
|
||||||
Clear();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (skeletonData != null)
|
if (skeletonData != null)
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
|
|
||||||
AttachmentLoader attachmentLoader;
|
AttachmentLoader attachmentLoader;
|
||||||
float skeletonDataScale;
|
float skeletonDataScale;
|
||||||
|
Atlas[] atlasArray = this.GetAtlasArray();
|
||||||
|
|
||||||
#if !SPINE_TK2D
|
#if !SPINE_TK2D
|
||||||
attachmentLoader = new AtlasAttachmentLoader(atlasArr);
|
attachmentLoader = new AtlasAttachmentLoader(atlasArray);
|
||||||
skeletonDataScale = scale;
|
skeletonDataScale = scale;
|
||||||
#else
|
#else
|
||||||
if (spriteCollection != null) {
|
if (spriteCollection != null) {
|
||||||
attachmentLoader = new Spine.Unity.TK2D.SpriteCollectionAttachmentLoader(spriteCollection);
|
attachmentLoader = new Spine.Unity.TK2D.SpriteCollectionAttachmentLoader(spriteCollection);
|
||||||
skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale);
|
skeletonDataScale = (1.0f / (spriteCollection.invOrthoSize * spriteCollection.halfTargetHeight) * scale);
|
||||||
} else {
|
} else {
|
||||||
if (atlasArr.Length == 0) {
|
if (atlasArray.Length == 0) {
|
||||||
Reset();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
attachmentLoader = new AtlasAttachmentLoader(atlasArr);
|
attachmentLoader = new AtlasAttachmentLoader(atlasArray);
|
||||||
skeletonDataScale = scale;
|
skeletonDataScale = scale;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool isBinary = skeletonJSON.name.ToLower().Contains(".skel");
|
||||||
|
SkeletonData loadedSkeletonData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//var stopwatch = new System.Diagnostics.Stopwatch();
|
if (isBinary)
|
||||||
if (skeletonJSON.name.ToLower().Contains(".skel")) {
|
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.bytes, attachmentLoader, skeletonDataScale);
|
||||||
var input = new MemoryStream(skeletonJSON.bytes);
|
else
|
||||||
var binary = new SkeletonBinary(attachmentLoader);
|
loadedSkeletonData = SkeletonDataAsset.ReadSkeletonData(skeletonJSON.text, attachmentLoader, skeletonDataScale);
|
||||||
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) {
|
} 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);
|
this.InitializeWithData(loadedSkeletonData);
|
||||||
FillStateData();
|
|
||||||
|
|
||||||
return skeletonData;
|
return skeletonData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void InitializeWithData (SkeletonData sd) {
|
||||||
|
this.skeletonData = sd;
|
||||||
|
this.stateData = new AnimationStateData(skeletonData);
|
||||||
|
FillStateData();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Atlas[] GetAtlasArray () {
|
||||||
|
var returnList = new System.Collections.Generic.List<Atlas>(atlasAssets.Length);
|
||||||
|
for (int i = 0; i < atlasAssets.Length; i++) {
|
||||||
|
var aa = atlasAssets[i];
|
||||||
|
if (aa == null) continue;
|
||||||
|
var a = aa.GetAtlas();
|
||||||
|
if (a == null) continue;
|
||||||
|
returnList.Add(a);
|
||||||
|
}
|
||||||
|
return returnList.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static SkeletonData ReadSkeletonData (byte[] bytes, AttachmentLoader attachmentLoader, float scale) {
|
||||||
|
var input = new MemoryStream(bytes);
|
||||||
|
var binary = new SkeletonBinary(attachmentLoader) {
|
||||||
|
Scale = scale
|
||||||
|
};
|
||||||
|
return binary.ReadSkeletonData(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static SkeletonData ReadSkeletonData (string text, AttachmentLoader attachmentLoader, float scale) {
|
||||||
|
var input = new StringReader(text);
|
||||||
|
var json = new SkeletonJson(attachmentLoader) {
|
||||||
|
Scale = scale
|
||||||
|
};
|
||||||
|
return json.ReadSkeletonData(input);
|
||||||
|
}
|
||||||
|
|
||||||
public void FillStateData () {
|
public void FillStateData () {
|
||||||
if (stateData != null) {
|
if (stateData != null) {
|
||||||
stateData.defaultMix = defaultMix;
|
stateData.defaultMix = defaultMix;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user