コード例 #1
0
        public bool HandleShortcuts()
        {
            bool bShiftDown = Input.GetKey(KeyCode.LeftShift);
            bool bCtrlDown  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

            // ESCAPE CLEARS ACTIVE TOOL OR SELECTION
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                if (context.ToolManager.HasActiveTool(0) || context.ToolManager.HasActiveTool(1))
                {
                    context.ToolManager.DeactivateTool(0);
                    context.ToolManager.DeactivateTool(1);
                }
                else if (context.Scene.Selected.Count > 0)
                {
                    context.Scene.ClearSelection();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.A))
            {
                if (PanelGroup != null)
                {
                    PanelGroup.SelectModulo(PanelGroup.Selected + 1);
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.S))
            {
                if (PanelGroup != null)
                {
                    PanelGroup.SelectModulo(PanelGroup.Selected - 1);
                }
                return(true);


                // CENTER TARGET (??)
            }
            else if (Input.GetKeyUp(KeyCode.C))
            {
                Ray3f     cursorRay = context.MouseController.CurrentCursorWorldRay();
                AnyRayHit hit       = null;
                if (context.Scene.FindSceneRayIntersection(cursorRay, out hit))
                {
                    context.ActiveCamera.Manipulator().ScenePanFocus(context.Scene, context.ActiveCamera, hit.hitPos, true);
                }
                return(true);

                // TOGGLE FRAME TYPE
            }
            else if (Input.GetKeyUp(KeyCode.F))
            {
                FrameType eCur = context.TransformManager.ActiveFrameType;
                context.TransformManager.ActiveFrameType = (eCur == FrameType.WorldFrame)
                    ? FrameType.LocalFrame : FrameType.WorldFrame;
                return(true);

                // DROP A COPY
            }
            else if (Input.GetKeyUp(KeyCode.D))
            {
                foreach (SceneObject so in context.Scene.Selected)
                {
                    SceneObject copy = so.Duplicate();
                    if (copy != null)
                    {
                        // [TODO] could have a lighter record here because we can just re-run Duplicate() ?
                        context.Scene.History.PushChange(
                            new AddSOChange()
                        {
                            scene = context.Scene, so = copy
                        });
                        context.Scene.History.PushInteractionCheckpoint();
                    }
                }
                return(true);

                // VISIBILITY  (V HIDES, SHIFT+V SHOWS)
            }
            else if (Input.GetKeyUp(KeyCode.V))
            {
                // show/hide (should be abstracted somehow?? instead of directly accessing GOs?)
                if (bShiftDown)
                {
                    foreach (SceneObject so in context.Scene.SceneObjects)
                    {
                        so.RootGameObject.Show();
                    }
                }
                else
                {
                    foreach (SceneObject so in context.Scene.Selected)
                    {
                        so.RootGameObject.Hide();
                    }
                    context.Scene.ClearSelection();
                }
                return(true);

                // UNDO
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Z))
            {
                context.Scene.History.InteractiveStepBack();
                return(true);

                // REDO
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Y))
            {
                context.Scene.History.InteractiveStepForward();
                return(true);

                // FILE OPEN
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.O))
            {
                var cp = new FileOpenCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);

                // FILE SAVE
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.S))
            {
                var cp = new FileSaveCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);

                // FILE IMPORT
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.I))
            {
                var cp = new FileImportCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);

                // FILE EXPORT
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.E))
            {
                var cp = new FileExportCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);


                // APPLY CURRENT TOOL IF POSSIBLE
            }
            else if (Input.GetKeyUp(KeyCode.Return))
            {
                if (((context.ActiveInputDevice & InputDevice.Mouse) != 0) &&
                    context.ToolManager.HasActiveTool(ToolSide.Right) &&
                    context.ToolManager.ActiveRightTool.CanApply)
                {
                    context.ToolManager.ActiveRightTool.Apply();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha1))
            {
                context.ToolManager.SetActiveToolType(SnapDrawPrimitivesTool.Identifier, 1);
                context.ToolManager.ActivateTool(1);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha2))
            {
                context.ToolManager.SetActiveToolType(DrawTubeTool.Identifier, 1);
                context.ToolManager.ActivateTool(1);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha3))
            {
                context.ToolManager.SetActiveToolType(DrawCurveTool.Identifier, 1);
                context.ToolManager.ActivateTool(1);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.S))
            {
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Equals))
            {
                if (Application.isEditor)
                {
                    string sName = UniqueNames.GetNext("Screenshot");
                    sName = "C:\\scratch\\" + sName + ".png";
                    ScreenCapture.CaptureScreenshot(sName, 4);
                    Debug.Log("Wrote screenshot " + sName);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }