Пример #1
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            SerializedProperty poses = serializedObject.FindProperty("poses");

            if (doBoneAdd)
            {
                int addedIndex = poses.arraySize;
                poses.InsertArrayElementAtIndex(addedIndex);
                var pose = poses.GetArrayElementAtIndex(addedIndex);
                SerializedProperty bone = pose.FindPropertyRelative("bone");
                bone.stringValue = addBoneName;
                SerializedProperty hash = pose.FindPropertyRelative("hash");
                hash.intValue = UMASkeleton.StringToHash(addBoneName);
                SerializedProperty position = pose.FindPropertyRelative("position");
                position.vector3Value = Vector3.zero;
                SerializedProperty rotation = pose.FindPropertyRelative("rotation");
                rotation.quaternionValue = Quaternion.identity;
                SerializedProperty scale = pose.FindPropertyRelative("scale");
                scale.vector3Value = Vector3.one;

                activeBoneIndex = BAD_INDEX;
                editBoneIndex   = BAD_INDEX;
                mirrorBoneIndex = BAD_INDEX;
                addBoneIndex    = 0;
                addBoneName     = "";
                doBoneAdd       = false;
            }
            if (doBoneRemove)
            {
                poses.DeleteArrayElementAtIndex(removeBoneIndex - 1);

                activeBoneIndex = BAD_INDEX;
                editBoneIndex   = BAD_INDEX;
                mirrorBoneIndex = BAD_INDEX;
                removeBoneIndex = 0;
                doBoneRemove    = false;
            }

            // HACK
            if (!dynamicDNAConverterMode)
            {
                sourceUMA = EditorGUILayout.ObjectField("Source UMA", sourceUMA, typeof(UMAData), true) as UMAData;
            }
            else
            {
                if (sourceUMA != null)
                {
                    EditorGUILayout.HelpBox("Switch to 'Scene View' and you will see gizmos to help you edit the positions of the pose bones below that you choose to 'Edit'", MessageType.Info);
                }
            }
            if (sourceUMA != null)
            {
                if (context == null)
                {
                    context = new UMABonePoseEditorContext();
                }
                if (context.activeUMA != sourceUMA)
                {
                    context.activeUMA = sourceUMA;
                }
            }


            // Weight of pose on preview model
            if (haveValidContext && !dynamicDNAConverterMode)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(addRemovePadding);
                EditorGUI.BeginDisabledGroup(haveEditTarget);
                previewWeight = EditorGUILayout.Slider(previewGUIContent, previewWeight, 0f, 1f);
                EditorGUI.EndDisabledGroup();
                GUILayout.Space(addRemovePadding);
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight / 2f);

