mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 10:46:53 +08:00
[Unity] Remove dynamic meshes in prefabs by default.
This commit is contained in:
parent
655708718b
commit
4a36a95f06
@ -28,7 +28,6 @@
|
|||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
using System;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Spine;
|
using Spine;
|
||||||
@ -38,7 +37,6 @@ namespace Spine.Unity.Editor {
|
|||||||
[CustomEditor(typeof(SkeletonAnimation))]
|
[CustomEditor(typeof(SkeletonAnimation))]
|
||||||
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
||||||
protected SerializedProperty animationName, loop, timeScale, autoReset;
|
protected SerializedProperty animationName, loop, timeScale, autoReset;
|
||||||
protected bool m_isPrefab;
|
|
||||||
protected bool wasAnimationNameChanged;
|
protected bool wasAnimationNameChanged;
|
||||||
|
|
||||||
protected override void OnEnable () {
|
protected override void OnEnable () {
|
||||||
@ -46,9 +44,6 @@ namespace Spine.Unity.Editor {
|
|||||||
animationName = serializedObject.FindProperty("_animationName");
|
animationName = serializedObject.FindProperty("_animationName");
|
||||||
loop = serializedObject.FindProperty("loop");
|
loop = serializedObject.FindProperty("loop");
|
||||||
timeScale = serializedObject.FindProperty("timeScale");
|
timeScale = serializedObject.FindProperty("timeScale");
|
||||||
|
|
||||||
if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab)
|
|
||||||
m_isPrefab = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DrawInspectorGUI () {
|
protected override void DrawInspectorGUI () {
|
||||||
@ -58,55 +53,55 @@ namespace Spine.Unity.Editor {
|
|||||||
if (!component.valid)
|
if (!component.valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (wasAnimationNameChanged) {
|
if (!isInspectingPrefab) {
|
||||||
if (!Application.isPlaying) {
|
if (wasAnimationNameChanged) {
|
||||||
if (component.state != null) component.state.ClearTrack(0);
|
if (!Application.isPlaying) {
|
||||||
component.skeleton.SetToSetupPose();
|
if (component.state != null) component.state.ClearTrack(0);
|
||||||
|
component.skeleton.SetToSetupPose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Spine.Animation animationToUse = component.skeleton.Data.FindAnimation(animationName.stringValue);
|
||||||
|
|
||||||
|
if (!Application.isPlaying) {
|
||||||
|
if (animationToUse != null) animationToUse.Apply(component.skeleton, 0f, 0f, false, null);
|
||||||
|
component.Update();
|
||||||
|
component.LateUpdate();
|
||||||
|
SceneView.RepaintAll();
|
||||||
|
} else {
|
||||||
|
if (animationToUse != null)
|
||||||
|
component.state.SetAnimation(0, animationToUse, loop.boolValue);
|
||||||
|
else
|
||||||
|
component.state.ClearTrack(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
wasAnimationNameChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spine.Animation animationToUse = component.skeleton.Data.FindAnimation(animationName.stringValue);
|
// Reflect animationName serialized property in the inspector even if SetAnimation API was used.
|
||||||
|
if (Application.isPlaying) {
|
||||||
if (!Application.isPlaying) {
|
TrackEntry current = component.state.GetCurrent(0);
|
||||||
if (animationToUse != null) animationToUse.Apply(component.skeleton, 0f, 0f, false, null);
|
if (current != null) {
|
||||||
component.Update();
|
if (component.AnimationName != animationName.stringValue)
|
||||||
component.LateUpdate();
|
animationName.stringValue = current.Animation.Name;
|
||||||
SceneView.RepaintAll();
|
|
||||||
} else {
|
|
||||||
if (animationToUse != null)
|
|
||||||
component.state.SetAnimation(0, animationToUse, loop.boolValue);
|
|
||||||
else
|
|
||||||
component.state.ClearTrack(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
wasAnimationNameChanged = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reflect animationName serialized property in the inspector even if SetAnimation API was used.
|
|
||||||
if (Application.isPlaying) {
|
|
||||||
TrackEntry current = component.state.GetCurrent(0);
|
|
||||||
if (current != null) {
|
|
||||||
if (component.AnimationName != animationName.stringValue) {
|
|
||||||
animationName.stringValue = current.Animation.Name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
EditorGUILayout.PropertyField(animationName);
|
EditorGUILayout.PropertyField(animationName);
|
||||||
wasAnimationNameChanged |= EditorGUI.EndChangeCheck();
|
wasAnimationNameChanged |= EditorGUI.EndChangeCheck(); // Value used in the next update.
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(loop);
|
EditorGUILayout.PropertyField(loop);
|
||||||
EditorGUILayout.PropertyField(timeScale);
|
EditorGUILayout.PropertyField(timeScale);
|
||||||
component.timeScale = Math.Max(component.timeScale, 0);
|
component.timeScale = Mathf.Max(component.timeScale, 0);
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
if (!m_isPrefab) {
|
if (!isInspectingPrefab) {
|
||||||
if (component.GetComponent<SkeletonUtility>() == null) {
|
if (component.GetComponent<SkeletonUtility>() == null) {
|
||||||
if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) {
|
if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30)))
|
||||||
component.gameObject.AddComponent<SkeletonUtility>();
|
component.gameObject.AddComponent<SkeletonUtility>();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
* SkeletonAnimatorInspector created by Mitch Thompson
|
* SkeletonAnimatorInspector created by Mitch Thompson
|
||||||
* Full irrevocable rights and permissions granted to Esoteric Software
|
* Full irrevocable rights and permissions granted to Esoteric Software
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
using System;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -10,27 +9,21 @@ namespace Spine.Unity.Editor {
|
|||||||
[CustomEditor(typeof(SkeletonAnimator))]
|
[CustomEditor(typeof(SkeletonAnimator))]
|
||||||
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
||||||
protected SerializedProperty layerMixModes;
|
protected SerializedProperty layerMixModes;
|
||||||
protected bool isPrefab;
|
|
||||||
protected override void OnEnable () {
|
protected override void OnEnable () {
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
layerMixModes = serializedObject.FindProperty("layerMixModes");
|
layerMixModes = serializedObject.FindProperty("layerMixModes");
|
||||||
|
|
||||||
if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab)
|
|
||||||
isPrefab = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DrawInspectorGUI () {
|
protected override void DrawInspectorGUI () {
|
||||||
base.DrawInspectorGUI();
|
base.DrawInspectorGUI();
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(layerMixModes, true);
|
EditorGUILayout.PropertyField(layerMixModes, true);
|
||||||
|
var component = (SkeletonAnimator)target;
|
||||||
SkeletonAnimator component = (SkeletonAnimator)target;
|
|
||||||
if (!component.valid)
|
if (!component.valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
if (!isPrefab) {
|
if (!isInspectingPrefab) {
|
||||||
if (component.GetComponent<SkeletonUtility>() == null) {
|
if (component.GetComponent<SkeletonUtility>() == null) {
|
||||||
if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) {
|
if (GUILayout.Button(new GUIContent("Add Skeleton Utility", SpineEditorUtilities.Icons.skeletonUtility), GUILayout.Height(30))) {
|
||||||
component.gameObject.AddComponent<SkeletonUtility>();
|
component.gameObject.AddComponent<SkeletonUtility>();
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
#define NO_PREFAB_MESH
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@ -38,12 +39,14 @@ namespace Spine.Unity.Editor {
|
|||||||
[CustomEditor(typeof(SkeletonRenderer))]
|
[CustomEditor(typeof(SkeletonRenderer))]
|
||||||
public class SkeletonRendererInspector : UnityEditor.Editor {
|
public class SkeletonRendererInspector : UnityEditor.Editor {
|
||||||
protected static bool advancedFoldout;
|
protected static bool advancedFoldout;
|
||||||
|
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, separatorSlotNames, frontFacing, zSpacing;
|
||||||
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, separatorSlotNames, front, zSpacing;
|
|
||||||
|
|
||||||
protected SpineInspectorUtility.SerializedSortingProperties sortingProperties;
|
protected SpineInspectorUtility.SerializedSortingProperties sortingProperties;
|
||||||
|
protected bool isInspectingPrefab;
|
||||||
|
protected MeshFilter meshFilter;
|
||||||
|
|
||||||
protected virtual void OnEnable () {
|
protected virtual void OnEnable () {
|
||||||
|
isInspectingPrefab = (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab);
|
||||||
|
|
||||||
SpineEditorUtilities.ConfirmInitialization();
|
SpineEditorUtilities.ConfirmInitialization();
|
||||||
skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset");
|
skeletonDataAsset = serializedObject.FindProperty("skeletonDataAsset");
|
||||||
initialSkinName = serializedObject.FindProperty("initialSkinName");
|
initialSkinName = serializedObject.FindProperty("initialSkinName");
|
||||||
@ -54,7 +57,7 @@ namespace Spine.Unity.Editor {
|
|||||||
separatorSlotNames = serializedObject.FindProperty("separatorSlotNames");
|
separatorSlotNames = serializedObject.FindProperty("separatorSlotNames");
|
||||||
separatorSlotNames.isExpanded = true;
|
separatorSlotNames.isExpanded = true;
|
||||||
|
|
||||||
front = serializedObject.FindProperty("frontFacing");
|
frontFacing = serializedObject.FindProperty("frontFacing");
|
||||||
zSpacing = serializedObject.FindProperty("zSpacing");
|
zSpacing = serializedObject.FindProperty("zSpacing");
|
||||||
|
|
||||||
var renderer = ((SkeletonRenderer)target).GetComponent<Renderer>();
|
var renderer = ((SkeletonRenderer)target).GetComponent<Renderer>();
|
||||||
@ -63,16 +66,17 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
protected virtual void DrawInspectorGUI () {
|
protected virtual void DrawInspectorGUI () {
|
||||||
SkeletonRenderer component = (SkeletonRenderer)target;
|
SkeletonRenderer component = (SkeletonRenderer)target;
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
EditorGUILayout.BeginHorizontal();
|
||||||
EditorGUILayout.PropertyField(skeletonDataAsset);
|
EditorGUILayout.PropertyField(skeletonDataAsset);
|
||||||
float reloadWidth = GUI.skin.label.CalcSize(new GUIContent("Reload")).x + 20;
|
const string ReloadButtonLabel = "Reload";
|
||||||
if (GUILayout.Button("Reload", GUILayout.Width(reloadWidth))) {
|
float reloadWidth = GUI.skin.label.CalcSize(new GUIContent(ReloadButtonLabel)).x + 20;
|
||||||
|
if (GUILayout.Button(ReloadButtonLabel, GUILayout.Width(reloadWidth))) {
|
||||||
if (component.skeletonDataAsset != null) {
|
if (component.skeletonDataAsset != null) {
|
||||||
foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) {
|
foreach (AtlasAsset aa in component.skeletonDataAsset.atlasAssets) {
|
||||||
if (aa != null)
|
if (aa != null)
|
||||||
aa.Reset();
|
aa.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
component.skeletonDataAsset.Reset();
|
component.skeletonDataAsset.Reset();
|
||||||
}
|
}
|
||||||
component.Initialize(true);
|
component.Initialize(true);
|
||||||
@ -86,6 +90,14 @@ namespace Spine.Unity.Editor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if NO_PREFAB_MESH
|
||||||
|
if (meshFilter == null)
|
||||||
|
meshFilter = component.GetComponent<MeshFilter>();
|
||||||
|
|
||||||
|
if (isInspectingPrefab)
|
||||||
|
meshFilter.sharedMesh = null;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initial skin name.
|
// Initial skin name.
|
||||||
{
|
{
|
||||||
String[] skins = new String[component.skeleton.Data.Skins.Count];
|
String[] skins = new String[component.skeleton.Data.Skins.Count];
|
||||||
@ -96,7 +108,6 @@ namespace Spine.Unity.Editor {
|
|||||||
if (skinNameString == initialSkinName.stringValue)
|
if (skinNameString == initialSkinName.stringValue)
|
||||||
skinIndex = i;
|
skinIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins);
|
skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins);
|
||||||
initialSkinName.stringValue = skins[skinIndex];
|
initialSkinName.stringValue = skins[skinIndex];
|
||||||
}
|
}
|
||||||
@ -113,7 +124,7 @@ namespace Spine.Unity.Editor {
|
|||||||
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) {
|
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) {
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced");
|
advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced");
|
||||||
if(advancedFoldout) {
|
if (advancedFoldout) {
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
SeparatorsField(separatorSlotNames);
|
SeparatorsField(separatorSlotNames);
|
||||||
EditorGUILayout.PropertyField(meshes,
|
EditorGUILayout.PropertyField(meshes,
|
||||||
@ -126,30 +137,27 @@ namespace Spine.Unity.Editor {
|
|||||||
const float MaxZSpacing = 0f;
|
const float MaxZSpacing = 0f;
|
||||||
EditorGUILayout.Slider(zSpacing, MinZSpacing, MaxZSpacing);
|
EditorGUILayout.Slider(zSpacing, MinZSpacing, MaxZSpacing);
|
||||||
|
|
||||||
|
// Optional fields. May be disabled in SkeletonRenderer.
|
||||||
if (normals != null) {
|
if (normals != null) {
|
||||||
EditorGUILayout.PropertyField(normals);
|
EditorGUILayout.PropertyField(normals);
|
||||||
EditorGUILayout.PropertyField(tangents);
|
EditorGUILayout.PropertyField(tangents);
|
||||||
}
|
}
|
||||||
|
if (frontFacing != null)
|
||||||
|
EditorGUILayout.PropertyField(frontFacing);
|
||||||
|
|
||||||
if (front != null) {
|
|
||||||
EditorGUILayout.PropertyField(front);
|
|
||||||
}
|
|
||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
}
|
}
|
||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SeparatorsField (SerializedProperty separatorSlotNames) {
|
public static void SeparatorsField (SerializedProperty separatorSlotNames) {
|
||||||
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) {
|
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) {
|
||||||
if (separatorSlotNames.isExpanded) {
|
if (separatorSlotNames.isExpanded)
|
||||||
EditorGUILayout.PropertyField(separatorSlotNames, includeChildren: true);
|
EditorGUILayout.PropertyField(separatorSlotNames, includeChildren: true);
|
||||||
} else {
|
else
|
||||||
EditorGUILayout.PropertyField(separatorSlotNames, new GUIContent(separatorSlotNames.displayName + string.Format(" [{0}]", separatorSlotNames.arraySize)), includeChildren: true);
|
EditorGUILayout.PropertyField(separatorSlotNames, new GUIContent(separatorSlotNames.displayName + string.Format(" [{0}]", separatorSlotNames.arraySize)), includeChildren: true);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user