コード例 #1
0
        public bool DragTo(Vector2 currentGUIPosition, SnappingMode snappingMode = SnappingMode.Default)
        {
            Vector3 worldPlanePosition;

            if (!GetPlaneIntersection(currentGUIPosition, out worldPlanePosition))
            {
                return(false);
            }

            var worldDelta = worldPlanePosition - this.startWorldPlanePosition;

            if ((snappingMode != SnappingMode.Always) && worldDelta.sqrMagnitude == 0)
            {
                return(false);
            }

            this.worldSlidePosition = this.worldSlideOrigin + worldDelta;
            var newWorldPosition = (snappingMode == SnappingMode.Never) ? worldSlidePosition :
                                   this.worldSlideGrid.SnapExtents3D(this.gridSlideExtents, this.worldSlidePosition, this.worldSlideOrigin, out this.snapResult);

            // this doesn't make sense since we're locking axis in world space, but should be grid space, which we're already doing in SnapExtents3D?
            //newWorldPosition = SnappingUtility.PerformAxisLocking(this.worldSlideOrigin, newWorldPosition);

            if ((snappingMode != SnappingMode.Always) && (this.worldSnappedPosition - newWorldPosition).sqrMagnitude == 0)
            {
                return(false);
            }

            this.worldSnappedPosition = newWorldPosition;
            return(true);
        }
コード例 #2
0
ファイル: EditorInput.cs プロジェクト: Mettra/NotReaper
        public void SelectSnappingMode(SnappingMode mode)
        {
            if (selectedSnappingMode == mode)
            {
                return;
            }

            selectedSnappingMode = mode;

            switch (mode)
            {
            case SnappingMode.Grid:
                normalGrid.SetActive(true);
                noGrid.SetActive(false);
                meleeGrid.SetActive(false);
                break;

            case SnappingMode.None:
                normalGrid.SetActive(false);
                noGrid.SetActive(true);
                meleeGrid.SetActive(false);
                break;

            case SnappingMode.Melee:
                normalGrid.SetActive(false);
                noGrid.SetActive(true);
                meleeGrid.SetActive(true);
                break;
            }
        }
コード例 #3
0
ファイル: NoteGridSnap.cs プロジェクト: Mettra/NotReaper
        public static Vector3 SnapToGrid(Vector3 pos, SnappingMode mode)
        {
            switch (mode)
            {
            case SnappingMode.Grid:
            case SnappingMode.DetailGrid:
                return(GetNearestPointOnGrid(pos, mode));

            case SnappingMode.Melee:

                float x;
                float y;

                if (pos.x < 0)
                {
                    x = NotePosCalc.xSize * -2;
                }
                else
                {
                    x = NotePosCalc.xSize * 2;
                }

                if (pos.y < 0)
                {
                    y = NotePosCalc.ySize * -1;
                }
                else
                {
                    y = NotePosCalc.ySize * 1;
                }

                return(new Vector3(x, y, pos.z + 5));
            }
            return(new Vector3(pos.x, pos.y, pos.z + 5));
        }
コード例 #4
0
        public static Vector3 SnapToGrid(Vector3 pos, SnappingMode mode)
        {
            switch (mode)
            {
            case SnappingMode.Grid:
            case SnappingMode.DetailGrid:
                return(GetNearestPointOnGrid(pos, mode));

            case SnappingMode.Melee:
                return(new Vector3(Mathf.Sign(pos.x * NotePosCalc.xSize) * 2, Mathf.Sign(pos.y * NotePosCalc.ySize), pos.z + 5));
            }
            return(new Vector3(pos.x, pos.y, pos.z + 5));
        }
