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