//			string controlName = GUI.GetNameOfFocusedControl();
//			if ((controlName != null) && (controlName.Length > 0))
//				Debug.Log(controlName);

            // These can get corrupted by undo, so just rebuild them
            string[] removeBoneOptions = new string[targetPose.poses.Length + 1];
            removeBoneOptions[0] = " ";
            for (int i = 0; i < targetPose.poses.Length; i++)
            {
                removeBoneOptions[i + 1] = targetPose.poses[i].bone;
            }
            string[] addBoneOptions = new string[1];
            if (haveValidContext)
            {
                List <string> addList = new List <string>(context.boneList);
                addList.Insert(0, " ");
                for (int i = 0; i < targetPose.poses.Length; i++)
                {
                    addList.Remove(targetPose.poses[i].bone);
                }

                addBoneOptions = addList.ToArray();
            }

            // List of existing bones
            poses.isExpanded = EditorGUILayout.Foldout(poses.isExpanded, "Pose Bones (" + poses.arraySize + ")");
            if (poses.isExpanded)
            {
                for (int i = 0; i < poses.arraySize; i++)
                {
                    SerializedProperty pose = poses.GetArrayElementAtIndex(i);
                    drawBoneIndex = i;
                    PoseBoneDrawer(pose);
                }
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight);

            // Controls for adding a new bone
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(addRemovePadding);
            if (haveValidContext)
            {
                EditorGUI.BeginDisabledGroup(addBoneIndex < 1);
                if (GUILayout.Button(addBoneGUIContent, GUILayout.Width(90f)))
                {
                    addBoneName = addBoneOptions[addBoneIndex];
                    doBoneAdd   = true;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.BeginVertical();
                GUILayout.Space(buttonVerticalOffset);
                addBoneIndex = EditorGUILayout.Popup(addBoneIndex, addBoneOptions);
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUI.BeginDisabledGroup(addBoneName.Length < minBoneNameLength);
                if (GUILayout.Button(addBoneGUIContent, GUILayout.Width(90f)))
                {
                    doBoneAdd = true;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.BeginVertical();
                GUILayout.Space(buttonVerticalOffset);
                addBoneName = EditorGUILayout.TextField(addBoneName);
                EditorGUILayout.EndVertical();
            }
            GUILayout.Space(addRemovePadding);
            EditorGUILayout.EndHorizontal();

            // Controls for removing existing bone
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(addRemovePadding);
            EditorGUI.BeginDisabledGroup(removeBoneIndex < 1);
            if (GUILayout.Button(removeBoneGUIContent, GUILayout.Width(90f)))
            {
                doBoneRemove = true;
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.BeginVertical();
            GUILayout.Space(buttonVerticalOffset);
            removeBoneIndex = EditorGUILayout.Popup(removeBoneIndex, removeBoneOptions);
            EditorGUILayout.EndVertical();
            GUILayout.Space(addRemovePadding);
            EditorGUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            SerializedProperty poses = serializedObject.FindProperty("poses");

            if (doBoneAdd)
            {
                if (addBoneNames != null && addBoneNames.Count > 0)
                {
                    foreach (string s in addBoneNames)
                    {
                        AddABone(poses, s);
                    }
                }
                else if (!string.IsNullOrEmpty(addBoneName))
                {
                    AddABone(poses, addBoneName);
                }

                activeBoneIndex = BAD_INDEX;
                editBoneIndex   = BAD_INDEX;
                mirrorBoneIndex = BAD_INDEX;
                addBoneIndex    = 0;
                addBoneName     = "";
                addBoneNames.Clear();
                doBoneAdd = false;
            }
            if (doBoneRemove)
            {
                poses.DeleteArrayElementAtIndex(removeBoneIndex - 1);

                activeBoneIndex = BAD_INDEX;
                editBoneIndex   = BAD_INDEX;
                mirrorBoneIndex = BAD_INDEX;
                removeBoneIndex = 0;
                doBoneRemove    = false;
            }

            // HACK
            if (!dynamicDNAConverterMode)
            {
                EditorGUILayout.HelpBox("Select a built UMA (DynamicCharacterAvatar, DynamicAvatar, UMAData) to enable editing and addition of new bones.", MessageType.Info);
                sourceUMA   = EditorGUILayout.ObjectField("Source UMA", sourceUMA, typeof(UMAData), true) as UMAData;
                saveUMAData = sourceUMA;
            }
            else
            {
                if (sourceUMA != null)
                {
                    EditorGUILayout.HelpBox("Switch to 'Scene View' and you will see gizmos to help you edit the positions of the pose bones below that you choose to 'Edit'", MessageType.Info);
                }
            }
            if (sourceUMA != null)
            {
                if (context == null)
                {
                    context = new UMABonePoseEditorContext();
                }
                if (context.activeUMA != sourceUMA)
                {
                    context.activeUMA = sourceUMA;

                    ReloadFullTree();
                }
            }


            // Weight of pose on preview model
            if (haveValidContext && !dynamicDNAConverterMode)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(addRemovePadding);
                EditorGUI.BeginDisabledGroup(haveEditTarget);
                previewWeight = EditorGUILayout.Slider(previewGUIContent, previewWeight, 0f, 1f);
                EditorGUI.EndDisabledGroup();
                GUILayout.Space(addRemovePadding);
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight / 2f);

            // Toolbar
            GUIHelper.BeginVerticalPadded();
            MirrorAxis = EditorGUILayout.Popup("Mirror Axis", MirrorAxis, MirrorAxises);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Find UMA in scene"))
            {
                UMAData data = GameObject.FindObjectOfType <UMAData>();
                if (data != null)
                {
                    sourceUMA   = data;
                    saveUMAData = data;

                    var active = Selection.activeObject;

                    Selection.activeGameObject = data.gameObject;
                    SceneView.FrameLastActiveSceneView();

                    Selection.activeObject = active;
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Convert all Left/Right"))
            {
                for (int i = 0; i < poses.arraySize; i++)
                {
                    FlipBone(poses, i);
                }
            }
            if (GUILayout.Button("Mirror to opposite"))
            {
                // find the opposite bone.
                // Copy the parms
                // flip it with FlipBone
            }
            GUILayout.EndHorizontal();
            highlight = EditorGUILayout.TextField("Highlight bones containing: ", highlight);

            GUIHelper.EndVerticalPadded();

//			string controlName = GUI.GetNameOfFocusedControl();
//			if ((controlName != null) && (controlName.Length > 0))
//				Debug.Log(controlName);

            // These can get corrupted by undo, so just rebuild them
            string[] removeBoneOptions = new string[targetPose.poses.Length + 1];
            removeBoneOptions[0] = " ";
            for (int i = 0; i < targetPose.poses.Length; i++)
            {
                removeBoneOptions[i + 1] = targetPose.poses[i].bone;
            }
            string[] addBoneOptions = new string[1];
            if (haveValidContext)
            {
                List <string> addList = new List <string>(context.boneList);
                addList.Insert(0, " ");
                for (int i = 0; i < targetPose.poses.Length; i++)
                {
                    addList.Remove(targetPose.poses[i].bone);
                }

                addBoneOptions = addList.ToArray();
            }

            if (editBoneIndex != BAD_INDEX)
            {
                SerializedProperty editBone       = poses.GetArrayElementAtIndex(editBoneIndex);
                SerializedProperty bone           = editBone.FindPropertyRelative("bone");
                string             boneName       = bone.stringValue;
                string             mirrorBoneName = "";
                if (boneName.StartsWith("Left"))
                {
                    mirrorBoneName = boneName.Replace("Left", "Right");
                    //mirrorBoneIndex = FindMirrorBone(mirrorName);
                }
                if (boneName.StartsWith("Right"))
                {
                    mirrorBoneName = boneName.Replace("Right", "Left");
                    //mirrorBoneIndex = FindMirrorBone(mirrorName);
                }
            }

            // List of existing bones
            poses.isExpanded = EditorGUILayout.Foldout(poses.isExpanded, "Pose Bones (" + poses.arraySize + ")");
            if (poses.isExpanded)
            {
                for (int i = 0; i < poses.arraySize; i++)
                {
                    SerializedProperty pose = poses.GetArrayElementAtIndex(i);
                    drawBoneIndex = i;
                    PoseBoneDrawer(pose);
                }
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight);

            // Controls for adding a new bone
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(addRemovePadding);
            if (haveValidContext)
            {
                EditorGUI.BeginDisabledGroup(addBoneIndex < 1);
                if (GUILayout.Button(addBoneGUIContent, GUILayout.Width(90f)))
                {
                    addBoneName = addBoneOptions[addBoneIndex];
                    doBoneAdd   = true;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.BeginVertical();
                GUILayout.Space(buttonVerticalOffset);
                addBoneIndex = EditorGUILayout.Popup(addBoneIndex, addBoneOptions);
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUI.BeginDisabledGroup(addBoneName.Length < minBoneNameLength);
                if (GUILayout.Button(addBoneGUIContent, GUILayout.Width(90f)))
                {
                    doBoneAdd = true;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.BeginVertical();
                GUILayout.Space(buttonVerticalOffset);
                addBoneName = EditorGUILayout.TextField(addBoneName);
                EditorGUILayout.EndVertical();
            }
            GUILayout.Space(addRemovePadding);
            EditorGUILayout.EndHorizontal();

            // Controls for removing existing bone
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(addRemovePadding);
            EditorGUI.BeginDisabledGroup(removeBoneIndex < 1);
            if (GUILayout.Button(removeBoneGUIContent, GUILayout.Width(90f)))
            {
                doBoneRemove = true;
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.BeginVertical();
            GUILayout.Space(buttonVerticalOffset);
            removeBoneIndex = EditorGUILayout.Popup(removeBoneIndex, removeBoneOptions);
            EditorGUILayout.EndVertical();
            GUILayout.Space(addRemovePadding);
            EditorGUILayout.EndHorizontal();



            if (boneTreeView.RootNode != null)
            {
                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Expand All"))
                {
                    boneTreeView.ExpandAll();
                }
                if (GUILayout.Button("Collapse All"))
                {
                    boneTreeView.CollapseAll();
                }
                if (GUILayout.Button("Select None"))
                {
                    List <int> noselection = new List <int>();
                    boneTreeView.SetSelection(noselection);
                }
                EditorGUI.BeginDisabledGroup(!boneTreeView.HasSelection());
                if (GUILayout.Button("Add Selected"))
                {
                    addBoneNames = boneTreeView.GetSelectedBones();
                    doBoneAdd    = true;
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();

                filter = GUILayout.TextField(filter);
                if (GUILayout.Button("Filter", GUILayout.Width(80)))
                {
                    ReloadFilteredTree();
                }
                if (GUILayout.Button("Clear", GUILayout.Width(80)))
                {
                    filter = "";
                    ReloadFullTree();
                }

                EditorGUILayout.EndHorizontal();

                GUILayout.Space(10);
                string filterstate = "Bone List (No filter)";
                if (filtered)
                {
                    filterstate = "Bone List (filter=\"" + lastFilter + "\")";
                }
                EditorGUILayout.LabelField(filterstate, EditorStyles.toolbarButton);

                Rect r = GUILayoutUtility.GetLastRect();
                scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true);
                r.yMin         = 0;        //r.yMax + 60;
                r.height       = boneTreeView.totalHeight;

                GUILayout.Space(boneTreeView.totalHeight);

                boneTreeView.OnGUI(r);
                GUILayout.EndScrollView();
            }
            serializedObject.ApplyModifiedProperties();
        }