mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 02:06:03 +08:00
[unity] Fixed SkeletonGraphic related import error occurring occasionally on first import. Error message was usually 'Skeleton JSON file not set for SkeletonData asset'. Closes #1226.
This commit is contained in:
parent
4e8365012e
commit
52245d55f0
@ -453,6 +453,9 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
|
|
||||||
public static class DataReloadHandler {
|
public static class DataReloadHandler {
|
||||||
|
|
||||||
|
internal static Dictionary<int, string> savedSkeletonDataAssetAtSKeletonGraphicID = new Dictionary<int, string>();
|
||||||
|
|
||||||
#if NEWPLAYMODECALLBACKS
|
#if NEWPLAYMODECALLBACKS
|
||||||
internal static void OnPlaymodeStateChanged (PlayModeStateChange stateChange) {
|
internal static void OnPlaymodeStateChanged (PlayModeStateChange stateChange) {
|
||||||
#else
|
#else
|
||||||
@ -462,6 +465,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void ReloadAllActiveSkeletonsEditMode () {
|
public static void ReloadAllActiveSkeletonsEditMode () {
|
||||||
|
|
||||||
if (EditorApplication.isPaused) return;
|
if (EditorApplication.isPaused) return;
|
||||||
if (EditorApplication.isPlaying) return;
|
if (EditorApplication.isPlaying) return;
|
||||||
if (EditorApplication.isCompiling) return;
|
if (EditorApplication.isCompiling) return;
|
||||||
@ -475,10 +479,20 @@ namespace Spine.Unity.Editor {
|
|||||||
if (skeletonDataAsset != null) skeletonDataAssetsToReload.Add(skeletonDataAsset);
|
if (skeletonDataAsset != null) skeletonDataAssetsToReload.Add(skeletonDataAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Under some circumstances (e.g. on first import) SkeletonGraphic objects
|
||||||
|
// have their skeletonGraphic.skeletonDataAsset reference corrupted
|
||||||
|
// by the instance of the ScriptableObject being destroyed but still assigned.
|
||||||
|
// Here we save the skeletonGraphic.skeletonDataAsset asset path in order
|
||||||
|
// to restore it later.
|
||||||
var activeSkeletonGraphics = GameObject.FindObjectsOfType<SkeletonGraphic>();
|
var activeSkeletonGraphics = GameObject.FindObjectsOfType<SkeletonGraphic>();
|
||||||
foreach (var sg in activeSkeletonGraphics) {
|
foreach (var sg in activeSkeletonGraphics) {
|
||||||
var skeletonDataAsset = sg.skeletonDataAsset;
|
var skeletonDataAsset = sg.skeletonDataAsset;
|
||||||
if (skeletonDataAsset != null) skeletonDataAssetsToReload.Add(skeletonDataAsset);
|
if (skeletonDataAsset != null) {
|
||||||
|
var assetPath = AssetDatabase.GetAssetPath(skeletonDataAsset);
|
||||||
|
var sgID = sg.GetInstanceID();
|
||||||
|
savedSkeletonDataAssetAtSKeletonGraphicID[sgID] = assetPath;
|
||||||
|
skeletonDataAssetsToReload.Add(skeletonDataAsset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var sda in skeletonDataAssetsToReload) {
|
foreach (var sda in skeletonDataAssetsToReload) {
|
||||||
@ -780,6 +794,22 @@ namespace Spine.Unity.Editor {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// Any post processing of images
|
// Any post processing of images
|
||||||
|
|
||||||
|
// Under some circumstances (e.g. on first import) SkeletonGraphic objects
|
||||||
|
// have their skeletonGraphic.skeletonDataAsset reference corrupted
|
||||||
|
// by the instance of the ScriptableObject being destroyed but still assigned.
|
||||||
|
// Here we restore broken skeletonGraphic.skeletonDataAsset references.
|
||||||
|
var skeletonGraphicObjects = Resources.FindObjectsOfTypeAll(typeof(SkeletonGraphic)) as SkeletonGraphic[];
|
||||||
|
foreach (var skeletonGraphic in skeletonGraphicObjects) {
|
||||||
|
|
||||||
|
if (skeletonGraphic.skeletonDataAsset == null) {
|
||||||
|
var skeletonGraphicID = skeletonGraphic.GetInstanceID();
|
||||||
|
if (DataReloadHandler.savedSkeletonDataAssetAtSKeletonGraphicID.ContainsKey(skeletonGraphicID)) {
|
||||||
|
string assetPath = DataReloadHandler.savedSkeletonDataAssetAtSKeletonGraphicID[skeletonGraphicID];
|
||||||
|
skeletonGraphic.skeletonDataAsset = (SkeletonDataAsset)AssetDatabase.LoadAssetAtPath<SkeletonDataAsset>(assetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ReloadSkeletonData (string skeletonJSONPath) {
|
static void ReloadSkeletonData (string skeletonJSONPath) {
|
||||||
|
|||||||
@ -100,12 +100,16 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (skeletonDataAsset != null)
|
// Under some circumstances (e.g. sometimes on the first import) OnValidate is called
|
||||||
|
// before SpineEditorUtilities.ImportSpineContent, causing an unnecessary exception.
|
||||||
|
// The (skeletonDataAsset.skeletonJSON != null) condition serves to prevent this exception.
|
||||||
|
if (skeletonDataAsset != null && skeletonDataAsset.skeletonJSON != null)
|
||||||
Initialize(true);
|
Initialize(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Reset () {
|
protected override void Reset () {
|
||||||
|
|
||||||
base.Reset();
|
base.Reset();
|
||||||
if (material == null || material.shader != Shader.Find("Spine/SkeletonGraphic (Premultiply Alpha)"))
|
if (material == null || material.shader != Shader.Find("Spine/SkeletonGraphic (Premultiply Alpha)"))
|
||||||
Debug.LogWarning("SkeletonGraphic works best with the SkeletonGraphic material.");
|
Debug.LogWarning("SkeletonGraphic works best with the SkeletonGraphic material.");
|
||||||
@ -154,8 +158,17 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void Awake () {
|
protected override void Awake () {
|
||||||
|
|
||||||
base.Awake ();
|
base.Awake ();
|
||||||
if (!this.IsValid) {
|
if (!this.IsValid) {
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
// workaround for special import case of open scene where OnValidate and Awake are
|
||||||
|
// called in wrong order, before setup of Spine assets.
|
||||||
|
if (!Application.isPlaying) {
|
||||||
|
if (this.skeletonDataAsset != null && this.skeletonDataAsset.skeletonJSON == null)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Initialize(false);
|
Initialize(false);
|
||||||
Rebuild(CanvasUpdate.PreRender);
|
Rebuild(CanvasUpdate.PreRender);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user