Exemple #1
0
        //Reset is called when the user hits the Reset button in the Inspector's context menu or when adding the component the first time.
        private void Reset()
        {
            //Return if we already have assigned base transforms
            if (DefaultHandPose != null)
            {
                ResetHand();
                return;
            }

            else
            {
                //Store all children transforms so the user has the ability to reset back to a default pose
                var allChildren = new List <Transform>();
                allChildren.Add(transform);
                allChildren.AddRange(HandBinderAutoBinder.GetAllChildren(transform));

                var baseTransforms = new List <SerializedTransform>();
                foreach (var child in allChildren)
                {
                    var serializedTransform = new SerializedTransform();
                    serializedTransform.reference          = child.gameObject;
                    serializedTransform.transform          = new TransformStore();
                    serializedTransform.transform.position = child.localPosition;
                    serializedTransform.transform.rotation = child.localRotation.eulerAngles;
                    baseTransforms.Add(serializedTransform);
                }
                DefaultHandPose = baseTransforms.ToArray();
            }
        }
Exemple #2
0
 /// <summary>
 /// Draw any rotation offsets into the window
 /// </summary>
 void DrawRotationOffsets()
 {
     GUILayout.Label(dividerLine);
     GUILayout.Label(message2, editorSkin.label);
     if (GUILayout.Button("Calculate Rotation Offsets", editorSkin.button, GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth), GUILayout.MinHeight(spaceSize)))
     {
         if (EditorUtility.DisplayDialog("Auto Calculate Rotation Offsets",
                                         "Are you sure you want to recalculate the rotation offsets?", "Yes", "No"))
         {
             Undo.RegisterFullObjectHierarchyUndo(handBinder.gameObject, "Recalculate Offsets");
             HandBinderAutoBinder.EstimateWristRotationOffset(handBinder);
             HandBinderAutoBinder.CalculateElbowLength(handBinder);
             handBinder.SetEditorPose = true;
             handBinder.UpdateHand();
         }
     }
 }
Exemple #3
0
            /// <summary>
            /// Draw a button to allow the user to automatically bind the hand
            /// </summary>
            void DrawAutoBindButton()
            {
                if (GUILayout.Button(new GUIContent("Auto Bind", "Automatically try to search and bind the hand"), editorSkin.button, GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth), GUILayout.MinHeight(spaceSize)))
                {
                    if (EditorUtility.DisplayDialog("Auto Bind",
                                                    "Are you sure you want to discard all your changes and run the Auto Bind process?", "Yes", "No"))
                    {
                        Undo.RegisterFullObjectHierarchyUndo(handBinder, "AutoBind");
                        Undo.undoRedoPerformed += AutoRigUndo;
                        HandBinderAutoBinder.AutoBind(handBinder);
                        handBinder.UpdateHand();
                    }
                }

                GUILayout.Label(message1, editorSkin.label);
                GUILayout.Label(dividerLine);
            }
Exemple #4
0
            /// <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();
            }
Exemple #5
0
            /// <summary>
            /// Automatically assign any children of the selected transform to the hand binder for the user
            /// </summary>
            /// <param name="newT"></param>
            /// <param name="fingerID"></param>
            /// <param name="boneID"></param>
            private void AutoAssignChildrenBones(Transform newT, int fingerID, int boneID)
            {
                var firstChildList = new List <Transform>()
                {
                    newT
                };

                firstChildList = GetFirstChildren(newT, ref firstChildList);
                for (int i = 0; i < firstChildList.Count; i++)
                {
                    if (boneID + i <= 3)
                    {
                        handBinder.BoundHand.fingers[fingerID].boundBones[boneID + i] = HandBinderAutoBinder.AssignBoundBone(firstChildList[i]);
                    }
                }
            }