Esempio n. 1
0
    // Use this for initialization
    void Awake()
    {
        RectTransform tempRect;
        float         offsetX = (1f - amountX * width) / (amountX + 1);
        float         offsetY = (1f - amountY * heigth) / (amountY + 1);

        for (int y = 0; y < amountY; ++y)
        {
            for (int x = 0; x < amountX; ++x)
            {
                tempRect = Instantiate(uiPrefab).GetComponent <RectTransform>();
                tempRect.SetParent(transform, false);
                tempRect.anchorMin = new Vector2(offsetX + x * width + x * offsetX,
                                                 offsetY + y * heigth + y * offsetY);
                tempRect.anchorMax = new Vector2(tempRect.anchorMin.x + width,
                                                 tempRect.anchorMin.y + heigth);
                tempRect.anchoredPosition = Vector2.zero;
                IIndexable indexable = tempRect.GetComponent(typeof(IIndexable)) as IIndexable;
                if (indexable != null)
                {
                    indexable.Index = x + (amountY - 1 - y) * (amountX);
                }
                if (indexable is IUnitUI)
                {
                    IUnitUI temp = (IUnitUI)indexable;
                    temp.TroopLocation = unitLocation;
                }
                if (indexable is IItemUI)
                {
                    IItemUI temp = (IItemUI)indexable;
                    temp.ItemLocation = itemLocation;
                }
            }
        }
    }
Esempio n. 2
0
        private void Awake()
        {
            _iconIsNull = !TryGetComponent(out _icon);

            _emitter = GetComponentInChildren <IEmitterUI>();
            if (_emitter != null)
            {
                _emitterIsNull = false;
            }

            _itemUI = GetComponentInChildren <IItemUI>();
            if (_itemUI != null)
            {
                _itemUIIsNull = false;
            }

            _outline = GetComponentInChildren <IOutlineComponent>(true);
            if (_outline != null)
            {
                _outlineIsNull = false;
            }

            GetRectTransform = GetComponent <RectTransform>();
        }