Пример #1
0
        void RenderConnectorBar(int lineNum)
        {
            var barSprite = cache.GetSpriteObject("Bar_Line");

            barSprite.transform.parent = scoreContainer.transform;

            var topScoreLine    = layouts[0].scoreLines[lineNum];
            var bottomScoreLine = layouts[layouts.Count - 1].scoreLines[lineNum];

            var barPos = bottomScoreLine.container.transform.localPosition;
            var topPos = topScoreLine.container.transform.localPosition.y + staffHeight;

            var targetHeight = topPos - barPos.y;
            var scale        = targetHeight / barSprite.bounds.size.y;

            barSprite.transform.localPosition = barPos;
            barSprite.transform.localScale    = new Vector3(1.0f, scale, 1.0f);
        }
Пример #2
0
        /// <summary>
        /// Creates a basic straight beam connecting the first and last item in this beam.
        /// Note that this method should be used when the first and last items have the same max Y bounding value.
        /// </summary>
        public bool CreateBasicBeam(SpriteCache cache, GameObject container)
        {
            if (type != Type.Basic && type != Type.Straight)
            {
                return(false);
            }

            float offsetY = 0.0f;

            ABC.Length length = (items[0] as ABC.Duration).length;

            for (ABC.Length l = ABC.Length.Eighth; l >= length; l--)
            {
                var beam = cache.GetSpriteObject($"Note_Beam_{noteDirection}");
                beam.transform.parent = container.transform;

                float distX;
                if (noteDirection == NoteCreator.NoteDirection.Up)
                {
                    var beamPos = first.max;
                    beam.transform.localPosition = new Vector3(beamPos.x, beamPos.y - offsetY, 0.0f);

                    distX = last.max.x - beamPos.x;
                }
                else
                {
                    var beamPos = first.min;
                    beam.transform.localPosition = new Vector3(beamPos.x, beamPos.y + offsetY, 0.0f);

                    distX = last.min.x - beamPos.x;
                }

                beam.transform.localScale = new Vector3(distX, 1.0f, 1.0f);

                offsetY += beamHeight + defaultBeamSpacer;
            }

            return(true);
        }
Пример #3
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));
        }