예제 #1
0
    public void NotePressed(MusicPiece piece)
    {
        if (hasWon)
        {
            return;
        }
        int correctNote = correctSequence[currentNote];

        if (piece.noteID == correctNote)
        {
            Debug.Log("Correct note");
            CorrectNoteAtMusicSlot();
            currentNote++;
            if (currentNote == (correctSequence.Length))
            {
                PlayMakerFSM fsm = this.GetComponent <PlayMakerFSM>();
                fsm.SendEvent("won");
                hasWon = true;
                Debug.Log("Win");
            }
        }
        else
        {
            Debug.Log("Reset back to 0");
            ResetAllMusicSlots();
            currentNote = 0;
        }
    }
예제 #2
0
 void UpdateSection(MusicSection section, float time)
 {
     if (section.nextUnloadedPiece < section.pieces.Count)
     {
         MusicPiece piece = section.pieces[section.nextUnloadedPiece];
         if ((piece.startTime - time) < 10.0f)
         {
             section.nextUnloadedPiece++;
             LineSegment seg = NewSegment();
             seg.piece = piece;
             seg.MakeArc(NoteToAngle(piece.noteArcFrom), NoteToAngle(piece.noteArcTo), (piece.endTime - piece.startTime) * scale);
             seg.UpdateMaterial();
             if (section.currTail && piece.connected)
             {
                 seg.transform.SetParent(section.currTail.transform);
                 seg.transform.localPosition = section.currTail.end;
                 section.currTail.next       = seg;
             }
             else
             {
                 seg.transform.SetParent(transform);
                 UpdateApproachingSegment(seg);
                 baseSegments.Add(seg);
             }
             section.currTail = seg;
         }
     }
 }
예제 #3
0
        private static void MusicPiece_Update(On.Music.MusicPiece.orig_Update orig, MusicPiece self)
        {
            AudioSource audioSource = null;

            for (int i = 0; i < self.subTracks.Count; i++)
            {
                //this.subTracks[i].Update();
                if (self.IsProcedural)
                {
                    if (audioSource == null && self.subTracks[i].source.isPlaying)
                    {
                        audioSource = self.subTracks[i].source;
                    }
                    else if (audioSource != null && self.subTracks[i].source.isPlaying && Math.Abs(audioSource.timeSamples - self.subTracks[i].source.timeSamples) >= audioSource.clip.frequency / 4)
                    {
                        self.subTracks[i].source.timeSamples = audioSource.timeSamples;
                    }
                }
            }

            orig(self);
        }
예제 #4
0
    void UpdateApproachingSegment(LineSegment seg)
    {
        MusicPiece piece     = seg.piece;
        float      musicTime = (piece.section == currSection) ? MusicTime() : (MusicTime() - currSection.transitionTime);
        float      fromAngle = NoteToAngle(piece.noteArcFrom);

        if (musicTime > piece.startTime)
        {
            float toAngle = NoteToAngle(piece.noteArcTo);
            seg.transform.localPosition = Vector3.zero;
            float fac = (musicTime - piece.startTime) / (piece.endTime - piece.startTime);
            seg.MakeArc(fromAngle, toAngle, (piece.endTime - piece.startTime) * scale, fac);
            if (seg.next)
            {
                seg.next.transform.localPosition = seg.end;
            }
        }
        else
        {
            float approachDistance = (piece.startTime - musicTime) * scale;
            seg.transform.localPosition = new Vector3(Mathf.Cos(fromAngle) * approachDistance, Mathf.Sin(fromAngle) * approachDistance);
        }
    }
