public static ActionHistory.Action[] AddObjectToCurrentChart(Note note, ChartEditor editor, bool update = true, bool copy = true)
    {
        Note throwaway;

        return(AddObjectToCurrentChart(note, editor, out throwaway, update, copy));
    }
 private void Start()
 {
     ChartEditor.GetInstance().globals.services.RegisterUpdateableService(this);
 }
 void Awake()
 {
     editor = GameObject.FindGameObjectWithTag("Editor").GetComponent <ChartEditor>();
 }
    static MoonscraperEngine.ICommand GenerateCommandsAdjustedForAnchors(BPM currentBPM, uint desiredBpmValue)
    {
        List <SongEditCommand> commands = new List <SongEditCommand>();

        int pos = SongObjectHelper.FindObjectPosition(currentBPM, currentBPM.song.bpms);

        if (pos != SongObjectHelper.NOTFOUND)
        {
            BPM anchor      = null;
            BPM bpmToAdjust = null;

            int anchorPos = 0;

            // Get the next anchor
            for (int i = pos + 1; i < currentBPM.song.bpms.Count; ++i)
            {
                if (currentBPM.song.bpms[i].anchor != null)
                {
                    anchor    = currentBPM.song.bpms[i];
                    anchorPos = i;
                    // Get the bpm before that anchor
                    bpmToAdjust = currentBPM.song.bpms[i - 1];

                    break;
                }
            }

            if (anchor == null || bpmToAdjust == currentBPM)
            {
                commands.Add(new SongEditModify <BPM>(currentBPM, new BPM(currentBPM.tick, desiredBpmValue, currentBPM.anchor)));
                return(new BatchedSongEditCommand(commands));
            }

            // Calculate the minimum the bpm can adjust to
            const float MIN_DT = 0.01f;

            float bpmTime    = (float)anchor.anchor - MIN_DT;
            float resolution = currentBPM.song.resolution;
            // Calculate the time of the 2nd bpm pretending that the adjustable one is super close to the anchor
            for (int i = anchorPos - 1; i > pos + 1; --i)
            {
                // Calculate up until 2 bpms before the anchor
                // Re-hash of the actual time calculation equation in Song.cs
                bpmTime -= (float)TickFunctions.DisToTime(currentBPM.song.bpms[i - 1].tick, currentBPM.song.bpms[i].tick, resolution, currentBPM.song.bpms[i - 1].value / 1000.0f);
            }

            float timeBetweenFirstAndSecond = bpmTime - currentBPM.time;
            // What bpm will result in this exact time difference?
            uint minVal = (uint)(Mathf.Ceil((float)TickFunctions.DisToBpm(currentBPM.song.bpms[pos].tick, currentBPM.song.bpms[pos + 1].tick, timeBetweenFirstAndSecond, currentBPM.song.resolution)) * 1000);

            if (desiredBpmValue < minVal)
            {
                desiredBpmValue = minVal;
            }

            BPM  anchorBPM = anchor;
            uint oldValue  = currentBPM.value;

            ChartEditor editor = ChartEditor.Instance;
            currentBPM.value = desiredBpmValue; // Very much cheating, better to not do this
            double deltaTime = (double)anchorBPM.anchor - editor.currentSong.LiveTickToTime(bpmToAdjust.tick, editor.currentSong.resolution);
            uint   newValue  = (uint)Mathf.Round((float)(TickFunctions.DisToBpm(bpmToAdjust.tick, anchorBPM.tick, deltaTime, editor.currentSong.resolution) * 1000.0d));
            currentBPM.value = oldValue;

            uint finalValue = oldValue;
            if (deltaTime > 0 && newValue > 0)
            {
                if (newValue != 0)
                {
                    commands.Add(new SongEditModify <BPM>(bpmToAdjust, new BPM(bpmToAdjust.tick, newValue, bpmToAdjust.anchor)));
                }

                finalValue = desiredBpmValue;
            }

            desiredBpmValue = finalValue;
        }

        if (desiredBpmValue == currentBPM.value)
        {
            return(null);
        }

        commands.Add(new SongEditModify <BPM>(currentBPM, new BPM(currentBPM.tick, desiredBpmValue, currentBPM.anchor)));
        return(new BatchedSongEditCommand(commands));
    }
    void SectionJump(float direction)
    {
        // Jump to the previous or next sections
        float position = Mathf.Round(strikeLine.position.y);

        int i = 0;

        while (i < editor.currentSong.sections.Count && Mathf.Round(ChartEditor.WorldYPosition(editor.currentSong.sections[i])) <= position)
        {
            ++i;
        }

        // Jump forward
        if (direction > 0)
        {
            // Found section ahead
            if (i < editor.currentSong.sections.Count && Mathf.Round(ChartEditor.WorldYPosition(editor.currentSong.sections[i])) > position)
            {
                SetPosition(editor.currentSong.sections[i].tick);
            }
            else
            {
                SetPosition(editor.currentSong.TimeToTick(editor.currentSongLength, editor.currentSong.resolution));       // Jump to the end of the song
            }
        }
        // Jump backwards
        else
        {
            while (i > editor.currentSong.sections.Count - 1 || (i >= 0 && Mathf.Round(ChartEditor.WorldYPosition(editor.currentSong.sections[i])) >= position))
            {
                --i;
            }

            if (i >= 0)
            {
                SetPosition(editor.currentSong.sections[i].tick);
            }
            else
            {
                SetPosition(0);
            }
        }
    }
 public static float TickToWorldYPosition(this Song song, uint position, float resolution)
 {
     return(ChartEditor.TimeToWorldYPosition(song.TickToTime(position, resolution)));
 }
 protected virtual void Awake()
 {
     editor    = ChartEditor.Instance;
     objectRen = GetComponent <Renderer>();
 }
