Created
January 3, 2017 00:46
-
-
Save pointcache/42a0dcf58a49b83ba29e7c8d6b6e4a73 to your computer and use it in GitHub Desktop.
Hierarchy Visualizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
namespace pointcache.utility | |
{ | |
using UnityEngine; | |
using System; | |
using System.Collections.Generic; | |
using UnityEditor; | |
public class BoneDrawer : MonoBehaviour | |
{ | |
const float rad = 0.05f; | |
private void OnDrawGizmos() | |
{ | |
if (transform.parent != null) | |
{ | |
Gizmos.DrawLine(transform.position, transform.parent.position); | |
Gizmos.DrawSphere(transform.position, rad); | |
} | |
} | |
private void OnDrawGizmosSelected() | |
{ | |
if (transform.parent != null) | |
{ | |
if (Selection.activeGameObject == gameObject) | |
{ | |
Handles.Label(transform.position, "----------- " + name); | |
Gizmos.color = Color.yellow; | |
Gizmos.DrawLine(transform.position, transform.parent.position); | |
Gizmos.DrawWireSphere(transform.position, rad + 0.01f); | |
Gizmos.DrawWireSphere(transform.parent.position, rad + 0.01f); | |
} | |
else | |
{ | |
Gizmos.color = Color.green; | |
Gizmos.DrawWireSphere(transform.position, rad + 0.01f); | |
Gizmos.DrawLine(transform.position, transform.parent.position); | |
} | |
} | |
} | |
} | |
} | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add this to your root object enable disable to control | |
#if UNITY_EDITOR | |
namespace pointcache.utility | |
{ | |
using UnityEngine; | |
using System; | |
using System.Collections.Generic; | |
using UnityEditor; | |
[ExecuteInEditMode] | |
public class HierarchyVisualizer : MonoBehaviour | |
{ | |
public bool hideMesh = true; | |
private void OnEnable() | |
{ | |
AddDrawers_Recursive(transform); | |
var mr = GetComponent<SkinnedMeshRenderer>(); | |
if (!mr) | |
{ | |
mr = GetComponentInChildren<SkinnedMeshRenderer>(); | |
} | |
mr.enabled = !hideMesh; | |
} | |
private void OnDisable() | |
{ | |
RemoveDrawers_Recursive(transform); | |
var mr = GetComponent<SkinnedMeshRenderer>(); | |
if (!mr) | |
{ | |
mr = GetComponentInChildren<SkinnedMeshRenderer>(); | |
} | |
mr.enabled = true; | |
} | |
void AddDrawers_Recursive(Transform tr) | |
{ | |
if (tr.childCount > 0) | |
{ | |
foreach (Transform t in tr) | |
{ | |
if (!t.gameObject.GetComponent<BoneDrawer>()) | |
t.gameObject.AddComponent<BoneDrawer>(); | |
AddDrawers_Recursive(t); | |
} | |
} | |
} | |
void RemoveDrawers_Recursive(Transform tr) | |
{ | |
if (tr.childCount > 0) | |
{ | |
foreach (Transform t in tr) | |
{ | |
var drawer = t.gameObject.GetComponent<BoneDrawer>(); | |
DestroyImmediate(drawer); | |
RemoveDrawers_Recursive(t); | |
} | |
} | |
} | |
} | |
} | |
#endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment