Пример #1
0
        public void Add(MusclePropertyName musclePropertyName, PoseTemplate srcPoseTemplate)
        {
            var handPose = new HandPoseData();

            handPose.name = srcPoseTemplate.name;
            {
                var beginMuscle = HumanTrait.MuscleFromBone((int)HumanBodyBones.LeftThumbProximal, 2);
                var endMuscle   = HumanTrait.MuscleFromBone((int)HumanBodyBones.LeftLittleDistal, 2);
                var muscleDic   = new Dictionary <string, float>();
                for (int muscle = beginMuscle; muscle <= endMuscle; muscle++)
                {
                    var index = ArrayUtility.IndexOf(srcPoseTemplate.musclePropertyNames, musclePropertyName.PropertyNames[muscle]);
                    if (index < 0)
                    {
                        continue;
                    }
                    muscleDic.Add(srcPoseTemplate.musclePropertyNames[index], srcPoseTemplate.muscleValues[index]);
                }
                handPose.musclePropertyNames = muscleDic.Keys.ToArray();
                handPose.muscleValues        = muscleDic.Values.ToArray();
            }
            if (list == null)
            {
                list = new List <HandPoseData>();
            }
            list.Add(handPose);
        }
        public void Add(PoseTemplate srcPoseTemplate)
        {
            var blendShape = new BlendShapeData();

            blendShape.name = srcPoseTemplate.name;
            {
                blendShape.blendShapePaths = new string[srcPoseTemplate.blendShapePaths.Length];
                srcPoseTemplate.blendShapePaths.CopyTo(blendShape.blendShapePaths, 0);
                blendShape.blendShapeValues = new PoseTemplate.BlendShapeData[srcPoseTemplate.blendShapeValues.Length];
                for (int i = 0; i < srcPoseTemplate.blendShapeValues.Length; i++)
                {
                    blendShape.blendShapeValues[i].names = new string[srcPoseTemplate.blendShapeValues[i].names.Length];
                    srcPoseTemplate.blendShapeValues[i].names.CopyTo(blendShape.blendShapeValues[i].names, 0);
                    blendShape.blendShapeValues[i].weights = new float[srcPoseTemplate.blendShapeValues[i].weights.Length];
                    srcPoseTemplate.blendShapeValues[i].weights.CopyTo(blendShape.blendShapeValues[i].weights, 0);
                }
            }
            if (list == null)
            {
                list = new List <BlendShapeData>();
            }
            list.Add(blendShape);
        }
