示例#1
0
    GameObject RandomNote(NoteDirection dir)
    {
        switch (dir)
        {
        case NoteDirection.Left:
            noteToReturn = leftNote;
            break;

        case NoteDirection.Up:
            noteToReturn = upNote;
            break;

        case NoteDirection.Down:
            noteToReturn = downNote;
            break;

        case NoteDirection.Right:
            noteToReturn = rightNote;
            break;

        default:
            noteToReturn = upNote;
            break;
        }

        return(noteToReturn);
    }
示例#2
0
    //this event will be called every time a beat is detected.
    //Change the threshold parameter in the inspector
    //to adjust the sensitivity
    void onOnbeatDetected()
    {
        if (noteSpawner.activeInHierarchy)
        {
            //Reset Beat Counter
            if (beatCounter > 11)
            {
                beatCounter = 0;
            }
            Instantiate(fireworkPrefab, new Vector3(beatCounter - 4f, 0f, 0f), Quaternion.identity, spectrumHolder.transform);
            beatCounter++;

            if (UnityEngine.Random.Range(0, 101) % 2 == 0)
            {
                int           index           = UnityEngine.Random.Range(0, 4);
                NoteDirection randomDirection = (NoteDirection)index;

                Vector3    pos        = spawners[index].transform.position;
                Quaternion quat       = spawners[index].transform.rotation;
                GameObject randomNote = Instantiate(RandomNote(randomDirection), pos, quat, noteHolder.transform);
                Note       note       = randomNote.GetComponent <Note>();
                note.InitializeNote(randomDirection, randomNote, pos, quat, noteHolder.transform);
            }
        }
    }
        public Candidates GetLeftCandidates(NoteDirection direction, NotePosition position)
        {
            switch (direction)
            {
            case NoteDirection.Up:
                return(GetLeftCandidatesForUp(position));

            case NoteDirection.UpRight:
                return(new Candidates());

            case NoteDirection.Right:
                return(GetLeftCandidatesForRight(position));

            case NoteDirection.DownRight:
                return(new Candidates());

            case NoteDirection.Down:
                return(GetLeftCandidatesForDown(position));

            case NoteDirection.DownLeft:
                return(new Candidates());

            case NoteDirection.Left:
                return(GetLeftCandidatesForLeft(position));

            case NoteDirection.UpLeft:
                return(new Candidates());
            }

            return(new Candidates());
        }
示例#4
0
    float RandomNoteXPos(NoteDirection dir)
    {
        float noteXPos = 0f;

        switch (dir)
        {
        case NoteDirection.Left:
            noteXPos = xPosList[0];
            break;

        case NoteDirection.Up:
            noteXPos = xPosList[1];
            break;

        case NoteDirection.Down:
            noteXPos = xPosList[2];
            break;

        case NoteDirection.Right:
            noteXPos = xPosList[3];
            break;
        }

        return(noteXPos);
    }
示例#5
0
        void AddChordDots(ABC.Chord chord, ABC.Clef clef, NoteDirection noteDirection, Bounds rootItem, GameObject container, ref Bounds totalBounds)
        {
            int oddStepOffset = noteDirection == NoteDirection.Up ? 1 : -1;
            var dotSet        = new HashSet <int>();

            foreach (var note in chord.notes)
            {
                int stepCount = note.pitch - clefZero[clef];

                if (stepCount % 2 == 1)
                {
                    stepCount += oddStepOffset;
                }

                dotSet.Add(stepCount);
            }

            foreach (var step in dotSet)
            {
                var positionX = rootItem.max.x;

                for (int i = 0; i < chord.dotCount; i++)
                {
                    var dot       = CreateNoteDot(step, container, positionX + dotAdvance);
                    var dotBounds = dot.bounds;
                    positionX += dotBounds.size.x;
                    totalBounds.Encapsulate(dotBounds);
                }
            }
        }
