Skip to content

Instantly share code, notes, and snippets.

@gekidoslair
Created February 7, 2018 00:40
Show Gist options
  • Save gekidoslair/c7c9a44858929db616440ceb65baba48 to your computer and use it in GitHub Desktop.
Save gekidoslair/c7c9a44858929db616440ceb65baba48 to your computer and use it in GitHub Desktop.
Debug draw bones in the editor
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