예제 #5
0
        protected virtual void OnUDPQueued(YoutubeQueued piece)
        {
            MusicPiece mPiece = new MusicPiece(piece);

            UDPQueued?.Invoke(this, new PiecePosArgs(mPiece, piece.qPos));
        }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        camerathing.backgroundColor = Color.Lerp(new Color(0, 0.5f, 1), new Color(1, 0, 0), 1 - health);
        bool leftHeld  = Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
        bool rightHeld = Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
        bool upHeld    = Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
        bool downHeld  = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);
        int  heldIndex = (upHeld ? 1 : 0) + (downHeld ? 2 : 0) + (rightHeld ? 4 : 0) + (leftHeld ? 8 : 0);
        int  heldNote  = HeldIndexToNote[heldIndex];
        bool playHeld  = Input.GetKey(KeyCode.Space);

        if (playHeld && !lastPlayHeld && currSection != null)
        {
            currSection.lastAttackTime = MusicTime();
        }
        if (!playHeld && lastPlayHeld && currSection != null)
        {
            currSection.lastReleaseTime = MusicTime();
        }
        if (heldNote != lastHeldNote)
        {
            currSection.lastNoteChangeTime = MusicTime();
        }

        if (heldNote != 0)
        {
            charthing.targetAngle = NoteToAngle(heldNote) * 180 / Mathf.PI;
        }

        lastPlayHeld     = playHeld;
        lastHeldNote     = heldNote;
        centerVis.sprite = centerVisSprites[heldNote];
        centerVis.transform.localScale = playHeld ? new Vector3(1.3f, 1.3f, 1.3f) : new Vector3(1.0f, 1.0f, 1.0f);
        bool doParticles = false;

        for (int i = 0; i < baseSegments.Count; i++)
        {
            LineSegment seg       = baseSegments[i];
            float       musicTime = (seg.piece.section == currSection) ? MusicTime() : (MusicTime() - currSection.transitionTime);
            if (seg.piece.isNote && musicTime >= seg.piece.startTime && musicTime <= seg.piece.endTime && seg.piece.section == currSection)
            {
                // Handle attack/release/whatever
                if (seg.attackDone)
                {
                    if (!seg.releaseDone)
                    {
                        doParticles = true;
                        if (heldNote != seg.piece.note || !playHeld)
                        {
                            seg.releaseDone = true;
                            float proportionAchieved = Mathf.InverseLerp(seg.piece.startTime, seg.piece.endTime, musicTime);
                            Debug.Log("Release at " + proportionAchieved);
                        }
                    }
                }
                else
                {
                    float attackTimeDiff = Mathf.Abs((seg.piece.isAttack ? currSection.lastAttackTime : currSection.lastNoteChangeTime) - seg.piece.startTime);
                    if (attackTimeDiff < thresholdOk && ((seg.piece.isAttack) == (currSection.lastNoteChangeTime <= currSection.lastAttackTime)) && heldNote == seg.piece.note)
                    {
                        seg.attackDone = true;
                        if (attackTimeDiff < thresholdGreat)
                        {
                            Debug.Log("GREAT!");
                        }
                        else if (attackTimeDiff < thresholdGood)
                        {
                            Debug.Log("GOOD!");
                        }
                        else
                        {
                            Debug.Log("OKAY!");
                        }
                    }
                    else if (musicTime >= seg.piece.startTime + thresholdOk)
                    {
                        HandleMiss(seg);
                        seg.attackDone = true;
                    }
                }
            }
            while (seg != null && musicTime > seg.piece.endTime)
            {
                LineSegment next = seg.next;
                if (next)
                {
                    next.transform.SetParent(transform);
                    baseSegments[i] = next;
                }
                seg.next = null;
                RecycleSegment(seg);
                seg = next;
                if (!seg)
                {
                    baseSegments.RemoveAt(i);
                    i--;
                    break;
                }
            }
            if (!seg)
            {
                continue;
            }
            UpdateApproachingSegment(seg);
        }
        if (currSection != null)
        {
            if (AudioSettings.dspTime - currSection.startTime >= currSection.transitionTime / musicSource.pitch)
            {
                if (nextSection != null)
                {
                    // transition the attack/release/whatever times over
                    nextSection.lastAttackTime     = currSection.lastAttackTime - currSection.transitionTime;
                    nextSection.lastReleaseTime    = currSection.lastReleaseTime - currSection.transitionTime;
                    nextSection.lastNoteChangeTime = currSection.lastNoteChangeTime - currSection.transitionTime;

                    StartSection(nextSection, currSection.startTime + currSection.transitionTime);
                }
                else
                {
                    fader.target   = 1;
                    fader.fadeTask = "Scenes/Menu";
                    oneshots.PlayOneShot(youwin);
                    enabled = false;
                }
            }
            UpdateSection(currSection, MusicTime());
            if (nextSection != null)
            {
                UpdateSection(nextSection, MusicTime() - currSection.transitionTime);
            }
            if (currSection.nextEvent < currSection.events.Count)
            {
                MusicEvent evt = currSection.events[currSection.nextEvent];
                while (evt != null && evt.time >= MusicTime())
                {
                    evt.DoEvent(this);
                    currSection.nextEvent++;
                    if (currSection.nextEvent < currSection.events.Count)
                    {
                        evt = currSection.events[currSection.nextEvent];
                    }
                    else
                    {
                        evt = null;
                    }
                }
            }
            if (sectionCurrPieceIndex + 1 < currSection.pieces.Count)
            {
                MusicPiece nextPiece = currSection.pieces[sectionCurrPieceIndex + 1];
                if (MusicTime() >= nextPiece.startTime)
                {
                    sectionCurrPieceIndex++;
                }
            }
        }

        if (shakeDir.sqrMagnitude != 0)
        {
            float   mag           = shakeDir.magnitude;
            Vector3 invNormalized = -shakeDir.normalized;
            mag      = Mathf.Min(mag, Time.deltaTime * 0.4f);
            shakeDir = shakeDir + invNormalized * mag;
            float   shakeMult = Mathf.Cos(Time.time * 40);
            Vector3 localPos  = transform.localPosition;
            localPos.x = shakeMult * shakeDir.x;
            localPos.y = shakeMult * shakeDir.y;
            transform.localPosition = localPos;
        }
        if (doParticles && !particles.isEmitting)
        {
            particles.Play();
        }
        else if (!doParticles && particles.isEmitting)
        {
            particles.Stop(false, ParticleSystemStopBehavior.StopEmitting);
        }
    }
