Beispiel #1
0
    public void AddNodeToActiveRail(float _x, float _y, float _z)
    {
        if (Track.s_instance.isOnLongNoteMode)
        {
            Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Info, "Can't add to rail in Long Mode.'");
            return;
        }
        activeRail = FindNearestRailBack();
        if (!activeRail.exists)
        {
            return;
        }
        List <Segment> segments = Track.s_instance.SegmentsList.FindAll(x => x.measure == Track.CurrentSelectedMeasure && x.note.Type == selectedNoteType);

        if (segments != null && segments.Count > 0)
        {
            Debug.Log("Existing node found!");
            return;
        }
        GameObject noteGO = GameObject.Instantiate(Track.s_instance.GetNoteMarkerByType(selectedNoteType, true));

        noteGO.transform.localPosition = new Vector3(_x, _y, _z);
        noteGO.transform.rotation      = Quaternion.identity;
        noteGO.transform.localScale   *= Track.s_instance.m_NoteSegmentMarkerRedution;
        noteGO.transform.parent        = activeRail.noteGO.transform.Find("LineArea");
        noteGO.name = activeRail.note.Id + "_Segment";
        activeRail.GetConnectedNodes();
        Track.HistoryChangeRailNode(selectedNoteType, true, Track.CurrentSelectedMeasure, new float[] { _x, _y, _z });
        Dictionary <float, List <Note> > workingTrack = Track.s_instance.GetCurrentTrackDifficulty();

        if (!workingTrack.ContainsKey(activeRail.time))
        {
            Debug.Log("Error while finding rail start.");
        }
        float[,] poses = GetLineSegementArrayPoses(activeRail.connectedNodes);

        if (workingTrack[activeRail.time][0].Type == selectedNoteType && workingTrack[activeRail.time][0].Segments != null)
        {
            workingTrack[activeRail.time][0].Segments = poses;
        }
        else
        {
            workingTrack[activeRail.time][1].Segments = poses;
        }
        var waveCustom = activeRail.noteGO.transform.Find("LineArea").GetComponentInChildren <Game_LineWaveCustom>();

        if (waveCustom)
        {
            waveCustom.targetOptional = poses;
            waveCustom.RenderLine(true, true);

            if (Track.s_instance.FullStatsContainer.activeInHierarchy)
            {
                Track.s_instance.GetCurrentStats();
            }
        }
        Track.s_instance.UpdateSegmentsList();
    }
Beispiel #2
0
    public static EditorNote NoteUnderMouse(Camera camera, LayerMask layer)
    {
        RaycastHit hit;
        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);


        if (Physics.Raycast(ray, out hit, 50f, layer))
        {
            if (!hit.transform)
            {
                return(null);
            }


            EditorNote draggableNote = new EditorNote();

            //Debug.Log("Hit note name: " + hit.transform.gameObject.name);

            //If it's a rail node segment.
            if (hit.transform.gameObject.name.EndsWith("_Segment"))
            {
                draggableNote.noteGO = hit.transform.gameObject;

                TempBeatTimeRef tempBeatTimeRef = draggableNote.noteGO.transform.parent.parent.GetComponent <TempBeatTimeRef>();

                draggableNote.note = Track.TryGetNoteFromBeatTimeType(tempBeatTimeRef.beatTime, tempBeatTimeRef.type);
                if (draggableNote.note == null)
                {
                    return(null);
                }

                draggableNote.time = tempBeatTimeRef.beatTime;

                //draggableNote.note = Track.TryGetNoteFromName(hit.transform.parent.parent.gameObject.name);
                //Debug.Log("This is a rail node");

                draggableNote.type = EditorNoteType.RailNode;

                draggableNote.startPosition = draggableNote.noteGO.transform.position;

                //We need to add it's fellow notes for future reference.
                draggableNote.GetConnectedNodes();
            }

            //Else it's a rail start or normal note
            else
            {
                draggableNote.noteGO = hit.transform.parent.gameObject;

                //draggableNote.note = Track.TryGetNoteFromName(draggableNote.noteGO.name);
                TempBeatTimeRef tempBeatTimeRef = draggableNote.noteGO.transform.GetComponent <TempBeatTimeRef>();
                draggableNote.note = Track.TryGetNoteFromBeatTimeType(tempBeatTimeRef.beatTime, tempBeatTimeRef.type);
                if (draggableNote.note == null)
                {
                    return(null);
                }

                draggableNote.time = tempBeatTimeRef.beatTime;

                draggableNote.startPosition = draggableNote.noteGO.transform.position;


                //if it's a normal note, we get the position count of the line renderer to see if it's a rail start.
                if (hit.transform.parent.GetComponentInChildren <LineRenderer>().positionCount > 0)
                {
                    draggableNote.type = EditorNoteType.RailStart;

                    //Since it's a wave start, we add the children transforms to the connected nodes list.
                    draggableNote.GetConnectedNodes();
                }

                //Else it's just a boring old note.
                else
                {
                    draggableNote.type = EditorNoteType.Standard;
                }
            }


            if (draggableNote.noteGO)
            {
                draggableNote.exists = true;
            }

            //Debug.Log(String.Format("Found note of type {0}, name {1}", draggableNote.type, draggableNote.note.name));

            return(draggableNote);
        }

        return(new EditorNote());
    }
Beispiel #3
0
    public EditorNote FindNearestRailBack()
    {
        selectedNoteType = Track.s_instance.selectedNoteType;

        EditorNote railStart = new EditorNote();

        Dictionary <float, List <Note> > workingTrack = Track.s_instance.GetCurrentTrackDifficulty();

        List <float> keys_tofilter = workingTrack.Keys.ToList();


        List <float> keysOrdered_ToFilter = keys_tofilter.OrderBy(f => f).ToList();


        int totalFilteredTime = keysOrdered_ToFilter.Count - 1;

        for (int filterList = totalFilteredTime; filterList >= 0; filterList--)
        {
            // If the time key exist, check how many notes are added
            //float targetTime = Track.GetTimeByMeasure(keysOrdered_ToFilter[filterList]);
            float targetBeat = keysOrdered_ToFilter[filterList];

            if (targetBeat > Track.CurrentSelectedMeasure)
            {
                continue;
            }

            List <Note> notes      = workingTrack[targetBeat];
            int         totalNotes = notes.Count;

            foreach (Note n in notes)
            {
                //If it's a rail start and it's the same note type as the user has selected.
                if (n.Segments != null && n.Type == selectedNoteType)
                {
                    //Debug.Log("Rail found! Note ID " + n.Id);

                    railStart.note   = n;
                    railStart.type   = EditorNoteType.RailStart;
                    railStart.noteGO = GameObject.Find(n.Id);
                    railStart.time   = targetBeat;
                    railStart.exists = true;

                    railStart.GetConnectedNodes();

                    if ((currentOriginPos.position.z - railStart.connectedNodes.Last().position.z) > distanceBackThreshold)
                    {
                        Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Info, "Nearest rail is too far back to edit.");
                        return(new EditorNote());
                    }


                    return(railStart);
                }
            }
        }


        Miku_DialogManager.ShowDialog(Miku_DialogManager.DialogType.Info, "No rails found to edit.");

        return(new EditorNote());
    }