1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
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;
}
}
|