public static void DrawSkeleton(Transform reference, Dictionary <Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones, Handles.BoneRenderer boneRenderer)
        {
            // it can happen when the avatar tool is in edit mode and the user exit the tool in an unsual way
            //  new scene
            //  delete GO
            //  press play
            if (reference == null || actualBones == null)
            {
                return;
            }

            sPoseError = false;

            Bounds meshBounds = new Bounds();

            Renderer[] renderers = reference.root.GetComponentsInChildren <Renderer>();
            if (renderers != null)
            {
                foreach (Renderer renderer in renderers)
                {
                    meshBounds.Encapsulate(renderer.bounds.min);
                    meshBounds.Encapsulate(renderer.bounds.max);
                }
            }

            Quaternion orientation = Quaternion.identity;

            if (bones != null)
            {
                orientation = AvatarSetupTool.AvatarComputeOrientation(bones);
            }

            boneRenderer.ClearInstances();
            DrawSkeletonSubTree(actualBones, bones, orientation, reference, meshBounds, boneRenderer);
            boneRenderer.Render();

            Camera camera = Camera.current;

            if (sPoseError && camera != null)
            {
                GUIStyle style = new GUIStyle(GUI.skin.label);
                style.normal.textColor = Color.red;
                style.wordWrap         = false;
                style.alignment        = TextAnchor.MiddleLeft;
                style.fontSize         = 20;

                GUIContent content = EditorGUIUtility.TrTextContent("Character is not in T pose");

                Rect rect = GUILayoutUtility.GetRect(content, style);

                rect.x = 30;
                rect.y = 30; //camera.pixelHeight;

                Handles.BeginGUI();
                GUI.Label(rect, content, style);
                Handles.EndGUI();
            }
        }
        private static bool DrawSkeletonSubTree(Dictionary <Transform, bool> actualBones, AvatarSetupTool.BoneWrapper[] bones, Quaternion orientation, Transform tr, Bounds bounds, Handles.BoneRenderer boneRenderer)
        {
            // if this transform is not a valid bone
            if (!actualBones.ContainsKey(tr))
            {
                return(false);
            }

            int drawnChildren = 0;

            foreach (Transform child in tr)
            {
                if (DrawSkeletonSubTree(actualBones, bones, orientation, child, bounds, boneRenderer))
                {
                    drawnChildren++;
                }
            }

            if (!actualBones[tr] && drawnChildren <= 1)
            {
                return(false);
            }

            int index = -1;

            if (bones != null)
            {
                for (int i = 0; i < bones.Length; i++)
                {
                    if (bones[i].bone == tr)
                    {
                        index = i;
                        break;
                    }
                }
            }

            // There is no need to check for a pose error if the avatar is not yet valid or tools is not the active one
            bool poseError = AvatarSetupTool.GetBoneAlignmentError(bones, orientation, index) > 0;

            sPoseError |= poseError;

            if (poseError)
            {
                DrawPoseError(tr, bounds);
                Handles.color = kErrorColor;
            }
            else if (index != -1)
            {
                Handles.color = kHumanColor;
            }
            else if (!actualBones[tr])
            {
                Handles.color = kDummyColor;
            }
            else
            {
                Handles.color = kSkeletonColor;
            }

            // Override color if bone is selected
            if (Selection.activeObject == tr)
            {
                Handles.color = kSelectedColor;
            }

            Handles.DoBoneHandle(tr, actualBones, boneRenderer);

            return(true);
        }
 public static void DrawSkeleton(Transform reference, Dictionary <Transform, bool> actualBones, Handles.BoneRenderer boneRenderer)
 {
     DrawSkeleton(reference, actualBones, null, boneRenderer);
 }