private static void DrawMissingBonesSign(TargetBonesData target) { var bone = target.Bones.FirstOrDefault(b => b != null); if (bone == null) { bone = target.Renderer.transform; } Handles.Label(bone.position, "Missing bones!!!", BONE_MISSING_LABEL_STYLE); }
private static void DrawBoneHandles(TargetBonesData target) { Handles.zTest = CompareFunction.Always; var bones = target.Bones; // Bones could be destroyed in any moment (edit or play mode). if (bones.Any(b => b == null)) { DrawMissingBonesSign(target); return; } // Single bone is a special case. if (bones.Length <= 1) { if (bones.Length == 1) { DrawLoneBone(bones[0]); } return; } if (target.AverageDistance < 0.001f) { DrawLoneBone(bones[0]); return; } // TODO: Draw lines from and to only if parented? // Draw lines and cones along the bones. { Handles.color = BONE_LINE_COLOR; foreach (var boneSegment in target.BoneSegments) { var pos1 = boneSegment.Bone1.position; var pos2 = boneSegment.Bone2.position; var dist = pos2 - pos1; if (dist == Vector3.zero) { continue; } Handles.DrawLine(pos1, pos2); var conePos = pos1 + dist / 2f; Handles.ConeHandleCap(0, conePos, Quaternion.LookRotation(dist.normalized), HandleSize(conePos, target.AverageDistance, 0.5f), Event.current.type); } } Handles.color = BONE_SPHERE_COLOR; for (int i = 0; i < bones.Length; ++i) { var bone = bones[i]; var handleSie = HandleSize(bone.position, target.AverageDistance); if (Handles.Button(bone.position, Quaternion.identity, handleSie, handleSie, Handles.SphereHandleCap)) { Selection.activeGameObject = bone.gameObject; } BONE_SPHERE_LABEL_STYLE.contentOffset = i < 10 ? new Vector2(-0.5f, -3f) : new Vector2(-3f, -3f); Handles.Label(bone.position, i.ToString(), BONE_SPHERE_LABEL_STYLE); } }