Пример #3
0
        private void OnGUI()
        {
            GUIStyleReady();

            var e = Event.current;

            if (VeryAnimationWindow.instance != null && VeryAnimationWindow.instance.initialized)
            {
                EditorGUILayout.HelpBox(Language.GetText(Language.Help.ToolsWindowVAEditing), MessageType.Warning);
            }
            else
            {
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUI.BeginChangeCheck();
                        var mode = (ToolMode)EditorGUILayout.EnumPopup(toolMode);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(this, "Change Tool Mode");
                            toolMode = mode;
                        }
                    }
                    {
                        if (GUILayout.Button(uEditorGUI.GetHelpIcon(), toolsHelp ? guiStyleIconActiveButton : guiStyleIconButton, GUILayout.Width(19)))
                        {
                            Undo.RecordObject(this, "Change Tool Help");
                            toolsHelp = !toolsHelp;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUI.indentLevel++;
                if (toolsHelp)
                {
                    EditorGUILayout.HelpBox(Language.GetText(Language.Help.ToolsWindowHelpResetPose + (int)toolMode), MessageType.Info);
                }
                if (toolMode == ToolMode.ResetPose)
                {
                    #region ResetPose
#if UNITY_2018_2_OR_NEWER
                    var activePrefab = Selection.activeGameObject != null?PrefabUtility.GetCorrespondingObjectFromSource(Selection.activeGameObject) as GameObject : null;
#else
                    var activePrefab = Selection.activeGameObject != null?PrefabUtility.GetPrefabParent(Selection.activeGameObject) as GameObject : null;
#endif
                    bool disable = Selection.activeGameObject == null || activePrefab == null;
                    {
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.ObjectField("Game Object", Selection.activeGameObject, typeof(GameObject), false);
                        EditorGUI.EndDisabledGroup();
                    }
                    {
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.ObjectField("Prefab", activePrefab, typeof(GameObject), false);
                        EditorGUI.EndDisabledGroup();
                    }
                    if (activeRootObject != null)
                    {
                        var animator = activeRootObject.GetComponent <Animator>();
                        if (animator != null && !animator.hasTransformHierarchy)
                        {
                            EditorGUILayout.HelpBox("Editing on optimized transform hierarchy is not supported.\nPlease deoptimize transform hierarchy.", MessageType.Error);
                            disable = true;
                        }
                    }
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        EditorGUI.BeginDisabledGroup(disable);
                        if (GUILayout.Button("Reset Pose"))
                        {
                            ToolsResetPose(Selection.activeGameObject, activePrefab);
                        }
                        EditorGUI.EndDisabledGroup();
                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                    }
                    #endregion
                }
                else if (toolMode == ToolMode.TemplatePose)
                {
                    #region TemplatePose
                    bool     disable  = activeRootObject == null || toolPoseTemplate == null;
                    Animator animator = activeRootObject != null?activeRootObject.GetComponent <Animator>() : null;

                    Animation animation = activeRootObject != null?activeRootObject.GetComponent <Animation>() : null;

                    {
                        EditorGUI.BeginDisabledGroup(true);
                        if (animation != null)
                        {
                            EditorGUILayout.ObjectField("Animation", animation, typeof(Animation), false);
                        }
                        else
                        {
                            EditorGUILayout.ObjectField("Animator", animator, typeof(Animator), false);
                        }
                        EditorGUI.EndDisabledGroup();
                    }
                    {
                        toolPoseTemplate = EditorGUILayout.ObjectField("Template", toolPoseTemplate, typeof(PoseTemplate), false) as PoseTemplate;
                    }
                    if (activeRootObject != null)
                    {
                        if (animator != null && !animator.hasTransformHierarchy)
                        {
                            EditorGUILayout.HelpBox("Editing on optimized transform hierarchy is not supported.\nPlease deoptimize transform hierarchy.", MessageType.Error);
                            disable = true;
                        }
                        if (animator == null && animation == null)
                        {
                            EditorGUILayout.HelpBox("There is no Animator or Animation in GameObject.", MessageType.Error);
                            disable = true;
                        }
                    }
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        EditorGUI.BeginDisabledGroup(disable);
                        if (GUILayout.Button("Set Pose"))
                        {
                            ToolsTemplatePose();
                        }
                        EditorGUI.EndDisabledGroup();
                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                    }
                    #endregion
                }
                else if (toolMode == ToolMode.RemoveSaveSettings)
                {
                    #region RemoveSaveSettings
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        if (GUILayout.Button("Remove All"))
                        {
                            if (EditorUtility.DisplayDialog(Language.GetText(Language.Help.DisplayDialogAnimationRemoveSaveSettings),
                                                            Language.GetTooltip(Language.Help.DisplayDialogAnimationRemoveSaveSettings), "ok", "cancel"))
                            {
                                ToolsRemoveSaveSettings();
                            }
                        }
                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                    }
                    #endregion
                }
                else if (toolMode == ToolMode.ReplaceReference)
                {
                    #region ReplaceReference
                    {
                        EditorGUI.BeginChangeCheck();
                        var oldClip = (AnimationClip)EditorGUILayout.ObjectField("Old Animation Clip", toolReplaceReference_OldClip, typeof(AnimationClip), false);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(this, "Change Old Clip");
                            toolReplaceReference_OldClip = oldClip;
                        }
                    }
                    {
                        EditorGUI.BeginChangeCheck();
                        var newClip = (AnimationClip)EditorGUILayout.ObjectField("New Animation Clip", toolReplaceReference_NewClip, typeof(AnimationClip), false);
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(this, "Change Old Clip");
                            toolReplaceReference_NewClip = newClip;
                        }
                    }
                    {
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.Space();
                        EditorGUI.BeginDisabledGroup(toolReplaceReference_OldClip == null || toolReplaceReference_NewClip == null);
                        if (GUILayout.Button("Replace Reference"))
                        {
                            if (EditorUtility.DisplayDialog(Language.GetText(Language.Help.DisplayDialogAnimationReplaceReference),
                                                            Language.GetTooltip(Language.Help.DisplayDialogAnimationReplaceReference), "ok", "cancel"))
                            {
                                ToolsReplaceReference();
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                        EditorGUILayout.Space();
                        EditorGUILayout.EndHorizontal();
                    }
                    #endregion
                }
                EditorGUI.indentLevel--;
            }
        }