예제 #1
0
        void Update()
        {
            if (keyboardInputHandler)
            {
                if (Input.GetKeyDown(key))
                {
                    var fakeTouch = new Touch();
                    fakeTouch.phase = TouchPhase.Began;
                    TriggerNote(fakeTouch);
                }
                else if (Input.GetKeyUp(key))
                {
                    if (currentNote != null)
                    {
                        currentNote.inInteraction = false;
                    }

                    OnInteractionEnd.Invoke();
                }
            }

            var touch = Input.touches.Where(x => x.fingerId == currentFingerID).FirstOrDefault();

            if (currentFingerID != -1)
            {
                if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                {
                    if (currentNote != null)
                    {
                        currentNote.inInteraction = false;
                    }

                    OnInteractionEnd.Invoke();
                }
            }

            if (currentNote || (currentNote && keyboardInputHandler))
            {
                switch (currentNote.action)
                {
                case Note.NoteAction.LongPress:
                    if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary || (keyboardInputHandler && Input.GetKey(key)))
                    {
                        if (longNoteDetecter && longNoteDetecter.exitedLineArea)
                        {
                            // print("noteFinished");

                            AddCombo(currentNote, touchDownNotePosition);

                            longNoteDetecter.OnTouchUp();
                            longNoteDetecter = null;
                            currentNote      = null;

                            sustainEffect.StopEffect();
                        }
                    }
                    else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled || (keyboardInputHandler && Input.GetKeyUp(key)))
                    {
                        if (longNoteDetecter.exitedLineArea)
                        {
                            // print("noteFinished");
                            AddCombo(currentNote, touchDownNotePosition);
                        }
                        else
                        {
                            // print("noteFailed");
                            ComboSystem.INSTANCE.BreakCombo();
                        }

                        longNoteDetecter.OnTouchUp();
                        longNoteDetecter = null;
                        currentNote      = null;

                        sustainEffect.StopEffect();
                    }
                    break;

                case Note.NoteAction.Swipe:
                    if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Ended || keyboardInputHandler)
                    {
                        if (currentNote.alreadyMissed)
                        {
                            currentNote = null;
                            return;
                        }

                        bool addCombo = false;
                        if (keyboardInputHandler)
                        {
                            switch (currentNote.swipeDirection)
                            {
                            case Note.SwipeDirection.Up:
                                addCombo = Input.GetKey(keyboardInputHandler.up);
                                break;

                            case Note.SwipeDirection.Down:
                                addCombo = Input.GetKey(keyboardInputHandler.down);
                                break;

                            case Note.SwipeDirection.Left:
                                addCombo = Input.GetKey(keyboardInputHandler.left);
                                break;

                            case Note.SwipeDirection.Right:
                                addCombo = Input.GetKey(keyboardInputHandler.right);
                                break;
                            }
                        }

                        if (!addCombo && currentFingerID != -1 && touch.phase != TouchPhase.Began)
                        {
                            var main = Camera.main;
                            var diff = main.ScreenToWorldPoint(touchDownPosition) - main.ScreenToWorldPoint(touch.position);
                            // var diff = touchDownPosition - touch.position;
                            switch (currentNote.swipeDirection)
                            {
                            case Note.SwipeDirection.Up:
                                addCombo = diff.y >= currentNote.swipeThreshold;
                                break;

                            case Note.SwipeDirection.Down:
                                addCombo = diff.y <= -currentNote.swipeThreshold;
                                break;

                            case Note.SwipeDirection.Left:
                                addCombo = diff.x >= currentNote.swipeThreshold;
                                break;

                            case Note.SwipeDirection.Right:
                                addCombo = diff.x <= -currentNote.swipeThreshold;
                                break;
                            }
                            // print(currentNote.swipeDirection + " " + diff.x + " " + addCombo + " " + touch.position + " " + touch.fingerId + " " + touch.phase);
                        }

                        if (addCombo)
                        {
                            PlayHitSound(currentNote);
                            AddCombo(currentNote, touchDownNotePosition);

                            if (effect && !currentNote.noTapEffect)
                            {
                                effect.EmitEffects(currentNote.transform);
                            }

                            KillNote(currentNote);
                            currentNote = null;
                        }
                    }
                    break;
                }
            }
        }