示例#8
0
 public override void Delete(bool update = true)
 {
     ChartEditor.GetInstance().songObjectPoolManager.SetAllPoolsDirty();
     base.Delete(update);
 }
 protected virtual void Awake()
 {
     editor    = GameObject.FindGameObjectWithTag("Editor").GetComponent <ChartEditor>();
     objectRen = GetComponent <Renderer>();
 }
示例#10
0
 // Use this for initialization
 protected override void Start()
 {
     base.Start();
     editor = ChartEditor.Instance;
     editor.events.saveEvent.Register(StartFade);
 }
    protected new void LateUpdate()
    {
        base.LateUpdate();

        // Re-do the controller's position setting
        var events = editor.currentSong.events;

        float offset = EventController.BASE_OFFSET;
        int   index, length;

        SongObjectHelper.GetRange(events, songEvent.tick, songEvent.tick, out index, out length);

        // Determine the offset for the object
        for (int i = index; i < index + length; ++i)
        {
            if (events[i].GetType() != songEvent.GetType())
            {
                continue;
            }

            offset += EventController.OFFSET_SPACING;
        }

        transform.position = new UnityEngine.Vector3(SongObjectController.CHART_CENTER_POS + EventController.position, ChartEditor.WorldYPosition(songEvent), offset);
    }
 // Use this for initialization
 protected override void Start()
 {
     base.Start();
     editor = ChartEditor.GetInstance();
     EventsManager.onSaveEventList.Add(StartFade);
 }
    void OnLanesChanged(int laneCount)
    {
        ChartEditor editor = ChartEditor.Instance;

        SetMaterialColours(editor.currentGameMode, laneCount);
    }
    public static ActionHistory.Action[] AddObjectToCurrentChart(Note note, ChartEditor editor, out Note addedNote, bool update = true, bool copy = true)
    {
        List <ActionHistory.Action> noteRecord = new List <ActionHistory.Action>();

        int index, length;

        SongObjectHelper.GetRange(editor.currentChart.notes, note.tick, note.tick, out index, out length);

        // Account for when adding an exact note as what's already in
        if (length > 0)
        {
            bool cancelAdd = false;
            for (int i = index; i < index + length; ++i)
            {
                Note overwriteNote = editor.currentChart.notes[i];

                if (note.AllValuesCompare(overwriteNote))
                {
                    cancelAdd = true;
                    break;
                }
                if ((((note.IsOpenNote() || overwriteNote.IsOpenNote()) && !Globals.drumMode) || note.guitarFret == overwriteNote.guitarFret) && !note.AllValuesCompare(overwriteNote))
                {
                    noteRecord.Add(new ActionHistory.Delete(overwriteNote));
                }
            }
            if (!cancelAdd)
            {
                noteRecord.Add(new ActionHistory.Add(note));
            }
        }
        else
        {
            noteRecord.Add(new ActionHistory.Add(note));
        }

        Note noteToAdd;

        if (copy)
        {
            noteToAdd = new Note(note);
        }
        else
        {
            noteToAdd = note;
        }

        if (noteToAdd.IsOpenNote())
        {
            noteToAdd.flags &= ~Note.Flags.Tap;
        }

        editor.currentChart.Add(noteToAdd, update);
        if (noteToAdd.cannotBeForced)
        {
            noteToAdd.flags &= ~Note.Flags.Forced;
        }

        noteToAdd.ApplyFlagsToChord();

        //NoteController nCon = editor.CreateNoteObject(noteToAdd);
        standardOverwriteOpen(noteToAdd);

        noteRecord.InsertRange(0, CapNoteCheck(noteToAdd));
        noteRecord.InsertRange(0, ForwardCap(noteToAdd));     // Do this due to pasting from the clipboard

        // Check if the automatic un-force will kick in
        ActionHistory.Action forceCheck = AutoForcedCheck(noteToAdd);

        addedNote = noteToAdd;

        if (forceCheck != null)
        {
            noteRecord.Insert(0, forceCheck);           // Insert at the start so that the modification happens at the end of the undo function, otherwise the natural force check prevents it from being forced
        }
        foreach (Note chordNote in addedNote.chord)
        {
            if (chordNote.controller)
            {
                chordNote.controller.SetDirty();
            }
        }

        Note next = addedNote.nextSeperateNote;

        if (next != null)
        {
            foreach (Note chordNote in next.chord)
            {
                if (chordNote.controller)
                {
                    chordNote.controller.SetDirty();
                }
            }
        }

        return(noteRecord.ToArray());
    }
