コード例 #1
0
 /// <summary>
 /// Sets the note to inactive and returns it to the <see cref="NotePool"/>
 /// </summary>
 public void Delete()
 {
     State = NoteState.Destroyed;
     NotePool.Return(this);
 }
コード例 #2
0
        /// <summary>
        /// Rents a note from the <see cref="NotePool"/>, initializes it and returns it
        /// </summary>
        /// <param name="orderIndex">The note order</param>
        /// <param name="startTime">The time when the note was spawned</param>
        /// <param name="color">The notes color</param>
        /// <param name="hitTime">The time when the note should be hit</param>
        /// <param name="start">Spawn positon</param>
        /// <param name="hit">Position when note should be hit</param>
        /// <param name="destroy">Position when note should be destroyed</param>
        /// <param name="hitSize">The amount a note can be away from the <see cref="_hitPos"/> to be still valid to be hit</param>
        public static Note CreateNew(int orderIndex, float startTime, float hitTime, Vector3 start, Vector3 hit, Vector3 destroy, Vector3 hitSize,
                                     bool bigNote, Sprite defaultNoteSprite, Sprite defaultNoteOverlaySprite, NoteColor color)
        {
            Note n = NotePool.RentOne();

            if (n.transform.childCount == 0)
            {
                GameObject overlayChild = new GameObject();
                overlayChild.AddComponent <SpriteRenderer>().sprite = defaultNoteOverlaySprite;

                overlayChild.transform.SetParent(n.transform);
                overlayChild.transform.localPosition = Vector3.zero;
            }

            n.OrderIndex = orderIndex;
            n.Color      = color;

            n.StartTime = startTime;
            n.HitTime   = hitTime;
            n.HitSize   = hitSize;

            n._startPos   = start;
            n._hitPos     = hit;
            n._minHitPos  = new Vector3(hit.x - hitSize.x, hit.y, hit.z);
            n._maxHitPos  = new Vector3(hit.x + hitSize.x, hit.y, hit.z);
            n._destroyPos = destroy;

            n.State = NoteState.Spawned;

            if (bigNote)
            {
                n.transform.localScale = ActiveTaikoSettings.NoteScaleBig;
            }
            else
            {
                n.transform.localScale = ActiveTaikoSettings.NoteScaleNormal;
            }

            n.IsBigNote = bigNote;

            SpriteRenderer sr = n.GetComponent <SpriteRenderer>();

            switch (color)
            {
            default:
            case NoteColor.Red:
                sr.color = ActiveTaikoSettings.NoteColorRed;
                break;

            case NoteColor.Blue:
                sr.color = ActiveTaikoSettings.NoteColorBlue;
                break;

            case NoteColor.Yellow:
                sr.color = ActiveTaikoSettings.NoteColorYellow;
                break;
            }

            sr.sprite = defaultNoteSprite;

            Vector3 pos = start;

            pos.z = -1000f + orderIndex * .01f;

            n.transform.position = pos;
            n.gameObject.SetActive(true);
            return(n);
        }