예제 #2
0
        void Update()
        {
            if (keyboardInputHandler)
            {
                if (Input.GetKeyDown(key))
                {
                    var fakeTouch = new Touch();
                    fakeTouch.phase = TouchPhase.Began;
                    TriggerNote(fakeTouch);
                }
                else if (Input.GetKeyUp(key))
                {
                    if (currentNote != null)
                    {
                        currentNote.inInteraction = false;
                    }

                    OnInteractionEnd.Invoke();
                }
            }

            var touch = Input.touches.Where(x => x.fingerId == currentFingerID).FirstOrDefault();

            if (currentFingerID != -1)
            {
                if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                {
                    if (currentNote != null)
                    {
                        currentNote.inInteraction = false;
                    }

                    OnInteractionEnd.Invoke();
                }
            }

            //// Handling Recording mode
            if (NoteRecorder.INSTANCE && NoteRecorder.INSTANCE.IsRecording)
            {
                Note.NoteAction     action    = Note.NoteAction.Tap;
                Note.SwipeDirection direction = Note.SwipeDirection.Left;

                bool hasDirectionKey(KeyCode key)
                {
                    return(Input.GetKey(key) || Input.GetKeyUp(key) || Input.GetKeyDown(key));
                }

                if (hasTriggeredSomething && !hasPossibleDirection)
                {
                    var diff = _camera.ScreenToWorldPoint(touchDownPosition) - _camera.ScreenToWorldPoint(touch.position);
                    if ((keyboardInputHandler && hasDirectionKey(keyboardInputHandler.left)) || diff.x >= NoteRecorder.INSTANCE.swipeThreshold)
                    {
                        possibleDirection    = Note.SwipeDirection.Left;
                        hasPossibleDirection = true;
                    }
                    else if ((keyboardInputHandler && hasDirectionKey(keyboardInputHandler.right)) || diff.x <= -NoteRecorder.INSTANCE.swipeThreshold)
                    {
                        possibleDirection    = Note.SwipeDirection.Right;
                        hasPossibleDirection = true;
                    }
                    else if ((keyboardInputHandler && hasDirectionKey(keyboardInputHandler.up)) || diff.y <= -NoteRecorder.INSTANCE.swipeThreshold)
                    {
                        possibleDirection    = Note.SwipeDirection.Up;
                        hasPossibleDirection = true;
                    }
                    else if ((keyboardInputHandler && hasDirectionKey(keyboardInputHandler.down)) || diff.y >= NoteRecorder.INSTANCE.swipeThreshold)
                    {
                        possibleDirection    = Note.SwipeDirection.Down;
                        hasPossibleDirection = true;
                    }
                }

                if ((currentFingerID != -1 && (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)) || (keyboardInputHandler && Input.GetKeyUp(key)))
                {
                    //This could be a tap, long press, or even swipe
                    var duration = songManager.songPosition - touchDownTimeInSong;

                    if (hasPossibleDirection)
                    {
                        action    = Note.NoteAction.Swipe;
                        direction = possibleDirection;
                    }

                    //The duration is long enough
                    if (duration > NoteRecorder.INSTANCE.longNoteThershold)
                    {
                        action = Note.NoteAction.LongPress;
                    }

                    hasTriggeredSomething = false;
                    hasPossibleDirection  = false;
                    currentFingerID       = -1;

                    NoteRecorder.INSTANCE.RecordNote(new NoteRecorder.NoteEventData()
                    {
                        track          = track,
                        action         = action,
                        duration       = duration,
                        startTime      = touchDownTimeInSong,
                        swipeDirection = direction,
                    });
                }
                return;
            }

            if (currentNote || (currentNote && keyboardInputHandler))
            {
                switch (currentNote.action)
                {
                case Note.NoteAction.LongPress:
                    if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary || (keyboardInputHandler && Input.GetKey(key)))
                    {
                        if (longNoteDetecter && longNoteDetecter.exitedLineArea)
                        {
                            // print("noteFinished");

                            AddCombo(currentNote, touchDownNotePosition);

                            longNoteDetecter.OnTouchUp();
                            longNoteDetecter = null;
                            currentNote      = null;

                            sustainEffect.StopEffect();
                        }
                    }
                    else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled || (keyboardInputHandler && Input.GetKeyUp(key)))
                    {
                        if (longNoteDetecter.exitedLineArea)
                        {
                            // print("noteFinished");
                            AddCombo(currentNote, touchDownNotePosition);
                        }
                        else
                        {
                            // print("noteFailed");
                            songManager.comboSystem.BreakCombo();
                        }

                        longNoteDetecter.OnTouchUp();
                        longNoteDetecter = null;
                        currentNote      = null;

                        sustainEffect.StopEffect();
                    }
                    break;

                case Note.NoteAction.Swipe:
                    if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Ended || keyboardInputHandler)
                    {
                        if (currentNote.alreadyMissed)
                        {
                            currentNote = null;
                            return;
                        }

                        bool addCombo = false;
                        if (keyboardInputHandler)
                        {
                            switch (currentNote.swipeDirection)
                            {
                            case Note.SwipeDirection.Up:
                                addCombo = Input.GetKey(keyboardInputHandler.up);
                                break;

                            case Note.SwipeDirection.Down:
                                addCombo = Input.GetKey(keyboardInputHandler.down);
                                break;

                            case Note.SwipeDirection.Left:
                                addCombo = Input.GetKey(keyboardInputHandler.left);
                                break;

                            case Note.SwipeDirection.Right:
                                addCombo = Input.GetKey(keyboardInputHandler.right);
                                break;
                            }
                        }

                        if (!addCombo && currentFingerID != -1 && touch.phase != TouchPhase.Began)
                        {
                            var diff = _camera.ScreenToWorldPoint(touchDownPosition) - _camera.ScreenToWorldPoint(touch.position);
                            // var diff = touchDownPosition - touch.position;
                            switch (currentNote.swipeDirection)
                            {
                            case Note.SwipeDirection.Up:
                                addCombo = diff.y <= -currentNote.swipeThreshold;
                                break;

                            case Note.SwipeDirection.Down:
                                addCombo = diff.y >= currentNote.swipeThreshold;
                                break;

                            case Note.SwipeDirection.Left:
                                addCombo = diff.x >= currentNote.swipeThreshold;
                                break;

                            case Note.SwipeDirection.Right:
                                addCombo = diff.x <= -currentNote.swipeThreshold;
                                break;
                            }
                            // print(currentNote.swipeDirection + " " + diff.x + " " + addCombo + " " + touch.position + " " + touch.fingerId + " " + touch.phase);
                        }

                        if (addCombo)
                        {
                            PlayHitSound(currentNote);
                            AddCombo(currentNote, touchDownNotePosition);

                            if (effect && !currentNote.noTapEffect)
                            {
                                effect.EmitEffects(currentNote.transform);
                            }

                            KillNote(currentNote);
                            currentNote = null;
                        }
                    }
                    break;
                }
            }
        }