Skip to content

Instantly share code, notes, and snippets.

@mikenekoworks
Created February 27, 2018 03:53
Show Gist options
  • Save mikenekoworks/6b12369f9c1898d4aa8b19a10125fdb7 to your computer and use it in GitHub Desktop.
Save mikenekoworks/6b12369f9c1898d4aa8b19a10125fdb7 to your computer and use it in GitHub Desktop.
シーンビューにボーンを表示するです。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DisplayBone : MonoBehaviour {
public bool DisplayAxes = true;
public bool DisplayNames = true;
void DrawBones( Transform t ) {
foreach ( Transform child in t ) {
Gizmos.color = Color.black;
Gizmos.DrawLine( t.position, child.position );
Gizmos.DrawSphere( t.position, 0.0025f );
if ( DisplayNames == true ) {
#if UNITY_EDITOR
Gizmos.color = Color.black;
UnityEditor.Handles.Label( t.position + ( child.position - t.position ) / 2.0f, child.name );
#endif
}
if ( DisplayAxes == true ) {
float len = 0.01f;
Vector3 loxalX = new Vector3( len, 0, 0 );
Vector3 loxalY = new Vector3( 0, len, 0 );
Vector3 loxalZ = new Vector3( 0, 0, len );
loxalX = child.rotation * loxalX;
loxalY = child.rotation * loxalY;
loxalZ = child.rotation * loxalZ;
Gizmos.color = Color.red;
Gizmos.DrawLine( child.position, child.position + loxalX );
Gizmos.color = Color.green;
Gizmos.DrawLine( child.position, child.position + loxalY );
Gizmos.color = Color.blue;
Gizmos.DrawLine( child.position, child.position + loxalZ );
}
DrawBones( child );
}
}
void OnDrawGizmos() {
DrawBones( transform );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment