[unity] Move instantiation code.

This commit is contained in:
pharan 2018-10-01 21:57:32 +08:00
parent c81f9dbe62
commit 9eba3e1bbd
2 changed files with 13 additions and 13 deletions

View File

@ -37,23 +37,12 @@ namespace Spine.Unity.Editor {
public static class Menus { public static class Menus {
[MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)] [MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)]
static public void CreateSkeletonRendererGameObject () { static public void CreateSkeletonRendererGameObject () {
CreateSpineGameObject<SkeletonRenderer>("New SkeletonRenderer"); SpineEditorUtilities.EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonRenderer>("New SkeletonRenderer");
} }
[MenuItem("GameObject/Spine/SkeletonAnimation", false, 10)] [MenuItem("GameObject/Spine/SkeletonAnimation", false, 10)]
static public void CreateSkeletonAnimationGameObject () { static public void CreateSkeletonAnimationGameObject () {
CreateSpineGameObject<SkeletonAnimation>("New SkeletonAnimation"); SpineEditorUtilities.EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonAnimation>("New SkeletonAnimation");
}
static void CreateSpineGameObject<T> (string name) where T : MonoBehaviour {
var parentGameObject = Selection.activeObject as GameObject;
var parentTransform = parentGameObject == null ? null : parentGameObject.transform;
var gameObject = new GameObject(name, typeof(T));
gameObject.transform.SetParent(parentTransform, false);
EditorUtility.FocusProjectWindow();
Selection.activeObject = gameObject;
EditorGUIUtility.PingObject(Selection.activeObject);
} }
} }
} }

View File

@ -1227,6 +1227,17 @@ namespace Spine.Unity.Editor {
return newSkeletonAnimation; return newSkeletonAnimation;
} }
public static void InstantiateEmptySpineGameObject<T> (string name) where T : MonoBehaviour {
var parentGameObject = Selection.activeObject as GameObject;
var parentTransform = parentGameObject == null ? null : parentGameObject.transform;
var gameObject = new GameObject(name, typeof(T));
gameObject.transform.SetParent(parentTransform, false);
EditorUtility.FocusProjectWindow();
Selection.activeObject = gameObject;
EditorGUIUtility.PingObject(Selection.activeObject);
}
#region SkeletonMecanim #region SkeletonMecanim
#if SPINE_SKELETONMECANIM #if SPINE_SKELETONMECANIM
public static SkeletonMecanim InstantiateSkeletonMecanim (SkeletonDataAsset skeletonDataAsset, string skinName) { public static SkeletonMecanim InstantiateSkeletonMecanim (SkeletonDataAsset skeletonDataAsset, string skinName) {