mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-07 11:16:53 +08:00
[unity] Centralize creating GameObjects in the editor using SpineEditorUtilities.EditorInstantiation.
This commit is contained in:
parent
0aa617c44a
commit
40f5755fe0
@ -46,7 +46,7 @@ namespace Spine.Unity.Editor {
|
|||||||
[MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")]
|
[MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")]
|
||||||
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
||||||
var skeletonRenderer = cmd.context as SkeletonRenderer;
|
var skeletonRenderer = cmd.context as SkeletonRenderer;
|
||||||
var go = new GameObject("New BoneFollower");
|
var go = SpineEditorUtilities.EditorInstantiation.NewGameObject("New BoneFollower");
|
||||||
var t = go.transform;
|
var t = go.transform;
|
||||||
t.SetParent(skeletonRenderer.transform);
|
t.SetParent(skeletonRenderer.transform);
|
||||||
t.localPosition = Vector3.zero;
|
t.localPosition = Vector3.zero;
|
||||||
|
|||||||
@ -46,7 +46,7 @@ namespace Spine.Unity.Editor {
|
|||||||
[MenuItem("CONTEXT/SkeletonRenderer/Add PointFollower GameObject")]
|
[MenuItem("CONTEXT/SkeletonRenderer/Add PointFollower GameObject")]
|
||||||
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
||||||
var skeletonRenderer = cmd.context as SkeletonRenderer;
|
var skeletonRenderer = cmd.context as SkeletonRenderer;
|
||||||
var go = new GameObject("PointFollower");
|
var go = SpineEditorUtilities.EditorInstantiation.NewGameObject("PointFollower");
|
||||||
var t = go.transform;
|
var t = go.transform;
|
||||||
t.SetParent(skeletonRenderer.transform);
|
t.SetParent(skeletonRenderer.transform);
|
||||||
t.localPosition = Vector3.zero;
|
t.localPosition = Vector3.zero;
|
||||||
|
|||||||
@ -296,7 +296,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObject prefabRoot = new GameObject("root");
|
GameObject prefabRoot = SpineEditorUtilities.EditorInstantiation.NewGameObject("root");
|
||||||
|
|
||||||
Dictionary<string, Transform> slotTable = new Dictionary<string, Transform>();
|
Dictionary<string, Transform> slotTable = new Dictionary<string, Transform>();
|
||||||
Dictionary<string, Transform> boneTable = new Dictionary<string, Transform>();
|
Dictionary<string, Transform> boneTable = new Dictionary<string, Transform>();
|
||||||
@ -305,7 +305,7 @@ namespace Spine.Unity.Editor {
|
|||||||
//create bones
|
//create bones
|
||||||
for (int i = 0; i < skeletonData.Bones.Count; i++) {
|
for (int i = 0; i < skeletonData.Bones.Count; i++) {
|
||||||
var boneData = skeletonData.Bones.Items[i];
|
var boneData = skeletonData.Bones.Items[i];
|
||||||
Transform boneTransform = new GameObject(boneData.Name).transform;
|
Transform boneTransform = SpineEditorUtilities.EditorInstantiation.NewGameObject(boneData.Name).transform;
|
||||||
boneTransform.parent = prefabRoot.transform;
|
boneTransform.parent = prefabRoot.transform;
|
||||||
boneTable.Add(boneTransform.name, boneTransform);
|
boneTable.Add(boneTransform.name, boneTransform);
|
||||||
boneList.Add(boneTransform);
|
boneList.Add(boneTransform);
|
||||||
@ -336,7 +336,7 @@ namespace Spine.Unity.Editor {
|
|||||||
//create slots and attachments
|
//create slots and attachments
|
||||||
for (int i = 0; i < skeletonData.Slots.Count; i++) {
|
for (int i = 0; i < skeletonData.Slots.Count; i++) {
|
||||||
var slotData = skeletonData.Slots.Items[i];
|
var slotData = skeletonData.Slots.Items[i];
|
||||||
Transform slotTransform = new GameObject(slotData.Name).transform;
|
Transform slotTransform = SpineEditorUtilities.EditorInstantiation.NewGameObject(slotData.Name).transform;
|
||||||
slotTransform.parent = prefabRoot.transform;
|
slotTransform.parent = prefabRoot.transform;
|
||||||
slotTable.Add(slotData.Name, slotTransform);
|
slotTable.Add(slotData.Name, slotTransform);
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ namespace Spine.Unity.Editor {
|
|||||||
} else
|
} else
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Transform attachmentTransform = new GameObject(attachmentName).transform;
|
Transform attachmentTransform = SpineEditorUtilities.EditorInstantiation.NewGameObject(attachmentName).transform;
|
||||||
|
|
||||||
attachmentTransform.parent = slotTransform;
|
attachmentTransform.parent = slotTransform;
|
||||||
attachmentTransform.localPosition = offset;
|
attachmentTransform.localPosition = offset;
|
||||||
@ -1429,7 +1429,7 @@ namespace Spine.Unity.Editor {
|
|||||||
Directory.CreateDirectory(bakedDirPath);
|
Directory.CreateDirectory(bakedDirPath);
|
||||||
|
|
||||||
if (prefab == null) {
|
if (prefab == null) {
|
||||||
root = new GameObject("temp", typeof(MeshFilter), typeof(MeshRenderer));
|
root = SpineEditorUtilities.EditorInstantiation.NewGameObject("temp", typeof(MeshFilter), typeof(MeshRenderer));
|
||||||
#if NEW_PREFAB_SYSTEM
|
#if NEW_PREFAB_SYSTEM
|
||||||
prefab = PrefabUtility.SaveAsPrefabAsset(root, bakedPrefabPath);
|
prefab = PrefabUtility.SaveAsPrefabAsset(root, bakedPrefabPath);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -38,6 +38,10 @@
|
|||||||
#define NEWPLAYMODECALLBACKS
|
#define NEWPLAYMODECALLBACKS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_2018_3 || UNITY_2019
|
||||||
|
#define NEW_PREFAB_SYSTEM
|
||||||
|
#endif
|
||||||
|
|
||||||
#if UNITY_2018 || UNITY_2019
|
#if UNITY_2018 || UNITY_2019
|
||||||
#define NEWHIERARCHYWINDOWCALLBACKS
|
#define NEWHIERARCHYWINDOWCALLBACKS
|
||||||
#endif
|
#endif
|
||||||
@ -1274,7 +1278,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string spineGameObjectName = string.Format("Spine GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
string spineGameObjectName = string.Format("Spine GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
||||||
GameObject go = new GameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
|
GameObject go = EditorInstantiation.NewGameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(SkeletonAnimation));
|
||||||
SkeletonAnimation newSkeletonAnimation = go.GetComponent<SkeletonAnimation>();
|
SkeletonAnimation newSkeletonAnimation = go.GetComponent<SkeletonAnimation>();
|
||||||
newSkeletonAnimation.skeletonDataAsset = skeletonDataAsset;
|
newSkeletonAnimation.skeletonDataAsset = skeletonDataAsset;
|
||||||
TryInitializeSkeletonRendererSettings(newSkeletonAnimation, skin);
|
TryInitializeSkeletonRendererSettings(newSkeletonAnimation, skin);
|
||||||
@ -1298,12 +1302,30 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
return newSkeletonAnimation;
|
return newSkeletonAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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) {
|
||||||
|
#if NEW_PREFAB_SYSTEM
|
||||||
|
return ObjectFactory.CreateGameObject(gameObjectName);
|
||||||
|
#else
|
||||||
|
return new GameObject(name);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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) {
|
||||||
|
#if NEW_PREFAB_SYSTEM
|
||||||
|
return ObjectFactory.CreateGameObject(gameObjectName, components);
|
||||||
|
#else
|
||||||
|
return new GameObject(name, components);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public static void InstantiateEmptySpineGameObject<T> (string name) where T : MonoBehaviour {
|
public static void InstantiateEmptySpineGameObject<T> (string name) where T : MonoBehaviour {
|
||||||
var parentGameObject = Selection.activeObject as GameObject;
|
var parentGameObject = Selection.activeObject as GameObject;
|
||||||
var parentTransform = parentGameObject == null ? null : parentGameObject.transform;
|
var parentTransform = parentGameObject == null ? null : parentGameObject.transform;
|
||||||
|
|
||||||
var gameObject = new GameObject(name, typeof(T));
|
var gameObject = EditorInstantiation.NewGameObject(name, typeof(T));
|
||||||
gameObject.transform.SetParent(parentTransform, false);
|
gameObject.transform.SetParent(parentTransform, false);
|
||||||
EditorUtility.FocusProjectWindow();
|
EditorUtility.FocusProjectWindow();
|
||||||
Selection.activeObject = gameObject;
|
Selection.activeObject = gameObject;
|
||||||
@ -1333,7 +1355,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string spineGameObjectName = string.Format("Spine Mecanim GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
string spineGameObjectName = string.Format("Spine Mecanim GameObject ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
||||||
GameObject go = new GameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonMecanim));
|
GameObject go = EditorInstantiation.NewGameObject(spineGameObjectName, typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonMecanim));
|
||||||
|
|
||||||
if (skeletonDataAsset.controller == null) {
|
if (skeletonDataAsset.controller == null) {
|
||||||
SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
|
SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
|
||||||
|
|||||||
@ -192,7 +192,7 @@ namespace Spine.Unity.Editor {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
static GameObject AddBoundingBoxFollowerChild (SkeletonRenderer sr, BoundingBoxFollower original = null) {
|
static GameObject AddBoundingBoxFollowerChild (SkeletonRenderer sr, BoundingBoxFollower original = null) {
|
||||||
var go = new GameObject("BoundingBoxFollower");
|
var go = SpineEditorUtilities.EditorInstantiation.NewGameObject("BoundingBoxFollower");
|
||||||
go.transform.SetParent(sr.transform, false);
|
go.transform.SetParent(sr.transform, false);
|
||||||
var newFollower = go.AddComponent<BoundingBoxFollower>();
|
var newFollower = go.AddComponent<BoundingBoxFollower>();
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,35 @@
|
|||||||
using System.Collections;
|
/******************************************************************************
|
||||||
using System.Collections.Generic;
|
* Spine Runtimes Software License v2.5
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2016, Esoteric Software
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* You are granted a perpetual, non-exclusive, non-sublicensable, and
|
||||||
|
* non-transferable license to use, install, execute, and perform the Spine
|
||||||
|
* Runtimes software and derivative works solely for personal or internal
|
||||||
|
* use. Without the written permission of Esoteric Software (see Section 2 of
|
||||||
|
* the Spine Software License Agreement), you may not (a) modify, translate,
|
||||||
|
* adapt, or develop new applications using the Spine Runtimes or otherwise
|
||||||
|
* create derivative works or improvements of the Spine Runtimes or (b) remove,
|
||||||
|
* delete, alter, or obscure any trademarks or any copyright, trademark, patent,
|
||||||
|
* or other intellectual property or proprietary rights notices on or in the
|
||||||
|
* Software, including any copy thereof. Redistributions in binary or source
|
||||||
|
* form must include this license and terms.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||||
|
* EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
|
||||||
|
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
using Spine.Unity;
|
using Spine.Unity;
|
||||||
|
|
||||||
namespace Spine.Unity.Editor {
|
namespace Spine.Unity.Editor {
|
||||||
@ -21,7 +48,7 @@ namespace Spine.Unity.Editor {
|
|||||||
[MenuItem ("CONTEXT/SkeletonGraphic/Add BoneFollower GameObject")]
|
[MenuItem ("CONTEXT/SkeletonGraphic/Add BoneFollower GameObject")]
|
||||||
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
static void AddBoneFollowerGameObject (MenuCommand cmd) {
|
||||||
var skeletonGraphic = cmd.context as SkeletonGraphic;
|
var skeletonGraphic = cmd.context as SkeletonGraphic;
|
||||||
var go = new GameObject("BoneFollower", typeof(RectTransform));
|
var go = SpineEditorUtilities.EditorInstantiation.NewGameObject("BoneFollower", typeof(RectTransform));
|
||||||
var t = go.transform;
|
var t = go.transform;
|
||||||
t.SetParent(skeletonGraphic.transform);
|
t.SetParent(skeletonGraphic.transform);
|
||||||
t.localPosition = Vector3.zero;
|
t.localPosition = Vector3.zero;
|
||||||
|
|||||||
@ -206,7 +206,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GameObject NewSkeletonGraphicGameObject (string gameObjectName) {
|
static GameObject NewSkeletonGraphicGameObject (string gameObjectName) {
|
||||||
var go = new GameObject(gameObjectName, typeof(RectTransform), typeof(CanvasRenderer), typeof(SkeletonGraphic));
|
var go = SpineEditorUtilities.EditorInstantiation.NewGameObject(gameObjectName, typeof(RectTransform), typeof(CanvasRenderer), typeof(SkeletonGraphic));
|
||||||
var graphic = go.GetComponent<SkeletonGraphic>();
|
var graphic = go.GetComponent<SkeletonGraphic>();
|
||||||
graphic.material = SkeletonGraphicInspector.DefaultSkeletonGraphicMaterial;
|
graphic.material = SkeletonGraphicInspector.DefaultSkeletonGraphicMaterial;
|
||||||
return go;
|
return go;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user