void OnEnable() { // Setup the SerializedProperties. IkTarget = serializedObject.FindProperty("Target"); ShowAngleLimits = serializedObject.FindProperty("ShowAngleLimits"); ChainLength = serializedObject.FindProperty("chainLength"); _boneIk = (BoneIK)target; _bone = _boneIk.GetComponent <Bone>(); }
public static void DrawBoneIKGizmo(BoneIK scr, GizmoType gizmoType) { if (scr.Target != null && scr.ShowAngleLimits && (Selection.activeGameObject == scr.gameObject || Selection.activeGameObject == scr.Target.gameObject)) { var nodes = scr.GetComponentsInParent <Bone>().ToList(); nodes.Add(scr.GetComponent <Bone>()); foreach (var node1 in nodes) { if (node1.transform == null) { continue; } Transform nodetransform = node1.transform; Vector3 position = nodetransform.position; float handleSize = HandleUtility.GetHandleSize(position) / 2f; float discSize = handleSize * 0.5f; float parentRotation = nodetransform.parent != null && nodetransform.parent.GetComponent <Bone>() != null ? nodetransform.parent.eulerAngles.z : 0; bool throwZero = node1.Limit.x > node1.Limit.y; var minAngle = throwZero ? node1.Limit.x - 360f : node1.Limit.x; var maxAngle = node1.Limit.y; Vector3 min = Quaternion.Euler(0, 0, minAngle + parentRotation) * node1._head.normalized; Vector3 max = Quaternion.Euler(0, 0, maxAngle + parentRotation) * node1._head.normalized; Handles.color = new Color(0, 1, 0, 0.1f); Handles.DrawWireDisc(position, Vector3.back, discSize); Handles.DrawSolidArc(position, Vector3.forward, min, maxAngle - minAngle, discSize); Handles.color = Color.green; Handles.DrawLine(position, position + min * discSize); Handles.DrawLine(position, position + max * discSize); Handles.DrawLine(position, position + scr.Target.transform.parent.position); } } }