예제 #1
0
    public MeasureSeperator FindClosestOffsetFromPoint(Vector3 hitPoint)
    {
        int closestIndex = activeSeperators.FindIndex(s => s.timestamp == closestSeperator.timestamp);
        MeasureSeperator rtnSeperator = null;
        float            lastDistance = float.MaxValue;
        float            distance     = 0;

        for (int i = closestIndex; i < activeSeperators.Count; i++)
        {
            if (!activeSeperators[i].gameObject.activeInHierarchy)
            {
                continue;
            }

            distance = Vector3.Distance(hitPoint, activeSeperators[i].transform.position);

            if (distance < lastDistance)
            {
                lastDistance = distance;
                rtnSeperator = activeSeperators[i];
            }

            else
            {
                break;
            }
        }

        return(rtnSeperator);
    }
예제 #2
0
    private void Update()
    {
        // Add a new measure seperator if needed.
        if (EditorConductor.instance.source.isPlaying && activeSeperators.Count > 0)
        {
            MeasureSeperator final = activeSeperators[activeSeperators.Count - 1];

            if (final.timestamp < EditorConductor.instance.songPosition + (EditorConductor.instance.spb * NoteHelper.Whole * 2f))
            {
                int beat = (final.beatSegment + 1) % 4;
                MeasureSeperatorType type        = GetMeasureSeperatorTypeFromBeat(beat);
                MeasureSeperator     newInstance = SpawnSeperator(final.timestamp + EditorConductor.instance.spb * NoteHelper.Sixteenth, type, beat);
                activeSeperators.Add(newInstance);
            }
        }
    }
예제 #3
0
    // Mouse Up event
    public void SetNote(int endPath, Vector3 point)
    {
        Debug.Log("Call Set Note");

        if (selectedNote == null)
        {
            return;
        }

        // Set the Hold Note length based on the mouse up
        if (selectedNoteType == NoteType.Hold || selectedNoteType == NoteType.Transition)
        {
            EditorNoteHold   temp      = selectedNote as EditorNoteHold;
            MeasureSeperator seperator = MeasureSeperatorManager.instance.FindClosestOffsetFromPoint(point);
            int   difference           = Mathf.RoundToInt(((seperator.timestamp - temp.offset) / EditorConductor.instance.spb) * 4f);
            float length = difference / 4f;
            temp.SetLength(length);
        }


        // Set the end path for flick note
        else if (selectedNoteType == NoteType.Flick)
        {
            if (Mathf.Abs(selectedNote.notePathId - endPath) != 1)
            {
                Debug.Log("Start: " + selectedNote.notePathId + ", End: " + endPath + ", Removing");
                RemoveNote(selectedNote);
                selectedNote = null;
                return;
            }
            EditorNoteFlick temp = selectedNote as EditorNoteFlick;
            temp.SetNote(endPath);
        }

        // Set the End locations and length for drag note
        else if (selectedNoteType == NoteType.Drag)
        {
            EditorNoteDrag   temp      = selectedNote as EditorNoteDrag;
            MeasureSeperator seperator = MeasureSeperatorManager.instance.FindClosestOffsetFromPoint(point);
            int   difference           = Mathf.RoundToInt(((seperator.timestamp - temp.offset) / EditorConductor.instance.spb) * 4f);
            float length = difference / 4f;
            temp.SetNote(length, endPath);
        }

        selectedNote = null;
    }
예제 #4
0
    public void ScrollForward()
    {
        float songPosition = EditorConductor.instance.songPosition;

        int  index            = 0;
        bool spawnNewInstance = false;

        for (index = 0; index < activeSeperators.Count; index++)
        {
            if (activeSeperators[index].timestamp < songPosition + 0.05f)
            {
                continue;
            }

            // Else, Set the the spong position and the closestSeperator var- to the current Seperator, an
            else
            {
                EditorConductor.instance.SetSongPosition(activeSeperators[index].timestamp);
                spawnNewInstance = true;

                if (activeSeperators[index].gameObject.activeInHierarchy)
                {
                    activeSeperators[index].SetClosest();
                }

                break;
            }
        }

        // Spawn New Instance and Destory the first instance
        if (spawnNewInstance)
        {
            MeasureSeperator finalInstance = activeSeperators[activeSeperators.Count - 1];
            int beat = (finalInstance.beatSegment + 1) % 4;
            MeasureSeperatorType type        = GetMeasureSeperatorTypeFromBeat(beat);
            MeasureSeperator     newInstance = SpawnSeperator(finalInstance.timestamp + EditorConductor.instance.spb * NoteHelper.Sixteenth, type, beat);
            activeSeperators.Add(newInstance);
        }

        foreach (MeasureSeperator seperator in activeSeperators)
        {
            seperator.UpdateSeperatorPosition();
        }
    }
