mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-09 12:16:53 +08:00
Added Sorting Layers GUI to SkeletonRenderer and SkeletonAnimation Inspectors.
This commit is contained in:
parent
67a639d12a
commit
cd198cc970
@ -66,6 +66,7 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
//TODO: Refactor this to use GenericMenu and callbacks to avoid interfering with control by other behaviours.
|
//TODO: Refactor this to use GenericMenu and callbacks to avoid interfering with control by other behaviours.
|
||||||
// Animation name.
|
// Animation name.
|
||||||
@ -80,10 +81,7 @@ public class SkeletonAnimationInspector : SkeletonRendererInspector {
|
|||||||
animationIndex = i + 1;
|
animationIndex = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
animationIndex = EditorGUILayout.Popup("Animation", animationIndex, animations);
|
||||||
EditorGUILayout.LabelField("Animation", GUILayout.Width(EditorGUIUtility.labelWidth));
|
|
||||||
animationIndex = EditorGUILayout.Popup(animationIndex, animations);
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
String selectedAnimationName = animationIndex == 0 ? null : animations[animationIndex];
|
String selectedAnimationName = animationIndex == 0 ? null : animations[animationIndex];
|
||||||
if (component.AnimationName != selectedAnimationName) {
|
if (component.AnimationName != selectedAnimationName) {
|
||||||
|
|||||||
@ -28,12 +28,17 @@
|
|||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
[CustomEditor(typeof(SkeletonRenderer))]
|
[CustomEditor(typeof(SkeletonRenderer))]
|
||||||
public class SkeletonRendererInspector : Editor {
|
public class SkeletonRendererInspector : Editor {
|
||||||
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, submeshSeparators, front;
|
protected SerializedProperty skeletonDataAsset, initialSkinName, normals, tangents, meshes, immutableTriangles, submeshSeparators, front;
|
||||||
|
protected bool advancedFoldout;
|
||||||
|
|
||||||
|
private static PropertyInfo SortingLayerNamesProperty;
|
||||||
|
private static MethodInfo GetSortingLayerUserID;
|
||||||
|
|
||||||
protected virtual void OnEnable () {
|
protected virtual void OnEnable () {
|
||||||
SpineEditorUtilities.ConfirmInitialization();
|
SpineEditorUtilities.ConfirmInitialization();
|
||||||
@ -45,6 +50,15 @@ public class SkeletonRendererInspector : Editor {
|
|||||||
immutableTriangles = serializedObject.FindProperty("immutableTriangles");
|
immutableTriangles = serializedObject.FindProperty("immutableTriangles");
|
||||||
submeshSeparators = serializedObject.FindProperty("submeshSeparators");
|
submeshSeparators = serializedObject.FindProperty("submeshSeparators");
|
||||||
front = serializedObject.FindProperty("frontFacing");
|
front = serializedObject.FindProperty("frontFacing");
|
||||||
|
|
||||||
|
|
||||||
|
var unityInternalEditorUtility = Type.GetType("UnityEditorInternal.InternalEditorUtility, UnityEditor");
|
||||||
|
|
||||||
|
if(SortingLayerNamesProperty == null)
|
||||||
|
SortingLayerNamesProperty = unityInternalEditorUtility.GetProperty("sortingLayerNames", BindingFlags.Static | BindingFlags.NonPublic);
|
||||||
|
|
||||||
|
if(GetSortingLayerUserID == null)
|
||||||
|
GetSortingLayerUserID = unityInternalEditorUtility.GetMethod("GetSortingLayerUserID", BindingFlags.Static | BindingFlags.NonPublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void gui () {
|
protected virtual void gui () {
|
||||||
@ -84,22 +98,61 @@ public class SkeletonRendererInspector : Editor {
|
|||||||
skinIndex = i;
|
skinIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.BeginHorizontal();
|
skinIndex = EditorGUILayout.Popup("Initial Skin", skinIndex, skins);
|
||||||
EditorGUILayout.LabelField("Initial Skin", GUILayout.Width(EditorGUIUtility.labelWidth));
|
|
||||||
skinIndex = EditorGUILayout.Popup(skinIndex, skins);
|
|
||||||
EditorGUILayout.EndHorizontal();
|
|
||||||
|
|
||||||
initialSkinName.stringValue = skins[skinIndex];
|
initialSkinName.stringValue = skins[skinIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(meshes,
|
EditorGUILayout.Space();
|
||||||
new GUIContent("Render Meshes", "Disable to optimize rendering for skeletons that don't use meshes"));
|
|
||||||
EditorGUILayout.PropertyField(immutableTriangles,
|
// Sorting Layers
|
||||||
new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility"));
|
{
|
||||||
EditorGUILayout.PropertyField(normals);
|
var renderer = component.GetComponent<Renderer>();
|
||||||
EditorGUILayout.PropertyField(tangents);
|
if(renderer != null) {
|
||||||
EditorGUILayout.PropertyField(front);
|
var sortingLayerNames = GetSortingLayerNames();
|
||||||
EditorGUILayout.PropertyField(submeshSeparators, true);
|
|
||||||
|
if (sortingLayerNames != null) {
|
||||||
|
var layerName = SortingLayerNameOfLayerID(renderer.sortingLayerID);
|
||||||
|
|
||||||
|
int oldIndex = Array.IndexOf(sortingLayerNames, layerName);
|
||||||
|
int newIndex = EditorGUILayout.Popup("Sorting Layer", oldIndex, sortingLayerNames);
|
||||||
|
|
||||||
|
if (newIndex != oldIndex) {
|
||||||
|
Undo.RecordObject(renderer, "Sorting Layer Changed");
|
||||||
|
renderer.sortingLayerID = SortingLayerIdOfLayerIndex(newIndex);
|
||||||
|
EditorUtility.SetDirty(renderer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
renderer.sortingLayerID = EditorGUILayout.IntField("Sorting Layer ID", renderer.sortingLayerID);
|
||||||
|
if(EditorGUI.EndChangeCheck()) {
|
||||||
|
EditorUtility.SetDirty(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
renderer.sortingOrder = EditorGUILayout.IntField("Order in Layer", renderer.sortingOrder);
|
||||||
|
if(EditorGUI.EndChangeCheck()) {
|
||||||
|
EditorUtility.SetDirty(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// More Render Options...
|
||||||
|
{
|
||||||
|
advancedFoldout = EditorGUILayout.Foldout(advancedFoldout, "Advanced");
|
||||||
|
if(advancedFoldout) {
|
||||||
|
EditorGUI.indentLevel++;
|
||||||
|
EditorGUILayout.PropertyField(meshes,
|
||||||
|
new GUIContent("Render Meshes", "Disable to optimize rendering for skeletons that don't use meshes"));
|
||||||
|
EditorGUILayout.PropertyField(immutableTriangles,
|
||||||
|
new GUIContent("Immutable Triangles", "Enable to optimize rendering for skeletons that never change attachment visbility"));
|
||||||
|
EditorGUILayout.PropertyField(normals);
|
||||||
|
EditorGUILayout.PropertyField(tangents);
|
||||||
|
EditorGUILayout.PropertyField(front);
|
||||||
|
EditorGUILayout.PropertyField(submeshSeparators, true);
|
||||||
|
EditorGUI.indentLevel--;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override public void OnInspectorGUI () {
|
override public void OnInspectorGUI () {
|
||||||
@ -112,4 +165,33 @@ public class SkeletonRendererInspector : Editor {
|
|||||||
((SkeletonRenderer)target).Reset();
|
((SkeletonRenderer)target).Reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Sorting Layers
|
||||||
|
protected static string[] GetSortingLayerNames () {
|
||||||
|
if(SortingLayerNamesProperty == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return SortingLayerNamesProperty.GetValue(null, null) as string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static string SortingLayerNameOfLayerID (int id) {
|
||||||
|
var layerNames = GetSortingLayerNames();
|
||||||
|
if(layerNames == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
for (int i = 0, n = layerNames.Length; i < n; i++) {
|
||||||
|
if (SortingLayerIdOfLayerIndex(i) == id)
|
||||||
|
return layerNames[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static int SortingLayerIdOfLayerIndex (int index) {
|
||||||
|
if(GetSortingLayerUserID == null) return 0;
|
||||||
|
|
||||||
|
var parameters = new object[] {index};
|
||||||
|
return (int)( GetSortingLayerUserID.Invoke( null, parameters ) );
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user