コード例 #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();
    }
コード例 #2
0
ファイル: NoteToolState.cs プロジェクト: maxrchung/S2VX
        public override bool OnToolClick(ClickEvent e)
        {
            var note = new EditorNote {
                Coordinates = Editor.MousePosition,
                HitTime     = Time.Current
            };

            Editor.Reversibles.Push(new ReversibleAddNote(Story, note, Editor));
            return(false);
        }
コード例 #3
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            // In case there is no description focus the Edit
            if (string.IsNullOrWhiteSpace(ViewModel.Description) && !ViewModel.IsReadonly)
            {
                EditorNote.Focus();
            }
        }
コード例 #4
0
    /*private void OnEnable()
     * {
     *      if (true) {
     *              UnityEditorInternal.ComponentUtility.MoveComponentUp((EditorNote)target);
     *      }
     * }*/

    public override void OnInspectorGUI()
    {
        if (!init)
        {
            init    = true;
            _target = (EditorNote)target;
            SetTexture(200, 200, Color.red);
        }
        DrawLine();
        GUILayout.BeginVertical();
        _target.text = GUILayout.TextArea(_target.text, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true), GUILayout.MaxHeight(72f));
        GUILayout.EndVertical();
        DrawLine();


        GUILayout.BeginHorizontal(t, null, GUILayout.ExpandHeight(true));
        _target.text = GUILayout.TextArea(_target.text, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true), GUILayout.MaxHeight(72f));
        GUILayout.EndHorizontal();
    }
コード例 #5
0
 public void StartNewDrag()
 {
     Activate();
     selectedNote         = NoteRayUtil.NoteUnderMouse(activatedCamera, notesLayer);
     originNote           = new EditorNote();
     originNote.note      = new Note(new Vector3(0, 0, 0));
     originNote.note.Type = selectedNote.note.Type;
     if (selectedNote.type == EditorNoteType.RailNode && selectedNote.noteGO != null)
     {
         originNote.note.Position = new float[] { selectedNote.noteGO.transform.position.x, selectedNote.noteGO.transform.position.y, selectedNote.noteGO.transform.position.z }
     }
     ;
     else
     {
         originNote.note.Position = selectedNote.note.Position;
     }
     originNote.note.Segments = selectedNote.note.Segments;
     isDragging = true;
 }
コード例 #6
0
    private LongNote GetLongNoteFromRailStart(EditorNote rNote)
    {
        LongNote lNote = new LongNote();

        lNote.startTime   = rNote.time;
        lNote.note        = rNote.note;
        lNote.gameObject  = rNote.noteGO;
        lNote.segmentAxis = new List <int>();
        lNote.segments    = new List <GameObject>();
        lNote.lastSegment = rNote.connectedNodes.Count - 1;

        foreach (Transform t in rNote.connectedNodes)
        {
            lNote.segments.Add(t.gameObject);
            lNote.segmentAxis.Add(Track.YAxisInverse ? -1 : 1);
        }

        return(lNote);
    }
コード例 #7
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());
    }
コード例 #8
0
 private void EndCurrentDrag()
 {
     if (!selectedNote.exists)
     {
         return;
     }
     float[] historyTargetPos = new float[] {};
     float[] historyOriginPos = { originNote.note.Position[0], originNote.note.Position[1], originNote.note.Position[2] };
     //We need to update lines we drag with the parent GO
     if (selectedNote.type == EditorNoteType.RailStart)
     {
         Game_LineWaveCustom waveCustom = selectedNote.noteGO.GetComponentInChildren <Game_LineWaveCustom>();
         if (waveCustom)
         {
             var segments = GetLineSegementArrayPoses(selectedNote.connectedNodes);
             //Update the actual values in the note.
             selectedNote.note.Segments = segments;
             waveCustom.targetOptional  = segments;
             waveCustom.RenderLine(true, true);
         }
         Vector3 finalPos = selectedNote.noteGO.transform.position;
         selectedNote.note.Position = new float[3] {
             finalPos.x, finalPos.y, finalPos.z
         };
         historyTargetPos = new float[] { selectedNote.note.Position[0], selectedNote.note.Position[1], selectedNote.note.Position[2] };
         Track.HistoryChangeDragNote(selectedNote.type, selectedNote.note.Type, Track.CurrentSelectedMeasure, historyOriginPos, historyTargetPos, originNote.note.Segments, selectedNote.note.Segments);
     }
     else if (selectedNote.type == EditorNoteType.RailNode)
     {
         //Get the LineWave thingy from the Wave Start
         Game_LineWaveCustom waveCustom = selectedNote.noteGO.transform.parent.GetComponentInChildren <Game_LineWaveCustom>();
         if (waveCustom)
         {
             var segments = GetLineSegementArrayPoses(selectedNote.connectedNodes);
             //Update the actual values in the note.
             selectedNote.note.Segments = segments;
             waveCustom.targetOptional  = segments;
             waveCustom.RenderLine(true, true);
         }
         List <Segment> segmentsList = Track.s_instance.SegmentsList.FindAll(x => (Mathf.Abs(x.measure - Track.CurrentSelectedMeasure) < Track.MeasureCheckTolerance) && x.note.Type == selectedNote.note.Type);
         if (segmentsList == null || segmentsList.Count <= 0)
         {
             Debug.Log("Error finding segment!");
         }
         else
         {
             Note parentNote = segmentsList.First().note;
             if (parentNote == null)
             {
                 Debug.Log("Error finding parent note!");
             }
             else
             {
                 float noteBeat = Track.s_instance.FindClosestNoteBeat(Track.s_instance.GetBeatMeasureByUnit(parentNote.Position[2]));
                 // Instead of recording a change in position to an individual node, we have to record the before and after state of the parent note; otherwise there will be Undo errors when the moved node is the only node on the rail.
                 Track.HistoryChangeRailNodeParent(selectedNote.note.Type, noteBeat, new float[] { parentNote.Position[0], parentNote.Position[1], parentNote.Position[2] }, originNote.note.Segments, parentNote.Segments);
             }
         }
     }
     else if (selectedNote.type == EditorNoteType.Standard)
     {
         Vector3 finalPos = selectedNote.noteGO.transform.position;
         selectedNote.note.Position = new float[3] {
             finalPos.x, finalPos.y, finalPos.z
         };
         historyTargetPos = new float[] { selectedNote.note.Position[0], selectedNote.note.Position[1], selectedNote.note.Position[2] };
         Track.HistoryChangeDragNote(selectedNote.type, selectedNote.note.Type, Track.CurrentSelectedMeasure, historyOriginPos, historyTargetPos, originNote.note.Segments, selectedNote.note.Segments);
     }
     selectedNote = new EditorNote();
     originNote   = new EditorNote();
     isDragging   = false;
 }
コード例 #9
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();
        }
    }
コード例 #10
0
    public void RemoveNodeFromActiveRail()
    {
        EditorNote note = NoteRayUtil.NoteUnderMouse(activatedCamera, notesLayer);

        RemoveNodeFromActiveRail(note);
    }
コード例 #11
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());
    }