Created
February 7, 2018 00:40
-
-
Save gekidoslair/c7c9a44858929db616440ceb65baba48 to your computer and use it in GitHub Desktop.
Debug draw bones in the editor
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
using UnityEngine; | |
namespace PixelWizards.Shared.Utilities | |
{ | |
/// <summary> | |
/// Debug draw bones in the editor | |
/// </summary> | |
public class ShowBones : MonoBehaviour | |
{ | |
private Transform rootNode; | |
private Transform[] childNodes; | |
private void OnDrawGizmosSelected() | |
{ | |
if (childNodes == null) | |
{ | |
//get all joints to draw | |
PopulateChildren(); | |
} | |
foreach (var child in childNodes) | |
{ | |
if (child == rootNode) | |
{ | |
//list includes the root, if root then larger, green cube | |
Gizmos.color = Color.green; | |
Gizmos.DrawCube(child.position, new Vector3(.1f, .1f, .1f)); | |
} | |
else | |
{ | |
Gizmos.color = Color.blue; | |
Gizmos.DrawLine(child.position, child.parent.position); | |
Gizmos.DrawCube(child.position, new Vector3(.01f, .01f, .01f)); | |
} | |
} | |
} | |
private void PopulateChildren() | |
{ | |
childNodes = transform.GetComponentsInChildren<Transform>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment