protected override void Awake() { base.Awake(); if (data == null) { throw new DataException <ChordEditor>(); } if (ChordsUpdated == null) { ChordsUpdated = new ChordAttachedToSlotEvent(); } var prefabSprite = data.ChordSlotPrefab.GetComponent <SpriteRenderer>(); chordSize = prefabSprite.bounds.size; grid.cellSize = chordSize; grid.transform.localPosition = new Vector2(0, -chordSize.y / 2); bounds = new BoundsInt(-slotsAmount / 2 - slotsAmount % 2, 0, 0, slotsAmount, 2, 0); InstantiateSlots(); InitPointer(new Vector3Int(bounds.xMin, -1, 0)); spriteRenderer.size = new Vector2(chordSize.x * slotsAmount + 2 * data.ContentMargin, spriteRenderer.size.y); }
private void Awake() { if (ChordAttached == null) { ChordAttached = new ChordAttachedToSlotEvent(); } }
private void InstantiateSlots() { if (ChordsUpdated == null) { ChordsUpdated = new ChordAttachedToSlotEvent(); } slots = new List <ChordSlot>(); for (int i = bounds.xMin; i < bounds.xMax; ++i) { ChordSlot slot = ChordSlot.Instantiate(data.ChordSlotPrefab, grid.transform, grid.GetCellCenterLocal(new Vector3Int(i, 0, 0)), data.ChordPrefab, this); slot.ChordAttached.AddListener(ChordsUpdated.Invoke); slots.Add(slot); } }