using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using UnityEditor.EditorTools; [EditorTool("Bone Viewer", typeof(SkinnedMeshRenderer))] public class BoneViewerEditor : EditorTool { [SerializeField] Texture2D m_ToolIcon; GUIContent m_IconContent; void OnEnable() { m_IconContent = new GUIContent() { image = AssetDatabase.LoadAssetAtPath("Assets/Tools/BoneViewer/Editor/Bone.png"), text = "BoneView Tool", tooltip = "BoneView Tool" }; } public override GUIContent toolbarIcon { get { return m_IconContent; } } Rect m_WindowRect = new Rect(10, 30, 200, 0); bool m_ShowBones = true; Rect m_SceneRect; float m_Size = 0.03f; float m_Alpha = 0.2f; bool m_ShowName = false; void WindowFunction(int id) { Color col = GUI.color; if (m_ShowBones) GUI.color = Color.gray; if (GUILayout.Button("Show Bones")) { m_ShowBones = !m_ShowBones; } GUI.color = col; GUILayout.BeginHorizontal(); GUILayout.Label("Size "); m_Size = GUILayout.HorizontalSlider(m_Size, 0.01f, 0.1f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Alpha"); m_Alpha = GUILayout.HorizontalSlider(m_Alpha, 0f, 1f); GUILayout.EndHorizontal(); m_ShowName = GUILayout.Toggle(m_ShowName, "Show Name"); } public override void OnToolGUI(EditorWindow window) { SceneView scene = window as SceneView; if (scene == null) return; m_SceneRect = new Rect(0,0, scene.position.width, scene.position.height); SkinnedMeshRenderer renderer = this.target as SkinnedMeshRenderer; if (renderer == null) return; m_WindowRect = GUILayout.Window(1, m_WindowRect, WindowFunction, "Bone Viewer"); EditorGUILayout.LabelField("TestTestTestTestTestTest"); EditorGUI.BeginChangeCheck(); Handles.zTest = UnityEngine.Rendering.CompareFunction.Always; Handles.color = new Color(1, 1, 1, m_Alpha); Transform root = renderer.rootBone; if(root && m_ShowBones) DrawBone(null, root, 0); } void DrawBone(Transform parent, Transform bone, int depth) { if (bone == null) return; Handles.SphereHandleCap(0, bone.position, bone.rotation, m_Size, EventType.Repaint); if(parent) Handles.DrawLine(parent.position, bone.position); if(m_ShowName) { Handles.Label(bone.position, bone.name); } int count = bone.childCount; for(int i = 0;i < count; ++i) { DrawBone(bone, bone.GetChild(i), depth + 1); } } }