示例#6
0
        private bool ChordIsCompressed(ABC.Chord chord, NoteDirection noteDirection)
        {
            if (noteDirection == NoteDirection.Down)
            {
                for (int i = chord.notes.Length - 2; i >= 0; i--)
                {
                    if (chord.notes[i + 1].pitch - chord.notes[i].pitch == 1)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                for (int i = 1; i < chord.notes.Length; i++)
                {
                    if (chord.notes[i].pitch - chord.notes[i - 1].pitch == 1)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#7
0
        private NoteInfo CreateChord(ABC.Chord chord, ABC.Clef clef, NoteDirection noteDirection, Beam beam, IReadOnlyList <string> decorations, GameObject container)
        {
            var offset      = Vector3.zero;
            var totalBounds = new Bounds();

            totalBounds.SetMinMax(offset, offset);

            if (CreateChordAccidentals(chord.notes, clef, ref offset, container, ref totalBounds))
            {
                offset.x = totalBounds.max.x + accidentalOffset;
            }

            var staffMarkers = CreateChordStaffMarkers(noteDirection, chord, clef, offset.x, compressedChordNoteOffset, ref totalBounds);

            if (staffMarkers != null) // this ensures that the note appears centered w.r.t the markers
            {
                offset += new Vector3(staffMarkerNoteOffset, 0.0f, 0.0f);
            }

            Bounds rootBounds = CreateChordNotes(noteDirection, chord, beam, clef, container, offset, ref totalBounds);

            AddDecorations(chord, decorations, rootBounds, container, ref totalBounds);

            if (chord.dotCount > 0)
            {
                AddChordDots(chord, clef, noteDirection, totalBounds, container, ref totalBounds);
            }

            if (staffMarkers != null)
            {
                staffMarkers.transform.parent = container.transform;
            }

            return(new NoteInfo(rootBounds, totalBounds));
        }
示例#8
0
 public Note(Note note)
 {
     this.position   = note.position;
     this.type       = note.type;
     this.next       = note.next;
     this.prev       = note.prev;
     this.attributes = note.attributes;
     this.direction  = note.direction;
 }
示例#9
0
 public Note(NoteDirection dir, int t, string sfx, int s = 1, bool hold = false, float offX = 0, float offY = 0, float pitch = 0)
 {
     Direction   = dir;
     time        = t;
     sound       = sfx;
     noteSpeed   = s;
     held        = hold;
     camOffset   = new Vector2(offX, offY);
     pitchOffset = pitch;
 }
        private static ObjectMetadata GenerateObjectMetadata(
            Beatmap beatmap,
            CatchHitObject current,
            CatchHitObject next,
            NoteDirection lastDirection,
            double dashRange,
            double walkRange,
            double halfCatcherWidth,
            double baseWalkRange,
            double hyperdashLeniency,
            bool lastWasHyper
            )
        {
            var metadata = new ObjectMetadata {
                Direction = current.X == next.X ? NoteDirection.NONE : current.X > next.X ? NoteDirection.LEFT : NoteDirection.RIGHT,
                // 1/4th of a frame of grace time, taken from osu-stable
                TimeToNext         = next.ActualTime - current.ActualTime - 1000f / 60f / 4,
                DistanceInOsuCords = Math.Abs(next.X - current.X)
            };

            var bpmScale = beatmap.GetBpmScale(next);

            double actualWalkRange;

            if (lastWasHyper)
            {
                actualWalkRange = (lastDirection == metadata.Direction ? walkRange : baseWalkRange) *
                                  hyperdashLeniency;
            }
            else
            {
                actualWalkRange = lastDirection == metadata.Direction ? walkRange : baseWalkRange;
            }

            metadata.HyperDistanceToNext = metadata.DistanceInOsuCords - (lastDirection != NoteDirection.NONE || lastDirection == metadata.Direction ? dashRange : halfCatcherWidth);
            metadata.DashDistanceToNext  = metadata.DistanceInOsuCords - (lastDirection != NoteDirection.NONE ? actualWalkRange : baseWalkRange);
            metadata.DistanceToHyper     = (int)Math.Floor((float)(metadata.TimeToNext - metadata.HyperDistanceToNext));
            metadata.DistanceToDash      = (int)Math.Floor((float)(metadata.TimeToNext - metadata.DashDistanceToNext - (metadata.TimeToNext * (bpmScale * 0.3))));

            // Label the type of movement based on if the distance is dashable or walkable
            if (metadata.DistanceToHyper < 0)
            {
                metadata.MovementType = MovementType.HYPERDASH;
            }
            else if (metadata.DistanceToDash < 0)
            {
                metadata.MovementType = MovementType.DASH;
            }
            else
            {
                metadata.MovementType = MovementType.WALK;
            }

            return(metadata);
        }
示例#11
0
 private Bounds CreateChordNotes(NoteDirection noteDirection, ABC.Chord chord, Beam beam, ABC.Clef clef, GameObject container, Vector3 offset, ref Bounds totalBounds)
 {
     if (noteDirection == NoteDirection.Up)
     {
         return(CreateChordNotesUp(chord, beam, clef, container, offset, ref totalBounds));
     }
     else
     {
         return(CreateChordNotesDown(chord, beam, clef, container, offset, ref totalBounds));
     }
 }
示例#12
0
 private GameObject CreateNoteStaffMarkers(NoteDirection noteDirection, ABC.Note note, ABC.Clef clef, float position, ref Bounds totalBounds)
 {
     if (noteDirection == NoteDirection.Up)
     {
         return(CreateNoteStaffMarkersUp(note, clef, position, ref totalBounds));
     }
     else
     {
         return(CreateNoteStaffMarkersDown(note, clef, position, ref totalBounds));
     }
 }
示例#13
0
 private string GetNoteSpriteName(ABC.Length note, bool beam, NoteDirection noteDirection)
 {
     if (beam)
     {
         return($"Note_Quarter_{noteDirection}");
     }
     else
     {
         return(note == ABC.Length.Whole ? "Note_Whole" : $"Note_{note}_{noteDirection}");
     }
 }
示例#14
0
        public Note(UnityEngine.Vector3 pos, string idRoot = "", int idCmb = -1, NoteType t = NoteType.OneHandSpecial, NoteDirection d = NoteDirection.None)
        {
            if (idRoot != null)
            {
                Id = idRoot.ToString();
            }

            ComboId  = idCmb;
            Type     = t;
            Position = new float[3] {
                pos.x, pos.y, pos.z
            };
            Direction = d;
        }
示例#15
0
 private GameObject CreateChordStaffMarkers(NoteDirection noteDirection, ABC.Chord chord, ABC.Clef clef, float position, float offsetSize, ref Bounds totalBounds)
 {
     if (noteDirection == NoteDirection.Up)
     {
         return(CreateChordStaffMarkersUp(chord, clef, position, offsetSize, ref totalBounds));
     }
     else
     {
         if (ChordIsCompressed(chord, NoteDirection.Down))
         {
             position += offsetSize;
         }
         return(CreateChordStaffMarkersDown(chord, clef, position, -offsetSize, ref totalBounds));
     }
 }
示例#16
0
 private Vector3 DetermineNoteSpeed(NoteDirection direction)
 {
     if (direction == NoteDirection.Down)
     {
         return(new Vector3(0f, 0f, -noteSpeed));
     }
     else if (direction == NoteDirection.Left)
     {
         return(new Vector3(-noteSpeed, 0f, 0f));
     }
     else if (direction == NoteDirection.Up)
     {
         return(new Vector3(0f, 0f, noteSpeed));
     }
     else
     {
         return(new Vector3(noteSpeed, 0f, 0f));
     }
 }
示例#17
0
        private static ObjectMetadata GenerateObjectMetadata(
            CatchHitObject current,
            CatchHitObject next,
            NoteDirection lastDirection,
            double dashRange,
            double walkRange,
            double halfCatcherWidth
            )
        {
            var metadata = new ObjectMetadata {
                Direction = next.X > current.X ? NoteDirection.LEFT : NoteDirection.RIGHT,
                // 1/4th of a frame of grace time, taken from osu-stable
                TimeToNext         = next.time - current.time - 1000f / 60f / 4,
                DistanceInOsuCords = Math.Abs(next.X - current.X)
            };

            metadata.HyperDistanceToNext = metadata.DistanceInOsuCords - (lastDirection == metadata.Direction ? dashRange : halfCatcherWidth);
            metadata.DashDistanceToNext  = metadata.DistanceInOsuCords - (lastDirection == metadata.Direction ? walkRange : halfCatcherWidth / 2);
            metadata.DistanceToHyper     = (int)(metadata.TimeToNext - metadata.HyperDistanceToNext);
            // Greaper's : metadata.DistanceToDash = (int) (metadata.TimeToNext - metadata.DashDistanceToNext - (metadata.TimeToNext * 0.3));
            // Basically full walk - 30 counts as a dash according to data from salad diffs
            metadata.DistanceToDash = (int)(metadata.TimeToNext - metadata.DashDistanceToNext - (metadata.TimeToNext * 0.50) + 30);

            // Label the type of movement based on if the distance is dashable or walkable
            if (metadata.DistanceToHyper < 0)
            {
                metadata.MovementType = MovementType.HYPERDASH;
            }
            else if (metadata.DistanceToDash < 0)
            {
                metadata.MovementType = MovementType.DASH;
            }
            else
            {
                metadata.MovementType = MovementType.WALK;
            }

            return(metadata);
        }
示例#18
0
 private Vector3 DetermineSpawnPoint(NoteDirection direction)
 {
     if (direction == NoteDirection.Down)
     {
         topAnim.SetTrigger("Go");
         return(topSpawner.position);
     }
     else if (direction == NoteDirection.Left)
     {
         rightAnim.SetTrigger("Go");
         return(rightSideSpawner.position);
     }
     else if (direction == NoteDirection.Up)
     {
         bottomAnim.SetTrigger("Go");
         return(bottomSpawner.position);
     }
     else
     {
         leftAnim.SetTrigger("Go");
         return(leftSideSpawner.position);
     }
 }
示例#19
0
 public TypeNote DisplayRight()
 {
     _direction = NoteDirection.right;
     return this;
 }
示例#20
0
 public TypeNote DisplayLeft()
 {
     _direction = NoteDirection.left;
     return this;
 }
示例#21
0
        private Bounds AddChordNoteHead(ABC.Pitch value, ABC.Length length, ABC.Clef clef, NoteDirection noteDirection, GameObject container, Vector3 offset, ref Vector3 notePos)
        {
            int stepCount = value - clefZero[clef];

            notePos = offset + new Vector3(0.0f, noteStep * stepCount, 0.0f);

            var spriteName = length == ABC.Length.Whole ? "Note_Whole" : $"Chord_{length}";
            var dot        = spriteCache.GetSpriteObject(spriteName);

            dot.transform.parent        = container.transform;
            dot.transform.localPosition = notePos;

            return(dot.bounds);
        }
示例#22
0
 public override void NoteEffects(NoteDirection direction, float speed)
 {
 }
        public Candidates GetRightCandidates(NoteDirection direction, NotePosition position)
        {
            NoteDirection flippedDirection;
            NotePosition  flippedPosition;

            switch (direction)
            {
            case NoteDirection.Up:
                flippedDirection = NoteDirection.Up;
                break;

            case NoteDirection.UpRight:
                flippedDirection = NoteDirection.UpLeft;
                break;

            case NoteDirection.Right:
                flippedDirection = NoteDirection.Left;
                break;

            case NoteDirection.DownRight:
                flippedDirection = NoteDirection.DownLeft;
                break;

            case NoteDirection.Down:
                flippedDirection = NoteDirection.Down;
                break;

            case NoteDirection.DownLeft:
                flippedDirection = NoteDirection.DownRight;
                break;

            case NoteDirection.Left:
                flippedDirection = NoteDirection.Right;
                break;

            case NoteDirection.UpLeft:
                flippedDirection = NoteDirection.UpRight;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction));
            }
            switch (position)
            {
            case NotePosition.TopLeft:
                flippedPosition = NotePosition.TopRight;
                break;

            case NotePosition.TopCenterLeft:
                flippedPosition = NotePosition.TopCenterRight;
                break;

            case NotePosition.TopCenterRight:
                flippedPosition = NotePosition.TopCenterLeft;
                break;

            case NotePosition.TopRight:
                flippedPosition = NotePosition.TopLeft;
                break;

            case NotePosition.MiddleLeft:
                flippedPosition = NotePosition.MiddleRight;
                break;

            case NotePosition.MiddleCenterLeft:
                flippedPosition = NotePosition.MiddleCenterRight;
                break;

            case NotePosition.MiddleCenterRight:
                flippedPosition = NotePosition.MiddleCenterLeft;
                break;

            case NotePosition.MiddleRight:
                flippedPosition = NotePosition.MiddleLeft;
                break;

            case NotePosition.BottomLeft:
                flippedPosition = NotePosition.BottomRight;
                break;

            case NotePosition.BottomCenterLeft:
                flippedPosition = NotePosition.BottomCenterRight;
                break;

            case NotePosition.BottomCenterRight:
                flippedPosition = NotePosition.BottomCenterLeft;
                break;

            case NotePosition.BottomRight:
                flippedPosition = NotePosition.BottomLeft;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction));
            }
            var leftCandidates = GetLeftCandidates(flippedDirection, flippedPosition);

            return(leftCandidates.Flipped());
        }
