Beispiel #1
0
    public static bool HotkeyButton(GUIContent guiContent, NPVoxHotkey hotkey = null, bool showKey = true, bool bold = false, bool hotcontrolCheck = false, GUIStyle style = null)
    {
        Event e       = Event.current;
        bool  focusOK = EditorGUIUtility.keyboardControl == 0 && (!hotcontrolCheck || GUIUtility.hotControl == 0);

        guiContent.text = guiContent.text + (showKey && hotkey != null ? " (" + hotkey + ")" : "");
        style           = style == null ? GUI.skin.button : style;
        if (bold)
        {
            style.fontStyle = FontStyle.Bold;
        }
        if (GUILayout.Button(guiContent, style) || (focusOK && hotkey != null && hotkey.IsDown(e)))
        {
            e.Use();
            EditorWindow.focusedWindow.Repaint();
            return(true);
        }
        return(false);
    }
Beispiel #2
0
    private void KeyboardShortcuts()
    {
        if (Tools.current != Tool.None)
        {
            if (viewModel.UpdateCurrentToolFromSceneView(Tools.current))
            {
            }
        }

        Event e = Event.current;

        if (e.type == EventType.keyDown && e.isKey)
        {
            if (viewModel.SelectedTransformer == null)
            {
                // Start Editing Transformation
                if (HOTKEY_EDIT_LAST_TRANSFOMRATION.IsDown(e))
                {
                    if (viewModel.Transformers != null && viewModel.Transformers.Length > 0)
                    {
                        e.Use();
                        viewModel.SelectTransformation(viewModel.Transformers.Length - 1);
                    }
                }
            }
            else
            {
                // Maximize Affected Area
                if (HOTKEY_AFFECTED_AREA_SELECT_ALL.IsDown(e))
                {
                    e.Use();
                    viewModel.MaximizeAffectedArea();
                }
                // Reset current Editing Transformation
                if (HOTKEY_RESET_SELECTED_TRANSFORMATION.IsDown(e))
                {
                    e.Use();
                    viewModel.ResetTransformation();
                }

                // Stop Editing Transformation
                if (HOTKEY_EDIT_LAST_TRANSFOMRATION.IsDown(e) && !e.alt)
                {
                    e.Use();
                    viewModel.SelectTransformation(-1);
                    unfocus();
                }

                // Select Pivot Tool
                if (e.keyCode == KeyCode.D)
                {
                    e.Use();
                    viewModel.SetCurrentTool(NPVoxAnimationEditorVM.Tool.CUSTOM4);
                }

                // move selected up
                if (HOTKEY_MOVE_TRANSFORMATION_UP.IsDown(e))
                {
                    e.Use();
                    viewModel.MoveTransformation(viewModel.SelectedTransformationIndex, -1);
                }

                // move selected down
                if (HOTKEY_MOVE_TRANSFORMATION_DOWN.IsDown(e))
                {
                    e.Use();
                    viewModel.MoveTransformation(viewModel.SelectedTransformationIndex, +1);
                }
            }

            // Add new Transformation
            if (HOTKEY_APPEND_TRANSFORMATION.IsDown(e))
            {
                e.Use();
                viewModel.AddTransformation();
            }

            // Add new Transformation
            if (HOTKEY_APPEND_BONETRANSFORMATION.IsDown(e))
            {
                e.Use();
                viewModel.AddSkeletonTransformer();
            }

            // Delete Transformation
            if (HOTKEY_DELETE_LAST_TRANSFOMRATION.IsDown(e))
            {
                if (viewModel.SelectedTransformationIndex >= 0)
                {
                    e.Use();
                    viewModel.RemoveTransformationAt(viewModel.SelectedTransformationIndex);
                }
                else if (viewModel.Transformers.Length > 0)
                {
                    e.Use();
                    viewModel.RemoveTransformationAt(viewModel.Transformers.Length - 1);
                }
            }

            if (HOTKEY_PREVIOUS_FRAME.IsDown(e))
            {
                e.Use();
                viewModel.SelectFrame(viewModel.GetPreviousFrameIndex());
            }

            if (HOTKEY_NEXT_FRAME.IsDown(e))
            {
                e.Use();
                viewModel.SelectFrame(viewModel.GetNextFrameIndex());
            }

            if (HOTKEY_PREVIOUS_TRANSFORMATION.IsDown(e))
            {
                e.Use();
                viewModel.SelectTransformation(viewModel.GetPreviousTransformationIndex());
            }

            if (HOTKEY_NEXT_TRANSFORMATION.IsDown(e))
            {
                e.Use();
                viewModel.SelectTransformation(viewModel.GetNextTransformationIndex());
            }

            if (HOTKEY_HIDE_SELECTED_BONES.IsDown(e))
            {
                e.Use();
                viewModel.ApplyHiddenBoneMask();
            }

            for (int i = 0; i < HOTKEYS_SELECT_FRAME.Length; i++)
            {
                if (HOTKEYS_SELECT_FRAME[i].IsDown(e))
                {
                    e.Use();
                    viewModel.SelectFrame(i);
                    unfocus();
                }
            }


            for (int i = 0; i < HOTKEYS_SELECT_TRANSFORMATION.Length; i++)
            {
                if (HOTKEYS_SELECT_TRANSFORMATION[i].IsDown(e))
                {
                    e.Use();
                    if (viewModel.SelectedTransformationIndex == i)
                    {
                        unfocus();
                        viewModel.SelectTransformation(-1);
                    }
                    else
                    {
                        viewModel.SelectTransformation(i);
                    }
                }
            }

            // preview
            if (HOTKEY_PREVIEW.IsDown(e))
            {
                e.Use();
                if (viewModel.IsPlaying)
                {
                    viewModel.StopPreview();
                }
                else
                {
                    Preview();
                }
            }
        }
    }