mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-22 10:16:01 +08:00
[unity] Fixed SkeletonData asset preview constantly loading when editing a prefab. Closes #1545.
This commit is contained in:
parent
f0e4a1ebf0
commit
3f9d7b1c63
@ -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,10 +825,11 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
DestroyPreviewGameObject();
|
||||
}
|
||||
|
||||
if (previewGameObject == null) {
|
||||
try {
|
||||
previewGameObject = EditorInstantiation.InstantiateSkeletonAnimation(skeletonDataAsset, skinName).gameObject;
|
||||
previewGameObject = EditorInstantiation.InstantiateSkeletonAnimation(skeletonDataAsset, skinName, useObjectFactory:false).gameObject;
|
||||
|
||||
if (previewGameObject != null) {
|
||||
previewGameObject.hideFlags = HideFlags.HideAndDontSave;
|
||||
@ -852,7 +853,6 @@ namespace Spine.Unity.Editor {
|
||||
RefreshOnNextUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleInteractivePreviewGUI (Rect r, GUIStyle background) {
|
||||
if (Event.current.type == EventType.Repaint) {
|
||||
|
||||
@ -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,10 +330,12 @@ namespace Spine.Unity.Editor {
|
||||
#endif
|
||||
}
|
||||
|
||||
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
|
||||
if (useObjectFactory)
|
||||
return ObjectFactory.CreateGameObject(name);
|
||||
#else
|
||||
return new GameObject(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
|
||||
if (useObjectFactory)
|
||||
return ObjectFactory.CreateGameObject(name, components);
|
||||
#else
|
||||
return new GameObject(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);
|
||||
|
||||
@ -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