diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/BoneFollowerInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/BoneFollowerInspector.cs index dd44a34c5..8d547190e 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/BoneFollowerInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/BoneFollowerInspector.cs @@ -46,7 +46,7 @@ namespace Spine.Unity.Editor { [MenuItem ("CONTEXT/SkeletonRenderer/Add BoneFollower GameObject")] static void AddBoneFollowerGameObject (MenuCommand cmd) { var skeletonRenderer = cmd.context as SkeletonRenderer; - var go = new GameObject("New BoneFollower"); + var go = SpineEditorUtilities.EditorInstantiation.NewGameObject("New BoneFollower"); var t = go.transform; t.SetParent(skeletonRenderer.transform); t.localPosition = Vector3.zero; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs index 4baf3055c..d0cb09406 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/PointFollowerEditor.cs @@ -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 = new GameObject("PointFollower"); + var go = SpineEditorUtilities.EditorInstantiation.NewGameObject("PointFollower"); var t = go.transform; t.SetParent(skeletonRenderer.transform); t.localPosition = Vector3.zero; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs index 245ace09a..8a6ddb540 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SkeletonBaker.cs @@ -296,7 +296,7 @@ namespace Spine.Unity.Editor { } } - GameObject prefabRoot = new GameObject("root"); + GameObject prefabRoot = SpineEditorUtilities.EditorInstantiation.NewGameObject("root"); Dictionary slotTable = new Dictionary(); Dictionary boneTable = new Dictionary(); @@ -305,7 +305,7 @@ namespace Spine.Unity.Editor { //create bones for (int i = 0; i < skeletonData.Bones.Count; 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; boneTable.Add(boneTransform.name, boneTransform); boneList.Add(boneTransform); @@ -336,7 +336,7 @@ namespace Spine.Unity.Editor { //create slots and attachments for (int i = 0; i < skeletonData.Slots.Count; 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; slotTable.Add(slotData.Name, slotTransform); @@ -392,7 +392,7 @@ namespace Spine.Unity.Editor { } else continue; - Transform attachmentTransform = new GameObject(attachmentName).transform; + Transform attachmentTransform = SpineEditorUtilities.EditorInstantiation.NewGameObject(attachmentName).transform; attachmentTransform.parent = slotTransform; attachmentTransform.localPosition = offset; @@ -1429,7 +1429,7 @@ namespace Spine.Unity.Editor { Directory.CreateDirectory(bakedDirPath); if (prefab == null) { - root = new GameObject("temp", typeof(MeshFilter), typeof(MeshRenderer)); + root = SpineEditorUtilities.EditorInstantiation.NewGameObject("temp", typeof(MeshFilter), typeof(MeshRenderer)); #if NEW_PREFAB_SYSTEM prefab = PrefabUtility.SaveAsPrefabAsset(root, bakedPrefabPath); #else diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs index 02f735b70..4a345390c 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs @@ -38,6 +38,10 @@ #define NEWPLAYMODECALLBACKS #endif +#if UNITY_2018_3 || UNITY_2019 +#define NEW_PREFAB_SYSTEM +#endif + #if UNITY_2018 || UNITY_2019 #define NEWHIERARCHYWINDOWCALLBACKS #endif @@ -1274,7 +1278,7 @@ namespace Spine.Unity.Editor { } 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(); newSkeletonAnimation.skeletonDataAsset = skeletonDataAsset; TryInitializeSkeletonRendererSettings(newSkeletonAnimation, skin); @@ -1298,12 +1302,30 @@ namespace Spine.Unity.Editor { return newSkeletonAnimation; } + + /// Handles creating a new GameObject in the Unity Editor. This uses the new ObjectFactory API where applicable. + public static GameObject NewGameObject (string name) { + #if NEW_PREFAB_SYSTEM + return ObjectFactory.CreateGameObject(gameObjectName); + #else + return new GameObject(name); + #endif + } + + /// Handles creating a new GameObject in the Unity Editor. This uses the new ObjectFactory API where applicable. + 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 (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)); + var gameObject = EditorInstantiation.NewGameObject(name, typeof(T)); gameObject.transform.SetParent(parentTransform, false); EditorUtility.FocusProjectWindow(); Selection.activeObject = gameObject; @@ -1333,7 +1355,7 @@ namespace Spine.Unity.Editor { } 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) { SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/BoundingBoxFollower/Editor/BoundingBoxFollowerInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/BoundingBoxFollower/Editor/BoundingBoxFollowerInspector.cs index cc1ea35e1..e9ad835c7 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/BoundingBoxFollower/Editor/BoundingBoxFollowerInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/BoundingBoxFollower/Editor/BoundingBoxFollowerInspector.cs @@ -192,7 +192,7 @@ namespace Spine.Unity.Editor { #endregion 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); var newFollower = go.AddComponent(); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/BoneFollowerGraphicInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/BoneFollowerGraphicInspector.cs index 1d74f0b0c..dc0afba99 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/BoneFollowerGraphicInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/BoneFollowerGraphicInspector.cs @@ -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 UnityEditor; - using Spine.Unity; namespace Spine.Unity.Editor { @@ -21,7 +48,7 @@ namespace Spine.Unity.Editor { [MenuItem ("CONTEXT/SkeletonGraphic/Add BoneFollower GameObject")] static void AddBoneFollowerGameObject (MenuCommand cmd) { 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; t.SetParent(skeletonGraphic.transform); t.localPosition = Vector3.zero; diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs index 29a31dfdf..8ff7ce1ea 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Modules/SkeletonGraphic/Editor/SkeletonGraphicInspector.cs @@ -206,7 +206,7 @@ namespace Spine.Unity.Editor { } 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(); graphic.material = SkeletonGraphicInspector.DefaultSkeletonGraphicMaterial; return go;