/// <summary> /// Bind a transform in the scene to the Hand Binder /// </summary> /// <param name="boneTransform">The transform you want to assign </param> /// <param name="fingerIndex"> The index of the finger you want to assign</param> /// <param name="boneIndex">The index of the bone you want to assign</param> /// <param name="handBinder">The Hand Binder this information will be added to</param> /// <returns></returns> public static BoundBone[] AssignTransformToBoundBone(Transform[] boneTransform) { var boundFingers = new BoundBone[] { AssignBoundBone(boneTransform[0]), AssignBoundBone(boneTransform[1]), AssignBoundBone(boneTransform[2]), AssignBoundBone(boneTransform[3]), }; return(boundFingers); }
public static BoundBone AssignBoundBone(Transform transform) { var newBone = new BoundBone(); if (transform != null) { newBone.boundTransform = transform; newBone.startTransform = new TransformStore(); newBone.startTransform.position = transform.localPosition; newBone.startTransform.rotation = transform.localRotation.eulerAngles; } return(newBone); }
/// <summary> /// Draw the object field that will allow the user to drag a transform from the scene and attach it to the hand binder data /// </summary> /// <param name="name"></param> /// <param name="boundBone"></param> /// <param name="autoAssignChildren"></param> /// <param name="fingerID"></param> /// <param name="boneID"></param> void DrawObjectField(string name, ref BoundBone boundBone, bool autoAssignChildren = false, int fingerID = 0, int boneID = 0) { GUILayout.BeginHorizontal(); GUI.color = boundBone.boundTransform != null ? Color.green : Color.white; GUILayout.Label(name, editorSkin.label); GUI.color = Color.white; var newTransform = (Transform)EditorGUILayout.ObjectField(boundBone.boundTransform, typeof(Transform), true, GUILayout.MaxWidth(EditorGUIUtility.labelWidth * 2)); if (newTransform != boundBone.boundTransform) { Undo.RegisterFullObjectHierarchyUndo(handBinder, "Bound Object"); boundBone = HandBinderAutoBinder.AssignBoundBone(newTransform); if (boundBone.boundTransform != null) { if (autoAssignChildren) { AutoAssignChildrenBones(newTransform, fingerID, boneID); } } } GUILayout.EndHorizontal(); }