예제 #5
0
    // Remove note given a mouse Click;
    public void RemoveNote(int notePathId, Vector3 point)
    {
        // Get the closest Measure to the click, so we can determine at which note to remove
        MeasureSeperator seperator = MeasureSeperatorManager.instance.FindClosestOffsetFromPoint(point);

        for (int i = 0; i < Notes.Count; i++)
        {
            // Debug.Log("Seperator: " + seperator.timestamp + ", Note offset: " + Notes[i].offset);
            // Need to round float to 3 decimal points tho.
            if (Mathf.Abs((seperator.timestamp - Notes[i].offset)) < 0.01f && notePathId == Notes[i].notePathId)
            {
                Destroy(Notes[i].gameObject);
                Notes.RemoveAt(i);
                return;
            }
        }

        Debug.Log("Note note found");
    }
예제 #6
0
    public void InitializeSeperators()
    {
        float currentSongPos = EditorConductor.instance.offset;

        while (currentSongPos < EditorConductor.instance.offset * NoteHelper.Whole * 2f)
        {
            if (currentSongPos < 0)
            {
                currentSongPos += EditorConductor.instance.spb * NoteHelper.Sixteenth;
                continue;
            }

            MeasureSeperatorType spawnType = GetMeasureSeperatorTypeFromBeat(selectedBeat);
            MeasureSeperator     seperator = SpawnSeperator(currentSongPos, spawnType, selectedBeat);

            activeSeperators.Add(seperator);

            selectedBeat    = (selectedBeat + 1) % 4;
            currentSongPos += EditorConductor.instance.spb * NoteHelper.Sixteenth;
        }
    }
예제 #7
0
    // notePath to place the note, and the position in world space where the
    // notepath was clicked.
    // Mouse Down Event
    public void PlaceNote(int notePathId, Vector3 point, float length = 1f, int endPath = -1)
    {
        // Get the closest Measure to the click, so we can snap notes to the measure.
        MeasureSeperator seperator = MeasureSeperatorManager.instance.FindClosestOffsetFromPoint(point);

        foreach (EditorNoteBase note in Notes)
        {
            if (seperator.timestamp == note.offset && notePathId == note.notePathId)
            {
                Debug.Log("There is already a note in this position, returning");
                return;
            }
        }

        switch (selectedNoteType)
        {
        case NoteType.Regular:
            selectedNote = SpawnRegularNote(seperator.timestamp, notePathId);
            break;

        case NoteType.Hold:
            selectedNote = SpawnHoldNote(seperator.timestamp, notePathId, length, false);
            break;

        case NoteType.Transition:
            selectedNote = SpawnHoldNote(seperator.timestamp, notePathId, length, true);
            break;

        case NoteType.Flick:
            selectedNote = SpawnFlickNote(seperator.timestamp, notePathId, endPath);
            break;

        case NoteType.Drag:
            selectedNote = SpawnDragNote(seperator.timestamp, notePathId, length, selectedNoteDragType, notePathId);
            break;
        }
    }
예제 #8
0
    public void ScrollBackward()
    {
        float            songPosition = EditorConductor.instance.songPosition;
        MeasureSeperator lastInstance = null;

        int index = 0;

        for (index = 0; index < activeSeperators.Count; index++)
        {
            if (activeSeperators[index].timestamp < songPosition - 0.05f)
            {
                lastInstance = activeSeperators[index];
                continue;
            }

            else
            {
                break;
            }
        }

        if (lastInstance != null)
        {
            EditorConductor.instance.SetSongPosition(lastInstance.timestamp);
            if (lastInstance.gameObject.activeInHierarchy)
            {
                lastInstance.SetClosest();
                lastInstance.ResetHitSound();
            }
        }

        foreach (MeasureSeperator seperator in activeSeperators)
        {
            seperator.UpdateSeperatorPosition();
        }
    }