mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-11 01:28:44 +08:00
[unity] Added drag & drop instantiation option SkeletonGraphic (UI) Mecanim. Removed old GameObject - Spine - SkeletonRenderer component menu entries.
This commit is contained in:
parent
a5a5483f68
commit
7f5502233f
@ -348,6 +348,7 @@
|
||||
- UnityEngine Physics: `Physics.gravity` → `UnityEngine.Physics.gravity`.
|
||||
- When enabling `Threaded Animation` at `SkeletonAnimation` components, `SkeletonAnimation.AnimationState` callbacks and `TrackEntry` callbacks are not automatically called on the main thread. There are additional main thread callbacks provided to subscribe to instead, like `MainThreadComplete` for `Complete` and the like - see *Additions* below. Please note that this requires a change of user code to subscribe to these main thread delegate variants instead.
|
||||
- `SkeletonRenderer`: `maskInteraction` → `MaskInteraction`.
|
||||
- Removed rather useless old menu entries `GameObject - Spine - SkeletonRenderer` and the like which are spawning e.g. a GameObject with an empty `SkeletonRenderer` component without `SkeletonDataAsset` assigned and thus also not initialized properly.
|
||||
- **Changes of default values**
|
||||
- Changed default atlas texture workflow from PMA to straight alpha textures. This move was done because straight alpha textures are compatible with both Gamma and Linear color space, with the latter being the default for quite some time now in Unity. Note that `PMA Vertex Color` is unaffected and shall be enabled as usual to allow for single-pass additive rendering.
|
||||
|
||||
@ -361,6 +362,7 @@
|
||||
- For `SkeletonAnimation.AnimationState` callbacks, there are additional main thread callbacks `MainThreadStart`, `MainThreadInterrupt`, `MainThreadEnd`, `MainThreadDispose`, `MainThreadComplete` and `MainThreadEvent` provided directly at `SkeletonAnimation`, e.g. `SkeletonAnimation.MainThreadComplete` for `SkeletonAnimation.AnimationState.Complete` and so on. Please note that this requires a change of user code to subscribe to these main thread delegate variants instead.
|
||||
- The same applies to the `TrackEntry.Start`, `Interrupt`, `End`, `Dispose`, `Complete`, and `Event` events. If you need these callbacks to run on the main thread instead of worker threads, you should register them using the corresponding `SkeletonAnimation.MainThreadStart`, `MainThreadInterrupt`, etc. callbacks. Note that this does require a small code change, since these events are **not** automatically unregistered when the `TrackEntry` is removed. You’ll need to handle that manually, typically with logic such as `if (trackEntry.Animation == attackAnimation) ..`.
|
||||
- Added `SkeletonUpdateSystem.Instance.GroupRenderersBySkeletonType` and `GroupAnimationBySkeletonType` properties. Defaults to disabled. Later when smart partitioning is implemented, enabling this parameter might slightly improve cache locality. Until then having it enabled combined with different skeleton complexity would lead to worse load balancing.
|
||||
- Added previously missing editor drag & drop skeleton instantiation option *SkeletonGraphic (UI) Mecanim* combining components `SkeletonGraphic` and `SkeletonMecanim`.
|
||||
|
||||
- **Deprecated**
|
||||
|
||||
|
||||
@ -381,82 +381,6 @@ namespace Spine.Unity.Editor {
|
||||
if (!skeletonGraphic.MatchRectTransformWithBounds())
|
||||
Debug.Log("Mesh was not previously generated.");
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Spine/SkeletonGraphic (UnityUI)", false, 15)]
|
||||
static public void SkeletonGraphicCreateMenuItem () {
|
||||
GameObject parentGameObject = Selection.activeObject as GameObject;
|
||||
RectTransform parentTransform = parentGameObject == null ? null : parentGameObject.GetComponent<RectTransform>();
|
||||
|
||||
if (parentTransform == null)
|
||||
Debug.LogWarning("Your new SkeletonGraphic will not be visible until it is placed under a Canvas");
|
||||
|
||||
GameObject gameObject = NewSkeletonGraphicGameObject("New SkeletonGraphic", typeof(SkeletonAnimation));
|
||||
gameObject.transform.SetParent(parentTransform, false);
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = gameObject;
|
||||
EditorGUIUtility.PingObject(Selection.activeObject);
|
||||
}
|
||||
|
||||
// SpineEditorUtilities.InstantiateDelegate. Used by drag and drop.
|
||||
public static Component SpawnSkeletonGraphicFromDrop (SkeletonDataAsset data) {
|
||||
return InstantiateSkeletonGraphic(data);
|
||||
}
|
||||
|
||||
public static SkeletonGraphic InstantiateSkeletonGraphic (SkeletonDataAsset skeletonDataAsset, string skinName) {
|
||||
return InstantiateSkeletonGraphic(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
|
||||
}
|
||||
|
||||
public static SkeletonGraphic InstantiateSkeletonGraphic (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
|
||||
string spineGameObjectName = string.Format("SkeletonGraphic ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
||||
GameObject go = NewSkeletonGraphicGameObject(spineGameObjectName, typeof(SkeletonAnimation));
|
||||
SkeletonGraphic graphic = go.GetComponent<SkeletonGraphic>();
|
||||
SkeletonAnimation animation = go.GetComponent<SkeletonAnimation>();
|
||||
graphic.skeletonDataAsset = skeletonDataAsset;
|
||||
|
||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||
|
||||
if (data == null) {
|
||||
for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
|
||||
string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
|
||||
skeletonDataAsset.atlasAssets[i] = (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAssetBase));
|
||||
}
|
||||
|
||||
data = skeletonDataAsset.GetSkeletonData(true);
|
||||
}
|
||||
|
||||
skin = skin ?? data.DefaultSkin ?? data.Skins.Items[0];
|
||||
graphic.MeshSettings.zSpacing = SpineEditorUtilities.Preferences.defaultZSpacing;
|
||||
|
||||
animation.loop = SpineEditorUtilities.Preferences.defaultInstantiateLoop;
|
||||
graphic.Initialize(false);
|
||||
animation.Initialize(false);
|
||||
if (skin != null) graphic.Skeleton.SetSkin(skin);
|
||||
graphic.initialSkinName = skin.Name;
|
||||
graphic.Skeleton.UpdateWorldTransform(Physics.Update);
|
||||
graphic.UpdateMesh();
|
||||
return graphic;
|
||||
}
|
||||
|
||||
static GameObject NewSkeletonGraphicGameObject (string gameObjectName, System.Type animationComponentType) {
|
||||
GameObject go = EditorInstantiation.NewGameObject(gameObjectName, true, typeof(RectTransform),
|
||||
typeof(CanvasRenderer), typeof(SkeletonGraphic));
|
||||
// Note: SkeletonAnimation component was already implicitly added by
|
||||
// SkeletonGraphic.Awake() above, calling UpgradeTo43Components().
|
||||
if (go.GetComponent(animationComponentType) == null)
|
||||
EditorInstantiation.AddComponent(go, true, animationComponentType);
|
||||
|
||||
SkeletonGraphic graphic = go.GetComponent<SkeletonGraphic>();
|
||||
graphic.material = SkeletonGraphicUtility.DefaultSkeletonGraphicMaterial;
|
||||
graphic.additiveMaterial = SkeletonGraphicUtility.DefaultSkeletonGraphicAdditiveMaterial;
|
||||
graphic.multiplyMaterial = SkeletonGraphicUtility.DefaultSkeletonGraphicMultiplyMaterial;
|
||||
graphic.screenMaterial = SkeletonGraphicUtility.DefaultSkeletonGraphicScreenMaterial;
|
||||
|
||||
#if HAS_CULL_TRANSPARENT_MESH
|
||||
CanvasRenderer canvasRenderer = go.GetComponent<CanvasRenderer>();
|
||||
canvasRenderer.cullTransparentMesh = false;
|
||||
#endif
|
||||
return go;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,47 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated April 5, 2025. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2025, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "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 LLC 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
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity.Editor {
|
||||
public static class Menus {
|
||||
[MenuItem("GameObject/Spine/SkeletonRenderer", false, 10)]
|
||||
static public void CreateSkeletonRendererGameObject () {
|
||||
EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonRenderer>("New SkeletonRenderer", true);
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/Spine/SkeletonAnimation", false, 10)]
|
||||
static public void CreateSkeletonAnimationGameObject () {
|
||||
EditorInstantiation.InstantiateEmptySpineGameObject<SkeletonAnimation>("New SkeletonAnimation", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf21125cbd8928844a85a3ad9002693b
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -59,6 +59,10 @@
|
||||
#define HAS_BATCHMODE_QUERY
|
||||
#endif
|
||||
|
||||
#if UNITY_2018_2_OR_NEWER
|
||||
#define HAS_CULL_TRANSPARENT_MESH
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@ -1386,8 +1390,8 @@ namespace Spine.Unity.Editor {
|
||||
|
||||
internal static readonly List<SkeletonComponentSpawnType> additionalSpawnTypes = new List<SkeletonComponentSpawnType>();
|
||||
|
||||
public static void TryInitializeSkeletonRendererSettings (ISkeletonRenderer skeletonRenderer, Skin skin = null) {
|
||||
const string PMAShaderQuery = "Spine/";
|
||||
public static void TryInitializeSkeletonRenderer (ISkeletonRenderer skeletonRenderer, Skin skin = null) {
|
||||
const string SpineShaderPrefix = "Spine/";
|
||||
const string TintBlackShaderQuery = "Tint Black";
|
||||
|
||||
if (skeletonRenderer == null) return;
|
||||
@ -1399,7 +1403,7 @@ namespace Spine.Unity.Editor {
|
||||
foreach (AtlasAssetBase atlasAsset in skeletonDataAsset.atlasAssets) {
|
||||
if (!pmaVertexColors) {
|
||||
foreach (Material m in atlasAsset.Materials) {
|
||||
if (m.shader.name.Contains(PMAShaderQuery)) {
|
||||
if (m.shader.name.Contains(SpineShaderPrefix)) {
|
||||
pmaVertexColors = true;
|
||||
break;
|
||||
}
|
||||
@ -1432,6 +1436,46 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
}
|
||||
|
||||
static void TryInitializeSkeletonAnimation (SkeletonAnimation skeletonAnimation,
|
||||
SkeletonDataAsset skeletonDataAsset, GameObject gameObject, bool destroyInvalid = true) {
|
||||
|
||||
try {
|
||||
skeletonAnimation.Initialize(false);
|
||||
} catch (System.Exception e) {
|
||||
if (destroyInvalid) {
|
||||
Debug.LogWarning("Editor-instantiated SkeletonAnimation threw an Exception. Destroying GameObject to prevent orphaned GameObject.\n" + e.Message, skeletonDataAsset);
|
||||
GameObject.DestroyImmediate(gameObject);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
skeletonAnimation.loop = SpineEditorUtilities.Preferences.defaultInstantiateLoop;
|
||||
skeletonAnimation.Update(0);
|
||||
skeletonAnimation.AnimationState.Apply(skeletonAnimation.skeleton);
|
||||
skeletonAnimation.skeleton.UpdateWorldTransform(Physics.Update);
|
||||
}
|
||||
|
||||
static void TryInitializeSkeletonMecanim (SkeletonMecanim skeletonMecanim,
|
||||
SkeletonDataAsset skeletonDataAsset, GameObject gameObject, bool destroyInvalid = true) {
|
||||
|
||||
if (skeletonDataAsset.controller == null) {
|
||||
SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
|
||||
Debug.Log(string.Format("Mecanim controller was automatically generated and assigned for {0}", skeletonDataAsset.name), skeletonDataAsset);
|
||||
}
|
||||
gameObject.GetComponent<Animator>().runtimeAnimatorController = skeletonDataAsset.controller;
|
||||
|
||||
try {
|
||||
skeletonMecanim.Initialize(false);
|
||||
} catch (System.Exception e) {
|
||||
if (destroyInvalid) {
|
||||
Debug.LogWarning("Editor-instantiated SkeletonAnimation threw an Exception. Destroying GameObject to prevent orphaned GameObject.", skeletonDataAsset);
|
||||
GameObject.DestroyImmediate(gameObject);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
skeletonMecanim.UpdateOncePerFrame(0);
|
||||
skeletonMecanim.Renderer.LateUpdate();
|
||||
}
|
||||
|
||||
public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, string skinName,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
|
||||
@ -1440,11 +1484,8 @@ namespace Spine.Unity.Editor {
|
||||
return InstantiateSkeletonAnimation(skeletonDataAsset, skin, destroyInvalid, useObjectFactory);
|
||||
}
|
||||
|
||||
public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, Skin skin = null,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
|
||||
static SkeletonData GetSkeletonData (SkeletonDataAsset skeletonDataAsset) {
|
||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||
|
||||
if (data == null) {
|
||||
for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
|
||||
string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
|
||||
@ -1452,7 +1493,13 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
data = skeletonDataAsset.GetSkeletonData(false);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static SkeletonAnimation InstantiateSkeletonAnimation (SkeletonDataAsset skeletonDataAsset, Skin skin = null,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
|
||||
SkeletonData data = GetSkeletonData(skeletonDataAsset);
|
||||
if (data == null) {
|
||||
Debug.LogWarning("InstantiateSkeletonAnimation tried to instantiate a skeleton from an invalid SkeletonDataAsset.", skeletonDataAsset);
|
||||
return null;
|
||||
@ -1464,24 +1511,8 @@ namespace Spine.Unity.Editor {
|
||||
SkeletonRenderer skeletonRenderer = go.GetComponent<SkeletonRenderer>();
|
||||
SkeletonAnimation newSkeletonAnimation = go.GetComponent<SkeletonAnimation>();
|
||||
skeletonRenderer.skeletonDataAsset = skeletonDataAsset;
|
||||
TryInitializeSkeletonRendererSettings(skeletonRenderer, skin);
|
||||
|
||||
// Initialize
|
||||
try {
|
||||
newSkeletonAnimation.Initialize(false);
|
||||
} catch (System.Exception e) {
|
||||
if (destroyInvalid) {
|
||||
Debug.LogWarning("Editor-instantiated SkeletonAnimation threw an Exception. Destroying GameObject to prevent orphaned GameObject.\n" + e.Message, skeletonDataAsset);
|
||||
GameObject.DestroyImmediate(go);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
newSkeletonAnimation.loop = SpineEditorUtilities.Preferences.defaultInstantiateLoop;
|
||||
newSkeletonAnimation.Update(0);
|
||||
newSkeletonAnimation.AnimationState.Apply(newSkeletonAnimation.skeleton);
|
||||
newSkeletonAnimation.skeleton.UpdateWorldTransform(Physics.Update);
|
||||
|
||||
TryInitializeSkeletonRenderer(skeletonRenderer, skin);
|
||||
TryInitializeSkeletonAnimation(newSkeletonAnimation, skeletonDataAsset, go, destroyInvalid);
|
||||
return newSkeletonAnimation;
|
||||
}
|
||||
|
||||
@ -1513,17 +1544,6 @@ namespace Spine.Unity.Editor {
|
||||
return gameObject.AddComponent(type);
|
||||
}
|
||||
|
||||
public static void InstantiateEmptySpineGameObject<T> (string name, bool useObjectFactory) where T : MonoBehaviour {
|
||||
GameObject parentGameObject = Selection.activeObject as GameObject;
|
||||
Transform parentTransform = parentGameObject == null ? null : parentGameObject.transform;
|
||||
|
||||
GameObject gameObject = EditorInstantiation.NewGameObject(name, useObjectFactory, typeof(T));
|
||||
gameObject.transform.SetParent(parentTransform, false);
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = gameObject;
|
||||
EditorGUIUtility.PingObject(Selection.activeObject);
|
||||
}
|
||||
|
||||
#region SkeletonMecanim
|
||||
#if SPINE_SKELETONMECANIM
|
||||
public static SkeletonMecanim InstantiateSkeletonMecanim (SkeletonDataAsset skeletonDataAsset, string skinName) {
|
||||
@ -1532,16 +1552,8 @@ namespace Spine.Unity.Editor {
|
||||
|
||||
public static SkeletonMecanim InstantiateSkeletonMecanim (SkeletonDataAsset skeletonDataAsset, Skin skin = null,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
SkeletonData data = skeletonDataAsset.GetSkeletonData(true);
|
||||
|
||||
if (data == null) {
|
||||
for (int i = 0; i < skeletonDataAsset.atlasAssets.Length; i++) {
|
||||
string reloadAtlasPath = AssetDatabase.GetAssetPath(skeletonDataAsset.atlasAssets[i]);
|
||||
skeletonDataAsset.atlasAssets[i] = (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(reloadAtlasPath, typeof(AtlasAssetBase));
|
||||
}
|
||||
data = skeletonDataAsset.GetSkeletonData(false);
|
||||
}
|
||||
|
||||
|
||||
SkeletonData data = GetSkeletonData(skeletonDataAsset);
|
||||
if (data == null) {
|
||||
Debug.LogWarning("InstantiateSkeletonMecanim tried to instantiate a skeleton from an invalid SkeletonDataAsset.", skeletonDataAsset);
|
||||
return null;
|
||||
@ -1551,35 +1563,88 @@ namespace Spine.Unity.Editor {
|
||||
GameObject go = EditorInstantiation.NewGameObject(spineGameObjectName, useObjectFactory,
|
||||
typeof(MeshFilter), typeof(MeshRenderer), typeof(Animator), typeof(SkeletonRenderer), typeof(SkeletonMecanim));
|
||||
|
||||
if (skeletonDataAsset.controller == null) {
|
||||
SkeletonBaker.GenerateMecanimAnimationClips(skeletonDataAsset);
|
||||
Debug.Log(string.Format("Mecanim controller was automatically generated and assigned for {0}", skeletonDataAsset.name), skeletonDataAsset);
|
||||
}
|
||||
|
||||
go.GetComponent<Animator>().runtimeAnimatorController = skeletonDataAsset.controller;
|
||||
|
||||
SkeletonRenderer skeletonRenderer = go.GetComponent<SkeletonRenderer>();
|
||||
SkeletonMecanim newSkeletonMecanim = go.GetComponent<SkeletonMecanim>();
|
||||
skeletonRenderer.skeletonDataAsset = skeletonDataAsset;
|
||||
TryInitializeSkeletonRendererSettings(skeletonRenderer, skin);
|
||||
TryInitializeSkeletonRenderer(skeletonRenderer, skin);
|
||||
TryInitializeSkeletonMecanim(newSkeletonMecanim, skeletonDataAsset, go, destroyInvalid);
|
||||
return newSkeletonMecanim;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
try {
|
||||
newSkeletonMecanim.Initialize(false);
|
||||
} catch (System.Exception e) {
|
||||
if (destroyInvalid) {
|
||||
Debug.LogWarning("Editor-instantiated SkeletonAnimation threw an Exception. Destroying GameObject to prevent orphaned GameObject.", skeletonDataAsset);
|
||||
GameObject.DestroyImmediate(go);
|
||||
}
|
||||
throw e;
|
||||
public static SkeletonMecanim InstantiateSkeletonMecanimGraphic (SkeletonDataAsset skeletonDataAsset, string skinName) {
|
||||
return InstantiateSkeletonMecanimGraphic(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
|
||||
}
|
||||
|
||||
public static SkeletonMecanim InstantiateSkeletonMecanimGraphic (SkeletonDataAsset skeletonDataAsset, Skin skin = null,
|
||||
bool destroyInvalid = true, bool useObjectFactory = true) {
|
||||
|
||||
string spineGameObjectName = string.Format("SkeletonGraphic ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
||||
GameObject go = NewSkeletonGraphicGameObject(spineGameObjectName, typeof(SkeletonMecanim));
|
||||
SkeletonGraphic skeletonGraphic = go.GetComponent<SkeletonGraphic>();
|
||||
SkeletonMecanim newSkeletonMecanim = go.GetComponent<SkeletonMecanim>();
|
||||
skeletonGraphic.skeletonDataAsset = skeletonDataAsset;
|
||||
|
||||
SkeletonData data = GetSkeletonData(skeletonDataAsset);
|
||||
if (data == null) {
|
||||
Debug.LogWarning("InstantiateSkeletonMecanimGraphic tried to instantiate a skeleton from an invalid SkeletonDataAsset.", skeletonDataAsset);
|
||||
return null;
|
||||
}
|
||||
|
||||
newSkeletonMecanim.UpdateOncePerFrame(0);
|
||||
newSkeletonMecanim.Renderer.LateUpdate();
|
||||
|
||||
TryInitializeSkeletonRenderer(skeletonGraphic, skin);
|
||||
TryInitializeSkeletonMecanim(newSkeletonMecanim, skeletonDataAsset, go, destroyInvalid);
|
||||
return newSkeletonMecanim;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
#endregion SkeletonMecanim
|
||||
|
||||
#region SkeletonGraphic
|
||||
public static Component SpawnSkeletonGraphicFromDrop (SkeletonDataAsset data) {
|
||||
return InstantiateSkeletonGraphic(data);
|
||||
}
|
||||
|
||||
public static SkeletonGraphic InstantiateSkeletonGraphic (SkeletonDataAsset skeletonDataAsset, string skinName) {
|
||||
return InstantiateSkeletonGraphic(skeletonDataAsset, skeletonDataAsset.GetSkeletonData(true).FindSkin(skinName));
|
||||
}
|
||||
|
||||
public static SkeletonGraphic InstantiateSkeletonGraphic (SkeletonDataAsset skeletonDataAsset, Skin skin = null) {
|
||||
string spineGameObjectName = string.Format("SkeletonGraphic ({0})", skeletonDataAsset.name.Replace("_SkeletonData", ""));
|
||||
GameObject go = NewSkeletonGraphicGameObject(spineGameObjectName, typeof(SkeletonAnimation));
|
||||
SkeletonGraphic graphic = go.GetComponent<SkeletonGraphic>();
|
||||
SkeletonAnimation animation = go.GetComponent<SkeletonAnimation>();
|
||||
graphic.skeletonDataAsset = skeletonDataAsset;
|
||||
|
||||
SkeletonData data = GetSkeletonData(skeletonDataAsset);
|
||||
if (data == null) {
|
||||
Debug.LogWarning("InstantiateSkeletonGraphic tried to instantiate a skeleton from an invalid SkeletonDataAsset.", skeletonDataAsset);
|
||||
return null;
|
||||
}
|
||||
|
||||
TryInitializeSkeletonRenderer(graphic, skin);
|
||||
TryInitializeSkeletonAnimation(animation, skeletonDataAsset, go, true);
|
||||
|
||||
return graphic;
|
||||
}
|
||||
|
||||
public static GameObject NewSkeletonGraphicGameObject (string gameObjectName, System.Type animationComponentType) {
|
||||
GameObject go = EditorInstantiation.NewGameObject(gameObjectName, true, typeof(RectTransform),
|
||||
typeof(CanvasRenderer), typeof(SkeletonGraphic));
|
||||
// Note: SkeletonAnimation component was already implicitly added by
|
||||
// SkeletonGraphic.Awake() above, calling UpgradeTo43Components().
|
||||
if (go.GetComponent(animationComponentType) == null)
|
||||
EditorInstantiation.AddComponent(go, true, animationComponentType);
|
||||
|
||||
SkeletonGraphic graphic = go.GetComponent<SkeletonGraphic>();
|
||||
graphic.material = SkeletonGraphicUtility.DefaultSkeletonGraphicMaterial;
|
||||
graphic.additiveMaterial = SkeletonGraphicUtility.DefaultSkeletonGraphicAdditiveMaterial;
|
||||
graphic.multiplyMaterial = SkeletonGraphicUtility.DefaultSkeletonGraphicMultiplyMaterial;
|
||||
graphic.screenMaterial = SkeletonGraphicUtility.DefaultSkeletonGraphicScreenMaterial;
|
||||
|
||||
#if HAS_CULL_TRANSPARENT_MESH
|
||||
CanvasRenderer canvasRenderer = go.GetComponent<CanvasRenderer>();
|
||||
canvasRenderer.cullTransparentMesh = false;
|
||||
#endif
|
||||
return go;
|
||||
}
|
||||
#endregion SkeletonGraphic
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ namespace Spine.Unity.Editor {
|
||||
Transform parent, int siblingIndex = 0) {
|
||||
GenericMenu menu = new GenericMenu();
|
||||
|
||||
// SkeletonAnimation
|
||||
// SkeletonAnimation + SkeletonRenderer
|
||||
menu.AddItem(new GUIContent("SkeletonAnimation"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||
skeletonDataAsset = skeletonDataAsset,
|
||||
spawnPoint = spawnPoint,
|
||||
@ -106,24 +106,19 @@ namespace Spine.Unity.Editor {
|
||||
isUI = false
|
||||
});
|
||||
|
||||
// SkeletonGraphic
|
||||
System.Type skeletonGraphicInspectorType = System.Type.GetType("Spine.Unity.Editor.SkeletonGraphicInspector");
|
||||
if (skeletonGraphicInspectorType != null) {
|
||||
MethodInfo graphicInstantiateDelegate = skeletonGraphicInspectorType.GetMethod("SpawnSkeletonGraphicFromDrop", BindingFlags.Static | BindingFlags.Public);
|
||||
if (graphicInstantiateDelegate != null)
|
||||
menu.AddItem(new GUIContent("SkeletonGraphic (UI)"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||
skeletonDataAsset = skeletonDataAsset,
|
||||
spawnPoint = spawnPoint,
|
||||
parent = parent,
|
||||
siblingIndex = siblingIndex,
|
||||
instantiateDelegate = System.Delegate.CreateDelegate(typeof(EditorInstantiation.InstantiateDelegate), graphicInstantiateDelegate) as EditorInstantiation.InstantiateDelegate,
|
||||
isUI = true
|
||||
});
|
||||
}
|
||||
// SkeletonAnimation + SkeletonGraphic
|
||||
menu.AddItem(new GUIContent("SkeletonGraphic (UI)"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||
skeletonDataAsset = skeletonDataAsset,
|
||||
spawnPoint = spawnPoint,
|
||||
parent = parent,
|
||||
siblingIndex = siblingIndex,
|
||||
instantiateDelegate = (data) => EditorInstantiation.SpawnSkeletonGraphicFromDrop(data),
|
||||
isUI = true
|
||||
});
|
||||
|
||||
#if SPINE_SKELETONMECANIM
|
||||
menu.AddSeparator("");
|
||||
// SkeletonMecanim
|
||||
// SkeletonMecanim + SkeletonRenderer
|
||||
menu.AddItem(new GUIContent("SkeletonMecanim"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||
skeletonDataAsset = skeletonDataAsset,
|
||||
spawnPoint = spawnPoint,
|
||||
@ -132,6 +127,16 @@ namespace Spine.Unity.Editor {
|
||||
instantiateDelegate = (data) => EditorInstantiation.InstantiateSkeletonMecanim(data),
|
||||
isUI = false
|
||||
});
|
||||
|
||||
// SkeletonMecanim + SkeletonGraphic
|
||||
menu.AddItem(new GUIContent("SkeletonGraphic (UI) Mecanim"), false, HandleSkeletonComponentDrop, new SpawnMenuData {
|
||||
skeletonDataAsset = skeletonDataAsset,
|
||||
spawnPoint = spawnPoint,
|
||||
parent = parent,
|
||||
siblingIndex = siblingIndex,
|
||||
instantiateDelegate = (data) => EditorInstantiation.InstantiateSkeletonMecanimGraphic(data),
|
||||
isUI = true
|
||||
});
|
||||
#endif
|
||||
|
||||
menu.ShowAsContext();
|
||||
@ -160,7 +165,7 @@ namespace Spine.Unity.Editor {
|
||||
newTransform.position = isUI ? data.spawnPoint : RoundVector(data.spawnPoint, 2);
|
||||
|
||||
if (isUI) {
|
||||
SkeletonGraphic skeletonGraphic = ((SkeletonGraphic)newSkeletonComponent);
|
||||
SkeletonGraphic skeletonGraphic = newSkeletonComponent.GetComponent<SkeletonGraphic>();
|
||||
if (usedParent != null && usedParent.GetComponent<RectTransform>() != null) {
|
||||
skeletonGraphic.MatchRectTransformWithBounds();
|
||||
} else
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user