예제 #7
0
    void ReadLevelData(string str)
    {
        string[]     lines            = str.Split('\n');
        MusicSection currMusicSection = null;
        bool         runsepFlag       = false;
        float        timeBase         = 0;
        float        timeScale        = 1;

        foreach (string line in lines)
        {
            try {
                int    firstSpaceIndex = line.IndexOf(' ');
                string key             = firstSpaceIndex == -1 ? line : line.Substring(0, firstSpaceIndex);
                string value           = firstSpaceIndex == -1 ? "" : line.Substring(firstSpaceIndex + 1);
                key = key.Trim(); value = value.Trim();
                if (key == "section")
                {
                    currMusicSection      = new MusicSection();
                    currMusicSection.name = value;
                    timeBase  = 0;
                    timeScale = 1;
                    sections.Add(value, currMusicSection);
                }
                else if (key == "rebase")
                {
                    string[] parts    = value.Trim().Split(' ');
                    float    newBase  = parts.Length >= 1 ? float.Parse(parts[0]) : 0;
                    float    newScale = parts.Length >= 2 ? (60 / float.Parse(parts[1])) : timeScale;
                    timeBase  = timeBase + (newBase * timeScale);
                    timeScale = newScale;
                }
                else if (key == "transition")
                {
                    currMusicSection.transitionTime = float.Parse(value) * timeScale + timeBase;
                }
                else if (key == "setnext")
                {
                    MusicEventSetNext evt   = new MusicEventSetNext();
                    string[]          parts = value.Split(' ');
                    evt.time          = float.Parse(parts[0]) * timeScale + timeBase;
                    evt.possibilities = parts[1].Split(',');
                    currMusicSection.events.Add(evt);
                }
                else if (key == "play")
                {
                    PlayEvent evt   = new PlayEvent();
                    string[]  parts = value.Split(' ');
                    evt.time  = float.Parse(parts[0]) * timeScale + timeBase;
                    evt.index = int.Parse(parts[1]);
                    currMusicSection.events.Add(evt);
                }
                else if (key == "clip")
                {
                    currMusicSection.clipId = int.Parse(value);
                }
                else if (key == "run")
                {
                    string[] parts               = value.Split(',');
                    int[]    notes               = new int[parts.Length - 1];
                    float[]  noteTimes           = new float[parts.Length];
                    int      earliestNonzeroNote = 0;
                    for (int i = 0; i < parts.Length - 1; i++)
                    {
                        string[] partparts = parts[i].Split(':');
                        notes[i]     = int.Parse(partparts[0].Trim());
                        noteTimes[i] = timeBase + timeScale * float.Parse(partparts[1].Trim());
                        if (earliestNonzeroNote == 0 && notes[i] != 0)
                        {
                            earliestNonzeroNote = notes[i];
                        }
                    }
                    noteTimes[parts.Length - 1] = timeBase + timeScale * float.Parse(parts[parts.Length - 1].Trim());

                    MusicPiece lastPiece = currMusicSection.pieces.Count > 0 ? currMusicSection.pieces[currMusicSection.pieces.Count - 1] : null;
                    MusicPiece joiner    = null;
                    if (lastPiece != null && !runsepFlag)
                    {
                        if (lastPiece.endTime >= noteTimes[0])
                        {
                            joiner = lastPiece;
                        }
                        else
                        {
                            joiner             = new MusicPiece();
                            joiner.section     = currMusicSection;
                            joiner.note        = 0;
                            joiner.startTime   = lastPiece.endTime;
                            joiner.endTime     = noteTimes[0];
                            joiner.noteArcFrom = lastPiece.noteArcTo;
                            joiner.noteArcTo   = earliestNonzeroNote == 0 ? joiner.noteArcFrom : earliestNonzeroNote;
                            joiner.isAttack    = false;
                            currMusicSection.pieces.Add(joiner);
                        }
                    }
                    for (int i = 0; i < notes.Length; i++)
                    {
                        MusicPiece piece = new MusicPiece();
                        piece.section   = currMusicSection;
                        piece.isAttack  = (i == 0);
                        piece.isNote    = true;
                        piece.connected = joiner != null;
                        piece.startTime = noteTimes[i];
                        piece.endTime   = noteTimes[i + 1];
                        piece.note      = notes[i];
                        if (piece.note != 0)
                        {
                            piece.noteArcFrom = piece.note;
                            piece.noteArcTo   = piece.note;
                        }
                        else
                        {
                            if (joiner != null)
                            {
                                piece.noteArcFrom = joiner.noteArcTo;
                            }
                            else if (earliestNonzeroNote != 0)
                            {
                                piece.noteArcFrom = earliestNonzeroNote;
                            }
                            else if (lastPiece != null)
                            {
                                piece.noteArcFrom = lastPiece.noteArcTo;
                            }
                            else
                            {
                                piece.noteArcFrom = 1;
                            }
                            if (i < notes.Length - 1 && notes[i + 1] > 0)
                            {
                                piece.noteArcTo = notes[i + 1];
                            }
                            else
                            {
                                piece.noteArcTo = piece.noteArcFrom;
                            }
                        }
                        currMusicSection.pieces.Add(piece);
                        joiner = piece;
                    }
                    runsepFlag = false;
                }
                else if (key == "runsep")
                {
                    runsepFlag = true;
                }
            } catch (System.Exception e) {
                Debug.Log(line);
                throw e;
            }
        }
    }
 public patch_SubTrack(MusicPiece piece, int index, string trackName) : base(piece, index, trackName)
 {
 }