Exemplo n.º 1
0
        public override bool ApplyPreset(GameObject avatar)
        {
            if (!avatar)
            {
                return(false);
            }

            Undo.RegisterFullObjectHierarchyUndo(avatar, "Apply Pose");

            PumkinsAvatarTools.ResetPose(avatar);

            if (presetMode == PosePresetMode.HumanPose)
            {
                Animator anim = avatar.GetComponent <Animator>();
                if (anim && anim.avatar && anim.avatar.isHuman)
                {
                    Vector3    pos = avatar.transform.position;
                    Quaternion rot = avatar.transform.rotation;

                    avatar.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);

                    var humanPoseHandler = new HumanPoseHandler(anim.avatar, avatar.transform);

                    var humanPose = new HumanPose();
                    humanPoseHandler.GetHumanPose(ref humanPose);

                    humanPose.muscles = muscles;

                    if (PumkinsAvatarTools.Settings.posePresetTryFixSinking)
                    {
                        if (humanPose.bodyPosition.y < 1 && !Mathf.Approximately(humanPose.bodyPosition.y, 0))
                        {
                            PumkinsAvatarTools.Log(Strings.PoseEditor.bodyPositionYTooSmall, LogType.Warning, humanPose.bodyPosition.y.ToString());
                            humanPose.bodyPosition.y = 1;
                        }
                    }

                    if (PumkinsAvatarTools.Settings.posePresetApplyBodyPosition)
                    {
                        humanPose.bodyPosition = bodyPosition;
                    }
                    if (PumkinsAvatarTools.Settings.posePresetApplyBodyRotation)
                    {
                        humanPose.bodyRotation = bodyRotation;
                    }

                    humanPoseHandler.SetHumanPose(ref humanPose);
                    avatar.transform.SetPositionAndRotation(pos, rot);

                    PumkinsPoseEditor.OnPoseWasChanged(PumkinsPoseEditor.PoseChangeType.Reset);
                    return(true);
                }
                else
                {
                    PumkinsAvatarTools.Log(Strings.Log.cantSetPoseNonHumanoid, LogType.Error, name);
                    return(false);
                }
            }
            else
            {
                if (!avatar)
                {
                    return(false);
                }

                for (int i = 0; i < transformPaths.Count; i++)
                {
                    var t = avatar.transform.Find(transformPaths[i]);
                    if (t != null)
                    {
                        t.localEulerAngles = transformRotations[i];
                    }
                }
                return(true);
            }
        }
Exemplo n.º 2
0
        private void OnGUI()
        {
            scroll = EditorGUILayout.BeginScrollView(scroll);
            try
            {
                PumkinsPosePreset preset = (PumkinsPosePreset)CreatePresetPopupBase.preset;
                if (!preset)
                {
                    AssignOrCreatePreset <PumkinsPosePreset>(null);
                    return;
                }

                EditorGUILayout.Space();

                preset.name = EditorGUILayout.TextField(Strings.Presets.presetName, preset.name);

                Helpers.DrawGUILine();

                PumkinsAvatarTools.DrawAvatarSelectionWithButtonGUI(false, false);

                Helpers.DrawGUILine();

                preset.presetMode = (PumkinsPosePreset.PosePresetMode)EditorGUILayout.EnumPopup(Strings.Presets.poseMode, preset.presetMode);

                Helpers.DrawGUILine();

                if (GUILayout.Button(Strings.Buttons.openPoseEditor, Styles.BigButton))
                {
                    PumkinsPoseEditor.ShowWindow();
                }

                Helpers.DrawGUILine();

                EditorGUILayout.EndScrollView();

                Helpers.DrawGUILine();

                EditorGUI.BeginDisabledGroup(!PumkinsAvatarTools.SelectedAvatar || !preset || string.IsNullOrEmpty(preset.name));
                {
                    if (!editingExistingPreset)
                    {
                        _overwriteFile = GUILayout.Toggle(_overwriteFile, Strings.Presets.overwriteFile);
                        if (GUILayout.Button(Strings.Buttons.savePreset, Styles.BigButton))
                        {
                            preset.SetupPreset(preset.name, PumkinsAvatarTools.SelectedAvatar, preset.presetMode);
                            if (preset)
                            {
                                EditorApplication.delayCall += () =>
                                {
                                    preset.SavePreset(_overwriteFile);
                                    Close();
                                };
                            }
                        }
                    }
                }
                EditorGUI.EndDisabledGroup();
                CreatePresetPopupBase.preset = preset;

                EditorGUILayout.Space();
            }
            catch
            {
                EditorGUILayout.EndScrollView();
                Close();
            }
        }