Пример #1
0
        public void RetargetList(BuildItemContainer buildingContainer)
        {
            objPlacer = GetComponent <ObjectPlacer>();
            activeKey = objPlacer.ToggleKey;
            if (BuilderMenuPrefab == null)
            {
                Debug.LogError("Missing BuilderMenuPrefab, please assign it!");
                return;
            }
            if (buildObjectList == null)
            {
                Debug.LogError("Missing buildObjectList, please assign it!");
                return;
            }

            //Transform parent = PlayerInterface.Instance.gameObject.transform;
            builderUI = Instantiate(BuilderMenuPrefab).GetComponentInChildren <IItemSelectionUI>(); //create the ui
            if (builderUI == null)
            {
                Debug.LogError("Please make sure that the UI prefab has one script that implements: IItemSlectionUI interface");
                return;
            }

            builderUI.Populatemenu(buildObjectList, this); //populate it

            if (!buildObjectList.isValid())
            {
                //Debug.LogError("Please add some some Items to list");
                return;
            }
        }
Пример #2
0
        /****************************************************
         * UI generation
         * *************************************************/

        /// <summary>
        /// Create the buttons for all the elements
        /// </summary>
        /// <param name="container">Item list</param>
        /// <param name="selector">Object Selector Script referenct for callbacks</param>
        public void Populatemenu(BuildItemContainer container, ObjectSelector selector)
        {
            this.selector = selector;

            for (int i = 0; i < container.items.Count; i++)
            {
                var item = Instantiate(objPrefab, ButtonsParent).GetComponent <BuilderObjectUI>();
                //reset position and scale of the instantiated item
                RectTransform rt = item.GetComponent <RectTransform>();
                rt.localScale    = Vector3.one;
                rt.localPosition = Vector3.zero;
                //setup content
                item.SetUp(container.items[i]);
                item.AddButtonListner(selector.UseItem, i);

                if (i == 0) //select the first button
                {
                    SetSelectedItem(item);
                }
            }
        }