示例#15
0
 void Awake()
 {
     editor = ChartEditor.Instance;
 }
 public override void SystemEnter()
 {
     editor          = ChartEditor.Instance;
     mainCamera      = Camera.main;
     world2DPosition = null;
 }
 public static uint WorldYPositionToTick(this Song song, float worldYPos, float resolution)
 {
     return(song.TimeToTick(ChartEditor.WorldYPositionToTime(worldYPos), resolution));
 }
示例#18
0
    void RecoveryDetect(float time, HitWindow <GuitarNoteHitKnowledge> hitWindow, int fretInputMask, bool strummed, uint noteStreak)
    {
        var noteKnowledgeList = hitWindow.noteKnowledgeQueue;

        // Search to see if user is hitting a note ahead
        List <GuitarNoteHitKnowledge> validatedNotes = new List <GuitarNoteHitKnowledge>();

        foreach (GuitarNoteHitKnowledge noteKnowledge in noteKnowledgeList)
        {
            // Collect all notes the user is possibly hitting
            if (
                GameplayInputFunctions.ValidateFrets(noteKnowledge.note, fretInputMask, noteStreak) &&
                GameplayInputFunctions.ValidateStrum(noteKnowledge.note, canTap, strummed, noteStreak)
                )
            {
                validatedNotes.Add(noteKnowledge);
            }
        }

        if (validatedNotes.Count > 0)
        {
            // Recovery algorithm
            // Select the note closest to the strikeline
            float aimYPos = ChartEditor.GetInstance().visibleStrikeline.transform.position.y + 0.25f;  // Added offset from the note controller

            GuitarNoteHitKnowledge selectedNote = validatedNotes[0];

            float dis = -1;

            foreach (GuitarNoteHitKnowledge validatedNote in validatedNotes)
            {
                if (!selectedNote.note.controller)
                {
                    return;
                }

                NoteController noteController = selectedNote.note.controller;

                float distance = Mathf.Abs(aimYPos - noteController.transform.position.y);
                if (distance < dis || dis < 0)
                {
                    selectedNote = validatedNote;
                    dis          = distance;
                }
            }

            int index = noteKnowledgeList.IndexOf(selectedNote);
            GuitarNoteHitKnowledge note = noteKnowledgeList[index];

            // Recovery missed notes
            if (index > 0)
            {
                Debug.Log("Missed notes when performing recovery. Notes skipped = " + index);
            }

            for (int missedCounter = 0; missedCounter < index; ++missedCounter)
            {
                MissNote(time, MissSubType.NoteMiss, noteKnowledgeList[missedCounter]);
            }

            HitNote(time, note);

            // We fill out our own knowledge
            note.fretValidationTime  = time;
            note.strumValidationTime = time;
            if (strummed)
            {
                ++note.strumCounter;
            }
        }
        else if (strummed)
        {
            MissNote(time, MissSubType.Overstrum);
            Debug.Log("Missed due to strumming when there were no notes to strum during recovery");
        }
    }
