예제 #1
0
    public void RemoveNodeFromActiveRail(EditorNote _note)
    {
        EditorNote note = _note;

        if (note == null || note.noteGO == null || (note.exists && note.type != EditorNoteType.RailNode))
        {
            return;
        }
        Game_LineWaveCustom waveCustom = note.noteGO.transform.parent.GetComponentInChildren <Game_LineWaveCustom>();

        if (note.connectedNodes.Count == 1)
        {
            // If this is the only node on the rail, record the before and after states of the parent note instead of the node to avoid errors during Undo; also delete and replace parent note to reset rail line.
            Note.NoteType selectedNoteTypeBackup = Track.s_instance.selectedNoteType;
            Track.s_instance.selectedNoteType = note.note.Type;
            activeRail = FindNearestRailBack();
            if (!activeRail.exists)
            {
                Debug.Log("No active rail found!");
                return;
            }
            Track.s_instance.selectedNoteType = selectedNoteTypeBackup;
            Track.HistoryChangeRailNodeParent(activeRail.note.Type, activeRail.time, new float[] { activeRail.note.Position[0], activeRail.note.Position[1], activeRail.note.Position[2] }, activeRail.note.Segments, new float[, ] {
            });
            note.connectedNodes.Remove(note.noteGO.transform);
            DestroyImmediate(note.noteGO);
            //DestroyImmediate(activeRail.noteGO.transform.Find("LineArea"));
            //DestroyImmediate(waveCustom);
            note.note.Segments = new float [, ] {
            };
            bool changingHistoryBackup = History.changingHistory;
            History.changingHistory = true;
            float         savedBeat     = activeRail.time;
            float[]       savedPosition = new float[] { activeRail.note.Position[0], activeRail.note.Position[1], activeRail.note.Position[2] };
            Note.NoteType savedType     = activeRail.note.Type;
            Track.DeleteIndividualNote(activeRail);
            Track.AddIndividualNote(savedBeat, savedPosition, savedType, new float [, ] {
            });
            History.changingHistory = changingHistoryBackup;
        }
        else
        {
            //Track.HistoryChangeRailNode(note.note.Type, false, Mathf.RoundToInt(3f*Track.s_instance.GetBeatMeasureByUnit(note.noteGO.transform.position.z))/3f, new float[] {note.noteGO.transform.position.x, note.noteGO.transform.position.y, note.noteGO.transform.position.z});
            Track.HistoryChangeRailNode(note.note.Type, false, Track.s_instance.RoundToThird(Track.s_instance.GetBeatMeasureByUnit(note.noteGO.transform.position.z)), new float[] { note.noteGO.transform.position.x, note.noteGO.transform.position.y, note.noteGO.transform.position.z });
            note.connectedNodes.Remove(note.noteGO.transform);
            DestroyImmediate(note.noteGO);
            if (waveCustom)
            {
                var segments = GetLineSegementArrayPoses(note.connectedNodes);
                //Update the actual values in the note.
                note.note.Segments        = segments;
                waveCustom.targetOptional = segments;
                waveCustom.RenderLine(true, true);
            }
        }
        Track.s_instance.UpdateSegmentsList();
        if (Track.s_instance.FullStatsContainer.activeInHierarchy)
        {
            Track.s_instance.GetCurrentStats();
        }
    }