示例#1
0
        private PooledButton PlaceButton(int i, int j, BuildingMenuPool pool)//returns a button
        {
            PooledButton pooledButton = pool.Get();

            pooledButton.gameObject.SetActive(true);
            RectTransform rectTransform;

            (rectTransform = pooledButton.GetComponent <RectTransform>()).SetParent(_contentHolderRect);
            rectTransform.sizeDelta        = new Vector2(_buttonSize, _buttonSize);
            rectTransform.localScale       = Vector3.one;
            rectTransform.anchoredPosition =
                new Vector2(
                    j * (_buttonSize + _spacing) + _spacing / 2 + _buttonSize / 2,
                    i * (_buttonSize + _spacing)
                    );

            pooledButton.MyPool = pool;
            return(pooledButton);
        }
示例#2
0
        private void Awake()
        {
            _buttonTable  = new SortedDictionary <int, List <PooledButton> >();
            _menuPoolList = new List <BuildingMenuPool>();

            if (pooledMenuButtons.Count > 0) //if there is a given buttons create pools for this buttons
            {
                foreach (var button in pooledMenuButtons)
                {
                    BuildingMenuPool menuPool = new BuildingMenuPool(button);
                    _menuPoolList.Add(menuPool);
                }
            }
            // else {DestroyImmediate(this);}

            _resolution     = new Vector2(Screen.width, Screen.height); // get res to set sizes
            _thisScrollRect = GetComponent <ScrollRect>();
            _thisScrollRect.onValueChanged.AddListener(SliderMoved);

            _contentHolderRect = _thisScrollRect.content;
        }