示例#19
0
 public SelectedObjectsManager(ChartEditor editor)
 {
     this.editor = editor;
 }
 protected void Awake()
 {
     editor = ChartEditor.Instance;
     isTool = GetComponent <ToolObject>();
 }
示例#21
0
 protected void Awake()
 {
     editor = ChartEditor.GetInstance();
 }
    // Update is called once per frame
    public override void UpdateVisuals()
    {
        if (!meshFilter)
        {
            Awake();
        }

        base.UpdateVisuals();

        Note note = nCon.note;

        if (note != null)
        {
            // Visuals
            // Update mesh
            if (note.IsOpenNote())// fret_type == Note.Fret_Type.OPEN)
            {
                meshFilter.sharedMesh = resources.openModel.sharedMesh;
            }
            else if (specialType == Note.SpecialType.StarPower)
            {
                meshFilter.sharedMesh = resources.spModel.sharedMesh;
            }
            else
            {
                meshFilter.sharedMesh = resources.standardModel.sharedMesh;
            }

            Material[] materials;

            ChartEditor    editor         = ChartEditor.Instance;
            Chart.GameMode gameMode       = editor.currentGameMode;
            Note.NoteType  visualNoteType = noteType;

            Vector3 scale = new Vector3(1, 1, 1);

            // Determine materials
            if (note.IsOpenNote())
            {
                materials = resources.openRenderer.sharedMaterials;

                int colourIndex = 0;

                if (specialType == Note.SpecialType.StarPower)
                {
                    if (visualNoteType == Note.NoteType.Hopo)
                    {
                        colourIndex = 3;
                    }
                    else
                    {
                        colourIndex = 2;
                    }
                }
                else
                {
                    if (visualNoteType == Note.NoteType.Hopo)
                    {
                        colourIndex = 1;
                    }
                    else
                    {
                        colourIndex = isTool ? 4 : 0;
                    }
                }

                materials[2] = resources.openMaterials[colourIndex];
            }
            else
            {
                LaneInfo laneInfo = editor.laneInfo;
                Material colorMat;

                int noteIndex = note.rawNote;

                if (note.ShouldBeCulledFromLanes(laneInfo))                      // Should have been culled, but we want to display it anyway, clamp it to the last lane
                {
                    noteIndex = Mathf.Min(note.rawNote, laneInfo.laneCount - 1); // Clamp to the edge of the lanes
                }

                if (isTool)
                {
                    switch (visualNoteType)
                    {
                    case Note.NoteType.Tap:
                    {
                        colorMat = resources.GetToolTapMaterial(gameMode, laneInfo, noteIndex);
                        break;
                    }

                    case Note.NoteType.Cymbal:
                    {
                        colorMat = resources.GetToolCymbalMaterial(gameMode, laneInfo, noteIndex);
                        break;
                    }

                    default:
                    {
                        colorMat = resources.GetToolStrumMaterial(gameMode, laneInfo, noteIndex);
                        break;
                    }
                    }
                }
                else
                {
                    switch (visualNoteType)
                    {
                    case Note.NoteType.Tap:
                    {
                        colorMat = resources.GetTapMaterial(gameMode, laneInfo, noteIndex);
                        break;
                    }

                    case Note.NoteType.Cymbal:
                    {
                        colorMat = resources.GetCymbalMaterial(gameMode, laneInfo, noteIndex);
                        break;
                    }

                    default:
                    {
                        colorMat = resources.GetStrumMaterial(gameMode, laneInfo, noteIndex);
                        break;
                    }
                    }
                }

                materials = GetMaterials(colorMat, visualNoteType);
            }

            transform.localScale         = scale;
            noteRenderer.sharedMaterials = materials;
        }

        UpdateTextDisplay(note);
    }
    void Update()
    {
        ChartEditor editor = ChartEditor.Instance;

        halfHeight       = rectTransform.rect.height / 2.0f;
        scaledHalfHeight = halfHeight * transform.lossyScale.y;

        int newPercentageValue = (int)(handlePosRound * 100);

        if (previousPercentageValue != newPercentageValue)
        {
            UpdatePercentageText(newPercentageValue);
        }

        bool update = (!ReferenceEquals(prevSong, editor.currentSong) || prevSongLength != editor.currentSongLength ||
                       previousScreenSize.x != Screen.width || previousScreenSize.y != Screen.height ||
                       prevRes.height != Screen.currentResolution.height ||
                       prevRes.width != Screen.currentResolution.width || prevRes.refreshRate != Screen.currentResolution.refreshRate);

        // Check if indicator pools need to be extended

        while (sectionIndicatorPool.Length < editor.currentSong.sections.Count)
        {
            SectionGuiController[] controllers = new SectionGuiController[sectionIndicatorPool.Length + POOL_EXTEND_SIZE];
            System.Array.Copy(sectionIndicatorPool, controllers, sectionIndicatorPool.Length);

            for (int i = sectionIndicatorPool.Length; i < controllers.Length; ++i)
            {
                controllers[i] = CreateSectionIndicator(i);
            }

            sectionIndicatorPool = controllers;
        }

        while (starpowerIndicatorPool.Length < editor.currentChart.starPower.Count)
        {
            StarpowerGUIController[] controllers = new StarpowerGUIController[starpowerIndicatorPool.Length + POOL_EXTEND_SIZE];
            System.Array.Copy(starpowerIndicatorPool, controllers, starpowerIndicatorPool.Length);

            for (int i = starpowerIndicatorPool.Length; i < controllers.Length; ++i)
            {
                controllers[i] = CreateSPIndicator(i);
            }

            starpowerIndicatorPool = controllers;
        }

        // Set the sections
        if (update || editor.currentSong.sections.Count != prevSectionLength || forceFullRepaint)
        {
            StartCoroutine(UpdateSectionIndicator());
        }

        // Set the sp
        if (update || editor.currentChart.starPower.Count != prevSPLength || forceFullRepaint)
        {
            StartCoroutine(UpdateStarpowerIndicators());
        }

        prevSong             = editor.currentSong;
        prevSongLength       = editor.currentSongLength;
        prevSPLength         = editor.currentChart.starPower.Count;
        prevSectionLength    = editor.currentSong.sections.Count;
        previousScreenSize.x = Screen.width;
        previousScreenSize.y = Screen.height;
        prevRes = Screen.currentResolution;

        forceFullRepaint = false;
    }
 protected virtual void Start()
 {
     ChartEditor.GetInstance().globals.services.RegisterUpdateableService(this);
 }
