Skip to content

Instantly share code, notes, and snippets.

@gekidoslair
Created February 7, 2018 00:40

Revisions

  1. gekidoslair created this gist Feb 7, 2018.
    43 changes: 43 additions & 0 deletions DrawBones.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    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>();
    }
    }
    }