示例#24
0
 public abstract void NoteEffects(NoteDirection direction, float speed);
示例#25
0
 public TypeNote DisplayTop()
 {
     _direction = NoteDirection.top;
     return this;
 }
示例#26
0
 public void Initialize(NoteButton button, NoteDirection direction, Vector3 noteSpeed)
 {
     this.Button    = button;
     this.Direction = direction;
     this.noteSpeed = noteSpeed;
 }
示例#27
0
 public TypeNote DisplayBottom()
 {
     _direction = NoteDirection.bottom;
     return(this);
 }
示例#28
0
 public TypeNote DisplayTop()
 {
     _direction = NoteDirection.top;
     return(this);
 }
示例#29
0
 public TypeNote DisplayRight()
 {
     _direction = NoteDirection.right;
     return(this);
 }
示例#30
0
 public TypeNote DisplayLeft()
 {
     _direction = NoteDirection.left;
     return(this);
 }
示例#31
0
        private NoteInfo CreateNote(ABC.Note note, ABC.Clef clef, int noteStepCount, Beam beam, NoteDirection noteDirection, IReadOnlyList <string> decorations, GameObject container)
        {
            var notePosition = new Vector3(0.0f, noteStep * noteStepCount, 0.0f);

            var totalBounds = new Bounds();

            totalBounds.SetMinMax(Vector3.zero, Vector3.zero);
            if (note.accidental != ABC.Accidental.Unspecified)
            {
                var accidental = spriteCache.GetSpriteObject($"Accidental_{note.accidental}");
                accidental.transform.parent        = container.transform;
                accidental.transform.localPosition = notePosition;

                totalBounds.Encapsulate(accidental.bounds);
                notePosition.x = totalBounds.size.x + accidentalOffset;
            }

            GameObject staffMarkers = null;

            if (NeedsStaffMarkers(noteStepCount))
            {
                staffMarkers  = CreateNoteStaffMarkers(noteDirection, note, clef, notePosition.x, ref totalBounds);
                notePosition += new Vector3(staffMarkerNoteOffset, 0.0f, 0.0f);
            }

            Bounds         rootItemBounds;
            SpriteRenderer rootItem = null;

            if (beam != null && beam.stemHeight != Beam.unspecifiedStemHeight)
            {
                var noteHead = spriteCache.GetSpriteObject("Chord_Quarter");
                noteHead.transform.parent        = container.transform;
                noteHead.transform.localPosition = notePosition;
                rootItemBounds = noteHead.bounds;

                rootItem = spriteCache.GetSpriteObject($"Note_Stem_{noteDirection}");
                rootItem.transform.parent = container.transform;

                var stemPos = notePosition + (noteDirection == NoteDirection.Up ? Beam.stemUpOffset : Beam.stemDownOffset);
                rootItem.transform.localPosition = stemPos;
                rootItem.transform.localScale    = new Vector3(1.0f, Mathf.Abs(beam.stemHeight - stemPos.y), 1.0f);
                rootItemBounds.Encapsulate(rootItem.bounds);
            }
            else
            {
                var spriteName = GetNoteSpriteName(note.length, note.beam != 0, noteDirection);
                rootItem = spriteCache.GetSpriteObject(spriteName);
                rootItem.transform.parent        = container.transform;
                rootItem.transform.localPosition = notePosition;

                rootItemBounds = rootItem.bounds;
            }

            totalBounds.Encapsulate(rootItemBounds);

            for (int i = 0; i < note.dotCount; i++)
            {
                float dotOffset = rootItemBounds.max.x + dotAdvance;
                var   dot       = CreateNoteDot(noteStepCount, container, dotOffset);
                totalBounds.Encapsulate(dot.bounds);
            }

            AddDecorations(note, decorations, rootItemBounds, container, ref totalBounds);

            if (staffMarkers != null)
            {
                staffMarkers.transform.parent = container.transform;
            }

            return(new NoteInfo(rootItemBounds, totalBounds));
        }
示例#32
0
 public TypeNote DisplayBottom()
 {
     _direction = NoteDirection.bottom;
     return this;
 }
示例#33
0
文件: Note.cs 项目: choukaweng/Rhythm
 public void InitializeNote(NoteDirection direction, GameObject notePrefab, Vector3 position, Quaternion rotation, Transform parent)
 {
     this.direction = direction;
     this.note      = notePrefab;
 }