Exemple #1
0
 private void DrawAutoRigButton()
 {
     //Draw the Auto Rig Button
     if (Selection.gameObjects.Length == 1 && GUILayout.Button("AutoRig", buttonStyle))
     {
         Undo.RegisterFullObjectHierarchyUndo(myTarget.gameObject, "AutoRig");
         HandBinderAutoRigger.AutoRig(myTarget);
         serializedObject.Update();
         SceneView.RepaintAll();
     }
     EditorGUILayout.Space();
 }
Exemple #2
0
        private void ShowFineTuningOptions()
        {
            //Draw the fine tuning options
            fineTuning.boolValue = GUILayout.Toggle(fineTuning.boolValue, !fineTuning.boolValue ? "Show Fine Tuning Options" : "Hide Fine Tuning Options", subButtonStyle);
            EditorGUILayout.Space();
            if (fineTuning.boolValue)
            {
                EditorGUILayout.Space();
                GUI.color = Color.white;
                GUILayout.BeginVertical("Box");
                EditorGUILayout.PropertyField(boundHand.FindPropertyRelative("wrist").FindPropertyRelative("offset").FindPropertyRelative("position"), new GUIContent("Wrist Position Offset"));
                EditorGUILayout.PropertyField(boundHand.FindPropertyRelative("wrist").FindPropertyRelative("offset").FindPropertyRelative("rotation"), new GUIContent("Wrist Rotation Offset"));
                EditorGUILayout.Space();
                GUI.color = previousCol;
                GUILayout.EndVertical();
                EditorGUILayout.PropertyField(globalFingerRotationOffset);
                EditorGUILayout.Space();
                if (Selection.gameObjects.Length == 1 && GUILayout.Button("Recalculate Offsets"))
                {
                    Undo.RegisterFullObjectHierarchyUndo(myTarget.gameObject, "Recalculate Offsets");
                    HandBinderAutoRigger.EstimateWristRotationOffset(myTarget);
                }
                EditorGUILayout.Space();
                GUILayout.Label(dividerLine);
                EditorGUILayout.Space();

                for (int offsetIndex = 0; offsetIndex < offsets.arraySize; offsetIndex++)
                {
                    SerializedProperty boundType         = offsets.GetArrayElementAtIndex(offsetIndex);
                    BoundTypes         previousBoundType = myTarget.offsets[offsetIndex];
                    SerializedProperty offsetProperty    = BoundTypeToOffsetProperty((BoundTypes)boundType.intValue);
                    SerializedProperty offsetRotation    = offsetProperty.FindPropertyRelative("rotation");
                    SerializedProperty offsetPosition    = offsetProperty.FindPropertyRelative("position");

                    GUILayout.BeginVertical("Box");
                    GUILayout.BeginHorizontal("Box");
                    EditorGUILayout.PropertyField(boundType, GUIContent.none);

                    if (GUILayout.Button(EditorGUIUtility.IconContent("d_Toolbar Minus")))
                    {
                        if (boundType.intValue != (int)BoundTypes.WRIST)
                        {
                            offsetRotation.vector3Value = Vector3.zero;
                            offsetPosition.vector3Value = Vector3.zero;
                        }

                        SceneView.RepaintAll();
                        offsets.DeleteArrayElementAtIndex(offsetIndex);
                        break;
                    }
                    GUILayout.EndHorizontal();

                    //Check to see if the user has changed the value
                    if ((int)previousBoundType != boundType.intValue)
                    {
                        //Check to see if any of the offsets are the same as this one
                        if (myTarget.offsets.Any(x => (int)x == boundType.intValue))
                        {
                            boundType.intValue = (int)previousBoundType;
                        }
                        else
                        {
                            offsetRotation.vector3Value = Vector3.zero;
                            offsetPosition.vector3Value = Vector3.zero;
                            offsetProperty = BoundTypeToOffsetProperty((BoundTypes)boundType.intValue);
                            offsetRotation = offsetProperty.FindPropertyRelative("rotation");
                            offsetPosition = offsetProperty.FindPropertyRelative("position");
                            SceneView.RepaintAll();
                        }
                    }

                    EditorGUILayout.PropertyField(offsetPosition);
                    EditorGUILayout.PropertyField(offsetRotation);
                    GUILayout.EndVertical();
                    EditorGUILayout.Space();
                    GUILayout.Label(dividerLine);
                    EditorGUILayout.Space();
                }

                GUILayout.BeginHorizontal("Box");
                GUILayout.Label("Add Finger Offset");
                if (GUILayout.Button(EditorGUIUtility.IconContent("d_Toolbar Plus")))
                {
                    if (offsets.arraySize < 22)
                    {
                        offsets.InsertArrayElementAtIndex(offsets.arraySize);
                        var offset = offsets.GetArrayElementAtIndex(offsets.arraySize - 1);

                        var enumList = new List <int>();

                        for (int i = 0; i < 22; i++)
                        {
                            enumList.Add(i);
                        }

                        var result = enumList.Where(typeA => myTarget.offsets.All(typeB => (int)typeB != typeA)).FirstOrDefault();

                        offset.intValue = result;
                    }
                }
                GUILayout.EndHorizontal();
                EditorGUILayout.Space();
                GUILayout.Label(dividerLine);
                EditorGUILayout.Space();
            }
        }