示例#25
0
    // Update is called once per frame
    public override void UpdateVisuals()
    {
        if (!meshFilter)
        {
            Awake();
        }

        base.UpdateVisuals();

        Note note = nCon.note;

        if (note != null)
        {
            // Visuals
            // Update mesh
            if (note.IsOpenNote())// fret_type == Note.Fret_Type.OPEN)
            {
                meshFilter.sharedMesh = resources.openModel.sharedMesh;
            }
            else if (specialType == Note.SpecialType.StarPower)
            {
                meshFilter.sharedMesh = resources.spModel.sharedMesh;
            }
            else
            {
                meshFilter.sharedMesh = resources.standardModel.sharedMesh;
            }

            Material[] materials;

            ChartEditor    editor         = ChartEditor.Instance;
            Chart.GameMode gameMode       = editor.currentGameMode;
            Note.NoteType  visualNoteType = noteType;

            // Determine materials
            if (note.IsOpenNote())
            {
                materials = resources.openRenderer.sharedMaterials;

                int colourIndex = 0;

                if (specialType == Note.SpecialType.StarPower)
                {
                    if (visualNoteType == Note.NoteType.Hopo)
                    {
                        colourIndex = 3;
                    }
                    else
                    {
                        colourIndex = 2;
                    }
                }
                else
                {
                    if (visualNoteType == Note.NoteType.Hopo)
                    {
                        colourIndex = 1;
                    }
                    else
                    {
                        colourIndex = isTool ? 4 : 0;
                    }
                }

                materials[2] = resources.openMaterials[colourIndex];
            }
            else
            {
                LaneInfo laneInfo = editor.laneInfo;
                Material colorMat;

                if (isTool)
                {
                    switch (visualNoteType)
                    {
                    case Note.NoteType.Tap:
                    {
                        colorMat = resources.GetToolTapMaterial(gameMode, laneInfo, note.rawNote);
                        break;
                    }

                    case Note.NoteType.Cymbal:
                    {
                        colorMat = resources.GetToolCymbalMaterial(gameMode, laneInfo, note.rawNote);
                        break;
                    }

                    default:
                    {
                        colorMat = resources.GetToolStrumMaterial(gameMode, laneInfo, note.rawNote);
                        break;
                    }
                    }
                }
                else
                {
                    switch (visualNoteType)
                    {
                    case Note.NoteType.Tap:
                    {
                        colorMat = resources.GetTapMaterial(gameMode, laneInfo, note.rawNote);
                        break;
                    }

                    case Note.NoteType.Cymbal:
                    {
                        colorMat = resources.GetCymbalMaterial(gameMode, laneInfo, note.rawNote);
                        break;
                    }

                    default:
                    {
                        colorMat = resources.GetStrumMaterial(gameMode, laneInfo, note.rawNote);
                        break;
                    }
                    }
                }

                materials = GetMaterials(colorMat, visualNoteType);
            }

            noteRenderer.sharedMaterials = materials;
        }
    }