コード例 #5
0
        private static Vector2 GetNearestPointOnGrid(Vector2 pos, SnappingMode mode)
        {
            //pos -= gridOffset; //Enable if grid is actually offset.
            pos.y += 0.45f;
            int x = Mathf.FloorToInt(pos.x / NotePosCalc.xSize);
            int y = Mathf.FloorToInt(pos.y / NotePosCalc.ySize);

            Vector2 result = new Vector2((float)x * NotePosCalc.xSize, (float)y * NotePosCalc.ySize);

            result.x += NotePosCalc.xSize / 2; //0.65f; //from 1.3 / 2

            //result += gridOffset; //Enable if grid is actually offset.

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Returns starttime for this navigatable. Taking snapping into account
        /// </summary>
        /// <param name="timeNavigatable"></param>
        /// <param name="mode">Custom snapping mode to use</param>
        /// <param name="start">Start time of selected range</param>
        /// <param name="end">End time of selected range</param>
        /// <returns>Start time to send to navigatable. This might be a snapped value of <para>start</para></returns>
        public static DateTime GetStartTime(ITimeNavigatable timeNavigatable, SnappingMode mode, DateTime start, DateTime? end)
        {
            //No snapping is easy
            if (mode == SnappingMode.None)
            {
                return start;
            }

            IEnumerable<DateTime> dateTimes = timeNavigatable.Times;

            DateTime? startTime;

            if (mode == SnappingMode.Interval)
            {
                startTime = GetFirstTimeLeftOfValue(dateTimes, start);
            }
            else
            {
                startTime = GetFirstTimeInRange(dateTimes, start, end);
            }
            return startTime != null ? startTime.Value : GetNearestDefinedTime(dateTimes, start);
        }
コード例 #7
0
        /// <summary>
        /// Returns starttime for this navigatable. Taking snapping into account
        /// </summary>
        /// <param name="timeNavigatable"></param>
        /// <param name="mode">Custom snapping mode to use</param>
        /// <param name="start">Start time of selected range</param>
        /// <param name="end">End time of selected range</param>
        /// <returns>Start time to send to navigatable. This might be a snapped value of <para>start</para></returns>
        public static DateTime GetStartTime(ITimeNavigatable timeNavigatable, SnappingMode mode, DateTime start, DateTime?end)
        {
            //No snapping is easy
            if (mode == SnappingMode.None)
            {
                return(start);
            }

            IEnumerable <DateTime> dateTimes = timeNavigatable.Times;

            DateTime?startTime;

            if (mode == SnappingMode.Interval)
            {
                startTime = GetFirstTimeLeftOfValue(dateTimes, start);
            }
            else
            {
                startTime = GetFirstTimeInRange(dateTimes, start, end);
            }
            return(startTime != null ? startTime.Value : GetNearestDefinedTime(dateTimes, start));
        }
コード例 #8
0
ファイル: EditorInput.cs プロジェクト: CircuitLord/NotReaper
        public void SelectSnappingMode(SnappingMode mode)
        {
            if (selectedSnappingMode == mode)
            {
                return;
            }

            selectedSnappingMode = mode;

            switch (mode)
            {
            case SnappingMode.Grid:
                normalGrid.SetActive(true);

                normalGrid.GetComponent <SpriteRenderer>().color = Color.white;

                noGrid.SetActive(false);
                meleeGrid.SetActive(false);
                break;

            case SnappingMode.None:
                normalGrid.SetActive(true);
                normalGrid.GetComponent <SpriteRenderer>().color = normalGridDisabledColor;


                noGrid.SetActive(false);
                meleeGrid.SetActive(false);
                break;

            case SnappingMode.Melee:
                normalGrid.SetActive(false);
                noGrid.SetActive(true);
                meleeGrid.SetActive(true);
                break;
            }
        }
コード例 #9
0
ファイル: EditorInput.cs プロジェクト: Mettra/NotReaper
        private void Update()
        {
            if (Timeline.inTimingMode && inUI)
            {
                if (Input.GetKeyDown(InputManager.timelineTogglePlay))
                {
                    timeline.TogglePlayback();
                }
            }

            if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.S))
            {
                timeline.Export();
            }

            if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.C))
            {
                timeline.CopyTimestampToClipboard();
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (pauseMenu.isOpened)
                {
                    if (!Timeline.audioLoaded)
                    {
                        return;
                    }

                    pauseMenu.ClosePauseMenu();
                }
                else
                {
                    if (selectedMode == EditorMode.Timing)
                    {
                        return;
                    }

                    if (bpmWindow.activeSelf)
                    {
                        bpmWindow.GetComponent <DynamicBPMWindow>().Deactivate();
                    }
                    else
                    {
                        pauseMenu.OpenPauseMenu();
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.B))
            {
                if (bpmWindow.activeSelf)
                {
                    bpmWindow.GetComponent <DynamicBPMWindow>().Deactivate();
                }
                else if (!inUI)
                {
                    bpmWindow.GetComponent <DynamicBPMWindow>().Activate();
                }
            }

            bool wasInUI = inUI;

            FigureOutIsInUI();

            if (wasInUI || inUI)
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.F1))
            {
                shortcutMenu.show();
            }

            if (Input.GetKeyUp(KeyCode.F1))
            {
                shortcutMenu.hide();
            }

            if (Input.GetKeyDown(KeyCode.LeftControl) || Input.GetKeyDown(KeyCode.RightControl))
            {
                SelectTool(EditorTool.DragSelect);
                previousSnappingMode = selectedSnappingMode;
            }
            if (Input.GetKeyUp(KeyCode.LeftControl) || Input.GetKeyUp(KeyCode.RightControl))
            {
                Tools.dragSelect.EndAllDragStuff();
                RevertTool();
                SelectSnappingMode(previousSnappingMode);
            }

            if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
            {
                previousSnappingMode = selectedSnappingMode;
                switch (selectedSnappingMode)
                {
                case SnappingMode.Grid:
                case SnappingMode.Melee:
                    SelectSnappingMode(SnappingMode.None);
                    break;

                case SnappingMode.None:
                    SelectSnappingMode(selectedTool == EditorTool.Melee ? SnappingMode.Melee : SnappingMode.Grid);
                    break;
                }
            }
            if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift))
            {
                if (selectedSnappingMode != previousSnappingMode)
                {
                    SelectSnappingMode(previousSnappingMode);
                }
            }

            if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
            {
                isCTRLDown = true;
            }
            else
            {
                isCTRLDown = false;
            }

            if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
            {
                isShiftDown = true;
            }
            else
            {
                isShiftDown = false;
            }


            if (Input.GetKeyDown(KeyCode.T))
            {
                //Tools.chainBuilder.NewChain(new Vector2(0, 0));
            }


            if (Input.GetMouseButtonDown(0))
            {
                switch (selectedTool)
                {
                case EditorTool.Standard:
                case EditorTool.Hold:
                case EditorTool.Horizontal:
                case EditorTool.Vertical:
                case EditorTool.ChainStart:
                case EditorTool.ChainNode:
                case EditorTool.Melee:
                    Tools.placeNote.TryPlaceNote();
                    break;

                case EditorTool.ChainBuilder:
                    //We let the chain builder script handle input since we activated it from SelectTool()
                    break;


                default:
                    break;
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                switch (selectedTool)
                {
                case EditorTool.Standard:
                case EditorTool.Hold:
                case EditorTool.Horizontal:
                case EditorTool.Vertical:
                case EditorTool.ChainStart:
                case EditorTool.ChainNode:
                case EditorTool.Melee:
                    Tools.placeNote.TryRemoveNote();
                    break;


                default:
                    break;
                }
            }


            if (Input.GetKeyDown(InputManager.timelineTogglePlay))
            {
                timeline.TogglePlayback();
            }


            if (Input.GetKeyDown(InputManager.selectStandard))
            {
                SelectTool(EditorTool.Standard);
            }
            if (Input.GetKeyDown(InputManager.selectHold))
            {
                SelectTool(EditorTool.Hold);
            }
            if (Input.GetKeyDown(InputManager.selectHorz))
            {
                SelectTool(EditorTool.Horizontal);
            }
            if (Input.GetKeyDown(InputManager.selectVert))
            {
                SelectTool(EditorTool.Vertical);
            }
            if (Input.GetKeyDown(InputManager.selectChainStart))
            {
                SelectTool(EditorTool.ChainStart);
            }
            if (Input.GetKeyDown(InputManager.selectChainNode))
            {
                SelectTool(EditorTool.ChainNode);
            }
            if (Input.GetKeyDown(InputManager.selectMelee))
            {
                SelectTool(EditorTool.Melee);
            }

            //Toggles the chain builder state
            if (Input.GetKeyDown(KeyCode.H))
            {
                if (Tools.chainBuilder.activated)
                {
                    Tools.chainBuilder.Activate(false);
                    RevertTool();
                }
                else
                {
                    SelectTool(EditorTool.ChainBuilder);
                }
            }

            if (Input.GetKeyDown(KeyCode.V) && !isCTRLDown)
            {
                SelectTool(EditorTool.DragSelect);
            }

            if (Input.GetKeyDown(KeyCode.G))
            {
                SelectSnappingMode(SnappingMode.Grid);
            }
            if (Input.GetKeyDown(KeyCode.N))
            {
                SelectSnappingMode(SnappingMode.None);
            }
            if (Input.GetKeyDown(KeyCode.M))
            {
                SelectSnappingMode(SnappingMode.Melee);
            }


            if (Input.GetKeyDown(InputManager.toggleColor))
            {
                if (selectedHand == TargetHandType.Left)
                {
                    SelectHand(TargetHandType.Right);
                }
                else if (selectedHand == TargetHandType.Right)
                {
                    SelectHand(TargetHandType.Left);
                }
                else
                {
                    SelectHand(TargetHandType.Left);
                }
            }

            if (Input.GetKeyDown(InputManager.selectSoundKick))
            {
                soundDropdown.value = 0;
            }
            else if (Input.GetKeyDown(InputManager.selectSoundSnare))
            {
                soundDropdown.value = 1;
            }
            else if (Input.GetKeyDown(InputManager.selectSoundPercussion))
            {
                soundDropdown.value = 2;
            }
            else if (Input.GetKeyDown(InputManager.selectSoundChainStart))
            {
                soundDropdown.value = 3;
            }
            else if (Input.GetKeyDown(InputManager.selectSoundChainNode))
            {
                soundDropdown.value = 4;
            }
            else if (Input.GetKeyDown(InputManager.selectSoundMelee))
            {
                soundDropdown.value = 5;
            }


            if (!isShiftDown && isCTRLDown && Input.GetKeyDown(InputManager.undo))
            {
                Tools.undoRedoManager.Undo();
                Debug.Log("Undoing...");
            }

            if (isShiftDown && isCTRLDown && Input.GetKeyDown(InputManager.redo))
            {
                Tools.undoRedoManager.Redo();
                Debug.Log("Redoing...");
            }
        }
コード例 #10
0
 public void SetSnappingMode(SnappingMode snappingMode)
 {
     snapMode = snappingMode;
     meleeGrid.SetActive(snapMode == SnappingMode.Melee);
     standardGrid.SetActive(snapMode == SnappingMode.Grid);
 }