mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[unity] Fixed SkeletonData asset preview constantly loading when editing a prefab. Closes #1545.
This commit is contained in:
parent
f0e4a1ebf0
commit
3f9d7b1c63
@ -175,7 +175,7 @@ namespace Spine.Unity.Editor {
|
||||
// Header
|
||||
EditorGUILayout.LabelField(SpineInspectorUtility.TempContent(target.name + " (SkeletonDataAsset)", Icons.spine), EditorStyles.whiteLargeLabel);
|
||||
if (targetSkeletonData != null) EditorGUILayout.LabelField("(Drag and Drop to instantiate.)", EditorStyles.miniLabel);
|
||||
|
||||
|
||||
// Main Serialized Fields
|
||||
using (var changeCheck = new EditorGUI.ChangeCheckScope()) {
|
||||
using (new SpineInspectorUtility.BoxScope())
|
||||
@ -201,11 +201,11 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Unity Quirk: Some code depends on valid preview. If preview is initialized elsewhere, this can cause contents to change between Layout and Repaint events, causing GUILayout control count errors.
|
||||
if (NoProblems())
|
||||
preview.Initialize(this.Repaint, targetSkeletonDataAsset, this.LastSkinName);
|
||||
|
||||
|
||||
if (targetSkeletonData != null) {
|
||||
GUILayout.Space(20f);
|
||||
|
||||
@ -597,7 +597,7 @@ namespace Spine.Unity.Editor {
|
||||
warnings.Add("Missing Skeleton JSON");
|
||||
} else {
|
||||
var fieldValue = (TextAsset)skeletonJSON.objectReferenceValue;
|
||||
|
||||
|
||||
if (!AssetUtility.IsSpineData(fieldValue, out compatibilityProblemInfo)) {
|
||||
warnings.Add("Skeleton data file is not a valid Spine JSON or binary file.");
|
||||
} else {
|
||||
@ -807,13 +807,13 @@ namespace Spine.Unity.Editor {
|
||||
return;
|
||||
}
|
||||
|
||||
const int PreviewLayer = 30;
|
||||
const int PreviewCameraCullingMask = 1 << PreviewLayer;
|
||||
|
||||
if (previewRenderUtility == null) {
|
||||
previewRenderUtility = new PreviewRenderUtility(true);
|
||||
animationLastTime = CurrentTime;
|
||||
|
||||
const int PreviewLayer = 30;
|
||||
const int PreviewCameraCullingMask = 1 << PreviewLayer;
|
||||
|
||||
{
|
||||
var c = this.PreviewUtilityCamera;
|
||||
c.orthographic = true;
|
||||
@ -825,32 +825,32 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
DestroyPreviewGameObject();
|
||||
}
|
||||
|
||||
if (previewGameObject == null) {
|
||||
try {
|
||||
previewGameObject = EditorInstantiation.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;
|
||||
if (previewGameObject == null) {
|
||||
try {
|
||||
previewGameObject = EditorInstantiation.InstantiateSkeletonAnimation(skeletonDataAsset, skinName, useObjectFactory:false).gameObject;
|
||||
|
||||
if (previewGameObject != null) {
|
||||
previewGameObject.hideFlags = HideFlags.HideAndDontSave;
|
||||
previewGameObject.layer = PreviewLayer;
|
||||
skeletonAnimation = previewGameObject.GetComponent<SkeletonAnimation>();
|
||||
skeletonAnimation.initialSkinName = skinName;
|
||||
skeletonAnimation.LateUpdate();
|
||||
previewGameObject.GetComponent<Renderer>().enabled = false;
|
||||
if (previewGameObject != null) {
|
||||
previewGameObject.hideFlags = HideFlags.HideAndDontSave;
|
||||
previewGameObject.layer = PreviewLayer;
|
||||
skeletonAnimation = previewGameObject.GetComponent<SkeletonAnimation>();
|
||||
skeletonAnimation.initialSkinName = skinName;
|
||||
skeletonAnimation.LateUpdate();
|
||||
previewGameObject.GetComponent<Renderer>().enabled = false;
|
||||
|
||||
#if SPINE_UNITY_2018_PREVIEW_API
|
||||
previewRenderUtility.AddSingleGO(previewGameObject);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (this.ActiveTrack != null) cameraAdjustEndFrame = EditorApplication.timeSinceStartup + skeletonAnimation.AnimationState.GetCurrent(0).Alpha;
|
||||
AdjustCameraGoals();
|
||||
} catch {
|
||||
DestroyPreviewGameObject();
|
||||
#if SPINE_UNITY_2018_PREVIEW_API
|
||||
previewRenderUtility.AddSingleGO(previewGameObject);
|
||||
#endif
|
||||
}
|
||||
|
||||
RefreshOnNextUpdate();
|
||||
if (this.ActiveTrack != null) cameraAdjustEndFrame = EditorApplication.timeSinceStartup + skeletonAnimation.AnimationState.GetCurrent(0).Alpha;
|
||||
AdjustCameraGoals();
|
||||
} catch {
|
||||
DestroyPreviewGameObject();
|
||||
}
|
||||
|
||||
RefreshOnNextUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ namespace Spine.Unity.Editor {
|
||||
[MenuItem ("CONTEXT/SkeletonGraphic/Add BoneFollower GameObject")]
|
||||
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
||||
var skeletonGraphic = cmd.context as SkeletonGraphic;
|
||||
var go = EditorInstantiation.NewGameObject("BoneFollower", typeof(RectTransform));
|
||||
var go = EditorInstantiation.NewGameObject("BoneFollower", true, typeof(RectTransform));
|
||||
var t = go.transform;
|
||||
t.SetParent(skeletonGraphic.transform);
|
||||
t.localPosition = Vector3.zero;
|
||||
|
||||
@ -45,7 +45,7 @@ namespace Spine.Unity.Editor {
|
||||
[MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")]
|
||||
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
||||
var skeletonRenderer = cmd.context as SkeletonRenderer;
|
||||
var go = EditorInstantiation.NewGameObject("New BoneFollower");
|
||||
var go = EditorInstantiation.NewGameObject("New BoneFollower", true);
|
||||
var t = go.transform;
|
||||
t.SetParent(skeletonRenderer.transform);
|
||||
t.localPosition = Vector3.zero;
|
||||
|
||||
@ -191,7 +191,7 @@ namespace Spine.Unity.Editor {
|
||||
#endregion
|
||||
|
||||
static GameObject AddBoundingBoxFollowerChild (SkeletonRenderer sr, BoundingBoxFollower original = null) {
|
||||
var go = EditorInstantiation.NewGameObject("BoundingBoxFollower");
|
||||
var go = EditorInstantiation.NewGameObject("BoundingBoxFollower", true);
|
||||
go.transform.SetParent(sr.transform, false);
|
||||
var newFollower = go.AddComponent<BoundingBoxFollower>();
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ namespace Spine.Unity.Editor {
|
||||
[MenuItem("CONTEXT/SkeletonRenderer/Add PointFollower GameObject")]
|
||||
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
||||
var skeletonRenderer = cmd.context as SkeletonRenderer;
|
||||
var go = EditorInstantiation.NewGameObject("PointFollower");
|
||||
var go = EditorInstantiation.NewGameObject("PointFollower", true);
|
||||
var t = go.transform;
|
||||
t.SetParent(skeletonRenderer.transform);
|
||||
t.localPosition = Vector3.zero;
|
||||
|
||||
@ -205,7 +205,7 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
static GameObject NewSkeletonGraphicGameObject (string gameObjectName) {
|
||||
var go = EditorInstantiation.NewGameObject(gameObjectName, typeof(RectTransform), typeof(CanvasRenderer), typeof(SkeletonGraphic));
|
||||
var go = EditorInstantiation.NewGameObject(gameObjectName, true, typeof(RectTransform), typeof(CanvasRenderer), typeof(SkeletonGraphic));
|
||||
var graphic = go.GetComponent<SkeletonGraphic>();
|
||||
graphic.material = SkeletonGraphicInspector.DefaultSkeletonGraphicMaterial;
|
||||
return go;
|
||||
|
||||
@ -36,12 +36,12 @@ namespace Spine.Unity.Editor {
|
||||
public static class Menus {
|
||||
[MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)]
|
||||
static public void CreateSkeletonRendererGameObject () {
|
||||
EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonRenderer>("New SkeletonRenderer");
|
||||
EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonRenderer>("New SkeletonRenderer", true);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Spine/SkeletonAnimation", false, 10)]
|
||||
static public void CreateSkeletonAnimationGameObject () {
|
||||
EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonAnimation>("New SkeletonAnimation");
|
||||
EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonAnimation>("New SkeletonAnimation", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,9 +330,11 @@ namespace Spine.Unity.Editor {
|
||||
#endif
|
||||
}
|
||||
|
||||
SkeletonDataAssetInspector[] skeletonDataInspectors = Resources.FindObjectsOfTypeAll<SkeletonDataAssetInspector>();
|
||||
foreach (var inspector in skeletonDataInspectors) {
|
||||
inspector.UpdateSkeletonData();
|
||||
if (atlasPaths.Count > 0 || imagePaths.Count > 0 || skeletonPaths.Count > 0) {
|
||||
SkeletonDataAssetInspector[] skeletonDataInspectors = Resources.FindObjectsOfTypeAll<SkeletonDataAssetInspector>();
|
||||
foreach (var inspector in skeletonDataInspectors) {
|
||||
inspector.UpdateSkeletonData();
|
||||
}
|
||||
}
|
||||
|
||||
// Any post processing of images
|
||||
@ -905,13 +907,17 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
}
|
||||
|
||||
public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, string skinName, bool destroyInvalid = true) {
|
||||
public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, string skinName,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
|
||||
var skeletonData = skeletonDataAsset.GetSkeletonData(true);
|
||||
var skin = skeletonData != null ? skeletonData.FindSkin(skinName) : null;
|
||||
return InstantiateSkeletonAnimation(skeletonDataAsset, skin, destroyInvalid);
|
||||
return InstantiateSkeletonAnimation(skeletonDataAsset, skin, destroyInvalid, useObjectFactory);
|
||||
}
|
||||
|
||||
public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, Skin skin = null, bool destroyInvalid = true) {
|
||||
public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, Skin skin = null,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
|
||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||
|
||||
if (data == null) {
|
||||
@ -928,7 +934,8 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
string spineGameObjectName = string.Format("Spine GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
||||
GameObject go = EditorInstantiation.NewGameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
|
||||
GameObject go = EditorInstantiation.NewGameObject(spineGameObjectName, useObjectFactory,
|
||||
typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
|
||||
SkeletonAnimation newSkeletonAnimation = go.GetComponent<SkeletonAnimation>();
|
||||
newSkeletonAnimation.skeletonDataAsset = skeletonDataAsset;
|
||||
TryInitializeSkeletonRendererSettings(newSkeletonAnimation, skin);
|
||||
@ -954,28 +961,28 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
/// <summary>Handles creating a new GameObject in the Unity Editor. This uses the new ObjectFactory API where applicable.</summary>
|
||||
public static GameObject NewGameObject (string name) {
|
||||
public static GameObject NewGameObject (string name, bool useObjectFactory) {
|
||||
#if NEW_PREFAB_SYSTEM
|
||||
return ObjectFactory.CreateGameObject(name);
|
||||
#else
|
||||
return new GameObject(name);
|
||||
if (useObjectFactory)
|
||||
return ObjectFactory.CreateGameObject(name);
|
||||
#endif
|
||||
return new GameObject(name);
|
||||
}
|
||||
|
||||
/// <summary>Handles creating a new GameObject in the Unity Editor. This uses the new ObjectFactory API where applicable.</summary>
|
||||
public static GameObject NewGameObject (string name, params System.Type[] components) {
|
||||
public static GameObject NewGameObject (string name, bool useObjectFactory, params System.Type[] components) {
|
||||
#if NEW_PREFAB_SYSTEM
|
||||
return ObjectFactory.CreateGameObject(name, components);
|
||||
#else
|
||||
return new GameObject(name, components);
|
||||
if (useObjectFactory)
|
||||
return ObjectFactory.CreateGameObject(name, components);
|
||||
#endif
|
||||
return new GameObject(name, components);
|
||||
}
|
||||
|
||||
public static void InstantiateEmptySpineGameObject<T> (string name) where T : MonoBehaviour {
|
||||
public static void InstantiateEmptySpineGameObject<T> (string name, bool useObjectFactory) where T : MonoBehaviour {
|
||||
var parentGameObject = Selection.activeObject as GameObject;
|
||||
var parentTransform = parentGameObject == null ? null : parentGameObject.transform;
|
||||
|
||||
var gameObject = EditorInstantiation.NewGameObject(name, typeof(T));
|
||||
var gameObject = EditorInstantiation.NewGameObject(name, useObjectFactory, typeof(T));
|
||||
gameObject.transform.SetParent(parentTransform, false);
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = gameObject;
|
||||
@ -988,7 +995,8 @@ namespace Spine.Unity.Editor {
|
||||
return InstantiateSkeletonMecanim(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
|
||||
}
|
||||
|
||||
public static SkeletonMecanim InstantiateSkeletonMecanim (SkeletonDataAsset skeletonDataAsset, Skin skin = null, bool destroyInvalid = true) {
|
||||
public static SkeletonMecanim InstantiateSkeletonMecanim (SkeletonDataAsset skeletonDataAsset, Skin skin = null,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||
|
||||
if (data == null) {
|
||||
@ -1005,7 +1013,8 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
string spineGameObjectName = string.Format("Spine Mecanim GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
||||
GameObject go = EditorInstantiation.NewGameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonMecanim));
|
||||
GameObject go = EditorInstantiation.NewGameObject(spineGameObjectName, useObjectFactory,
|
||||
typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonMecanim));
|
||||
|
||||
if (skeletonDataAsset.controller == null) {
|
||||
SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
|
||||
|
||||
@ -184,7 +184,7 @@ namespace Spine.Unity.Editor {
|
||||
Debug.LogError("Could not export Spine Skeleton because SkeletonDataAsset is null or invalid!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (outputPath == "") {
|
||||
outputPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(skeletonDataAsset)).Replace('\\', '/') + "/Baked";
|
||||
System.IO.Directory.CreateDirectory(outputPath);
|
||||
@ -299,7 +299,7 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
}
|
||||
|
||||
GameObject prefabRoot = EditorInstantiation.NewGameObject("root");
|
||||
GameObject prefabRoot = EditorInstantiation.NewGameObject("root", true);
|
||||
|
||||
Dictionary<string, Transform> slotTable = new Dictionary<string, Transform>();
|
||||
Dictionary<string, Transform> boneTable = new Dictionary<string, Transform>();
|
||||
@ -308,7 +308,7 @@ namespace Spine.Unity.Editor {
|
||||
//create bones
|
||||
for (int i = 0; i < skeletonData.Bones.Count; i++) {
|
||||
var boneData = skeletonData.Bones.Items[i];
|
||||
Transform boneTransform = EditorInstantiation.NewGameObject(boneData.Name).transform;
|
||||
Transform boneTransform = EditorInstantiation.NewGameObject(boneData.Name, true).transform;
|
||||
boneTransform.parent = prefabRoot.transform;
|
||||
boneTable.Add(boneTransform.name, boneTransform);
|
||||
boneList.Add(boneTransform);
|
||||
@ -339,7 +339,7 @@ namespace Spine.Unity.Editor {
|
||||
//create slots and attachments
|
||||
for (int slotIndex = 0; slotIndex < skeletonData.Slots.Count; slotIndex++) {
|
||||
var slotData = skeletonData.Slots.Items[slotIndex];
|
||||
Transform slotTransform = EditorInstantiation.NewGameObject(slotData.Name).transform;
|
||||
Transform slotTransform = EditorInstantiation.NewGameObject(slotData.Name, true).transform;
|
||||
slotTransform.parent = prefabRoot.transform;
|
||||
slotTable.Add(slotData.Name, slotTransform);
|
||||
|
||||
@ -389,7 +389,7 @@ namespace Spine.Unity.Editor {
|
||||
} else
|
||||
continue;
|
||||
|
||||
Transform attachmentTransform = EditorInstantiation.NewGameObject(attachmentName).transform;
|
||||
Transform attachmentTransform = EditorInstantiation.NewGameObject(attachmentName, true).transform;
|
||||
|
||||
attachmentTransform.parent = slotTransform;
|
||||
attachmentTransform.localPosition = offset;
|
||||
@ -1437,7 +1437,7 @@ namespace Spine.Unity.Editor {
|
||||
Directory.CreateDirectory(bakedDirPath);
|
||||
|
||||
if (prefab == null) {
|
||||
root = EditorInstantiation.NewGameObject("temp", typeof(MeshFilter), typeof(MeshRenderer));
|
||||
root = EditorInstantiation.NewGameObject("temp", true, typeof(MeshFilter), typeof(MeshRenderer));
|
||||
#if NEW_PREFAB_SYSTEM
|
||||
prefab = PrefabUtility.SaveAsPrefabAsset(root, bakedPrefabPath);
|
||||
#else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user