示例#26
0
    public override void Update()
    {
        base.Update();

        ChartEditor editor   = ChartEditor.Instance;
        Services    services = editor.services;

        Globals.ViewMode viewMode = Globals.viewMode;

        if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.StepIncrease))
        {
            Globals.gameSettings.snappingStep.Increment();
        }

        else if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.StepDecrease))
        {
            Globals.gameSettings.snappingStep.Decrement();
        }

        if (editor.groupMove.movementInProgress)
        {
            return;
        }

        if (services.CanPlay())
        {
            if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.PlayPause))
            {
                editor.Play();
                return;
            }
            else if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.StartGameplay))
            {
                editor.StartGameplay();
                return;
            }
        }

        if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.Delete) && editor.selectedObjectsManager.currentSelectedObjects.Count > 0)
        {
            editor.Delete();
        }

        else if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.SelectAll))
        {
            editor.toolManager.ChangeTool(EditorObjectToolManager.ToolID.Cursor);
            editor.selectedObjectsManager.SelectAllInView(viewMode);
        }
        else if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.SelectAllSection))
        {
            editor.toolManager.ChangeTool(EditorObjectToolManager.ToolID.Cursor);
            editor.selectedObjectsManager.HighlightCurrentSection(viewMode);
        }

        if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1))
        {
            bool success = false;

            if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.ActionHistoryUndo))
            {
                if (!editor.commandStack.isAtStart && editor.services.CanUndo())
                {
                    editor.UndoWrapper();
                    success = true;
                }
            }
            else if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.ActionHistoryRedo))
            {
                if (!editor.commandStack.isAtEnd && editor.services.CanRedo())
                {
                    editor.RedoWrapper();
                    success = true;
                }
            }

            if (success)
            {
                EventSystem.current.SetSelectedGameObject(null);
                editor.groupSelect.reset();
                TimelineHandler.Repaint();
            }
        }

        if (editor.selectedObjectsManager.currentSelectedObjects.Count > 0)
        {
            if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.ClipboardCut))
            {
                editor.Cut();
            }
            else if (MSChartEditorInput.GetInputDown(MSChartEditorInputActions.ClipboardCopy))
            {
                editor.Copy();
            }
        }
    }
    public static SongObject FindObjectToModify(SongObject so)
    {
        ChartEditor editor = ChartEditor.Instance;
        Song        song   = editor.currentSong;
        Chart       chart  = editor.currentChart;

        int index;

        switch ((SongObject.ID)so.classID)
        {
        case SongObject.ID.Note:
            index = SongObjectHelper.FindObjectPosition(so as Note, chart.notes);
            if (index == SongObjectHelper.NOTFOUND)
            {
                return(null);
            }
            return(chart.notes[index]);

        case SongObject.ID.Starpower:
            index = SongObjectHelper.FindObjectPosition(so as Starpower, chart.starPower);
            if (index == SongObjectHelper.NOTFOUND)
            {
                return(null);
            }
            return(chart.starPower[index]);

        case SongObject.ID.ChartEvent:
            index = SongObjectHelper.FindObjectPosition(so as ChartEvent, chart.events);
            if (index == SongObjectHelper.NOTFOUND)
            {
                return(null);
            }
            return(chart.events[index]);

        case SongObject.ID.BPM:
            index = SongObjectHelper.FindObjectPosition(so as BPM, song.bpms);
            if (index == SongObjectHelper.NOTFOUND)
            {
                return(null);
            }
            return(song.bpms[index]);

        case SongObject.ID.TimeSignature:
            index = SongObjectHelper.FindObjectPosition(so as TimeSignature, song.timeSignatures);
            if (index == SongObjectHelper.NOTFOUND)
            {
                return(null);
            }
            return(song.timeSignatures[index]);

        case SongObject.ID.Section:
            index = SongObjectHelper.FindObjectPosition(so as Section, song.sections);
            if (index == SongObjectHelper.NOTFOUND)
            {
                return(null);
            }
            return(song.sections[index]);

        case SongObject.ID.Event:
            index = SongObjectHelper.FindObjectPosition(so as Event, song.events);
            if (index == SongObjectHelper.NOTFOUND)
            {
                return(null);
            }
            return(song.events[index]);

        default:
            Debug.LogError("Object to modify not implemented for object. Object will not be modified.");
            break;
        }

        return(so);
    }
    // Update is called once per frame
    public override void SystemUpdate()
    {
        ChartEditor editor = ChartEditor.Instance;

        // Show a preview if the user will click on an object
        GameObject songObject = editor.services.mouseMonitorSystem.currentSelectableUnderMouse;

        foreach (GameObject highlight in highlights)
        {
            highlight.SetActive(false);
        }

        var  currentTool   = editor.toolManager.currentToolId;
        bool validTool     = currentTool == EditorObjectToolManager.ToolID.Cursor || currentTool == EditorObjectToolManager.ToolID.Eraser;
        bool previewDelete = Input.GetMouseButton(1) && (currentTool != EditorObjectToolManager.ToolID.Cursor || currentTool != EditorObjectToolManager.ToolID.Eraser);
        bool showHighlight = !Input.GetMouseButton(0) && songObject != null && (validTool || previewDelete);

        if (!showHighlight)
        {
            return;
        }

        // Change the shared material of the highlight
        if (Input.GetMouseButton(1))
        {
            if (songObject && songObject.GetComponent <SustainController>())
            {
                return;
            }
            else
            {
                hoverHighlightRen.sharedMaterial.color = new Color(Color.red.r, Color.red.g, Color.red.b, initColor.a);
            }
        }
        else
        {
            hoverHighlightRen.sharedMaterial.color = initColor;
        }

        if (showHighlight)
        {
            songObjects.Clear();

            if (MSChartEditorInput.GetInput(MSChartEditorInputActions.ChordSelect))
            {
                // Check if we're over a note
                NoteController nCon = songObject.GetComponent <NoteController>();
                if (nCon)
                {
                    foreach (Note note in nCon.note.chord)
                    {
                        songObjects.Add(note.controller.gameObject);
                    }
                }
                else
                {
                    SustainController sCon = songObject.GetComponent <SustainController>();
                    if (sCon)
                    {
                        foreach (Note note in sCon.nCon.note.chord)
                        {
                            songObjects.Add(note.controller.sustain.gameObject);
                        }
                    }
                }
            }
            else
            {
                songObjects.Add(songObject);
            }

            // Activate, position and scale highlights
            for (int i = 0; i < songObjects.Count; ++i)
            {
                if (i < highlights.Length)
                {
                    highlights[i].SetActive(true);
                    highlights[i].transform.position = songObjects[i].transform.position;

                    Vector3    scale = songObjects[i].transform.localScale;
                    Collider   col3d = songObjects[i].GetComponent <Collider>();
                    Collider2D col   = songObjects[i].GetComponent <Collider2D>();

                    if (col3d)
                    {
                        scale = col3d.bounds.size;
                    }
                    else
                    {
                        scale = col.bounds.size;
                    }

                    if (scale.z == 0)
                    {
                        scale.z = 0.1f;
                    }
                    highlights[i].transform.localScale = scale;
                }
            }
        }
    }
示例#29
0
    public bool CanRedo()
    {
        ChartEditor editor = ChartEditor.Instance;

        return(!editor.commandStack.isAtEnd && !editor.groupMove.movementInProgress);
    }
 // Use this for initialization
 void Start()
 {
     editor = ChartEditor.Instance;
 }