using System; using System.Reflection; using UnityEngine; using UnityEditor; // sortingLayer // sortingOrder // bounds // bonecount [CustomEditor(typeof(SkinnedMeshRenderer), true)] [CanEditMultipleObjects] public class SkinnedMeshRendererInspector : InspectorExt { protected override string defaultEditorName => "UnityEditor.SkinnedMeshRendererEditor, UnityEditor"; SkinnedMeshRenderer renderer; string s_BoundsIconPath = EditorGUIHelperSetUp.root + "Icons/bounds.png"; GUIContent s_BoundsIcon; bool s_ShowBounds = false; public override void OnEnable() { base.OnEnable(); renderer = target as SkinnedMeshRenderer; if (s_BoundsIcon == null) s_BoundsIcon = EditorGUIUtility.IconContent(s_BoundsIconPath); s_ShowBounds = false; } public override void OnDisable() { base.OnDisable(); s_ShowBounds = false; } public override void OnInspectorGUI() { base.OnInspectorGUI(); if (renderer == null) return; if(BeginMore()) { string sortingLayer = renderer.sortingLayerName; string[] layers = new string[SortingLayer.layers.Length]; int index = 0; for (int i = 0; i < layers.Length; ++i) { layers[i] = SortingLayer.layers[i].name; if (sortingLayer == layers[i]) index = i; } index = EditorGUILayout.Popup("Sorting Layer", index, layers); renderer.sortingLayerName = layers[index]; renderer.sortingOrder = EditorGUILayout.IntField("Sorting Order", renderer.sortingOrder); s_ShowBounds = EditorGUIHelper.ToggleButton("Show Bounds", s_ShowBounds, s_BoundsIcon); Transform bone0 = renderer.bones != null && renderer.bones.Length > 0 ? renderer.bones[0] : null; GUI.enabled = false; EditorGUILayout.ObjectField("Bones[0]", bone0, typeof(Transform), true); GUI.enabled = true; //EditorGUIHelper.LabelField("Bone Count", GetBoneCount(bone0).ToString()); EditorGUIHelper.LabelField("Bones Length", renderer.bones.Length.ToString()); // Mesh info Mesh mesh = renderer.sharedMesh; if(mesh) { EditorGUIHelper.LabelField("Mesh Info", "Vertex Count (VBO): " + mesh.vertexCount); EditorGUIHelper.LabelFieldRight("Topology Count (IBO): " + mesh.triangles.Length); EditorGUIHelper.LabelFieldRight("Possible Triangles Count: " + mesh.triangles.Length / 3); EditorGUIHelper.LabelFieldRight("SubMesh Count: " + mesh.subMeshCount); EditorGUIHelper.LabelFieldRight("Attributes: " + GetAttributesEnabled()); } } EndMore(); } private int GetBoneCount(Transform root) { if (root == null) return 0; int childCount = root.childCount; for (int i = 0; i < root.childCount; ++i) { childCount += GetBoneCount(root.GetChild(i)); } return childCount; } public override void OnSceneGUI() { base.OnSceneGUI(); if (s_ShowBounds) { Vector3 center = renderer.bounds.center; float radius = renderer.bounds.extents.magnitude; Handles.color = Color.white; EditorHandlesHelper.WireCube(center, renderer.bounds.size, Color.blue); Handles.color = Color.white; EditorHandlesHelper.Label(center, "bounds:" + renderer.bounds.size, Color.blue); } } private string GetAttributesEnabled() { if (renderer == null) return ""; string attr = ""; Mesh mesh = renderer.sharedMesh; if (mesh.vertices.Length > 0) attr += "[position] "; if (mesh.normals.Length > 0) attr += "[normal] "; if (mesh.tangents.Length > 0) attr += "[tangent] "; if (mesh.colors.Length > 0) attr += "[color] "; if (mesh.uv.Length > 0) attr += "[uv1] "; if (mesh.uv2.Length > 0) attr += "[uv2] "; if (mesh.uv3.Length > 0) attr += "[uv3] "; if (mesh.uv4.Length > 0) attr += "[uv4] "; #if UNITY_2019 || UNITY_2020 || UNITY_2021 if (mesh.uv5.Length > 0) attr += "[uv5] "; if (mesh.uv6.Length > 0) attr += "[uv6] "; if (mesh.uv7.Length > 0) attr += "[uv7] "; if (mesh.uv8.Length > 0) attr += "[uv8] "; #endif if (mesh.boneWeights.Length > 0) attr += "[boneWeights] "; return attr; } }