Пример #1
0
        void Reset()
        {
            queItems.Clear();
            bd = null;
            bt = TBDatabase.GetBuildingType(7); //building.Type);
            bd = bt.GetDefine(1);               //building.Level);

            // delete old items of each content
            for (int j = rtUnitQueList.childCount - 1; j >= 0; j--)
            {
                Destroy(rtUnitQueList.GetChild(j).gameObject);
            }
            for (int i = 0; i < building.queUnitGen.Count; ++i)
            {
                GenQueItem item = building.queUnitGen[i];

                GameObject go = (GameObject)Instantiate(prefabUnitQueItem, Vector3.zero, Quaternion.identity);
                go.transform.SetParent(rtUnitQueList);
                go.transform.localScale = Vector3.one;
                RectTransform rt = go.GetComponent <RectTransform>();
                rt.anchoredPosition = new Vector2(i * -100, 0);

                UIUnitQueItem script = go.GetComponent <UIUnitQueItem>();
                script.Init(this, item);
                queItems.Add(script);
                Debug.Log("queItems.Add " + queItems.Count.ToString() + "unitID:" + item.unitID.ToString());
            }

            // delete old items of each content
            for (int j = rtUnitList.childCount - 1; j >= 0; j--)
            {
                Destroy(rtUnitList.GetChild(j).gameObject);
            }
            int sz = TBDatabase.GetArmyTypeCount();

            for (int i = 0; i < sz; ++i)
            {
                int col = i / 2;
                int row = i % 2;

                GameObject go = (GameObject)Instantiate(prefabUnitItem, Vector3.zero, Quaternion.identity);
                go.transform.SetParent(rtUnitList);
                go.transform.localScale = Vector3.one;
                RectTransform rt = go.GetComponent <RectTransform>();
                rt.anchoredPosition = new Vector2(col * 160, row * -160);

                UIUnitItem script = go.GetComponent <UIUnitItem>();
                script.Init(this, i);
            }
            rtUnitList.sizeDelta = new Vector3(160 * ((sz + 1) / 2), 310);
        }
Пример #2
0
        public void UnitGenAdd(int unitID)
        {
            Debug.Log("UnitCreate " + unitID.ToString());

            GenQueItem item = building.UnitGenAdd(unitID, 1);

            // search unit que list with given unit id
            int idx = queItems.FindIndex(x => x.item.unitID == unitID);

            Debug.Log("UnitCreate idx:" + idx.ToString());
            if (idx == -1)
            {
                GameObject go = (GameObject)Instantiate(prefabUnitQueItem, Vector3.zero, Quaternion.identity);
                go.transform.SetParent(rtUnitQueList);
                go.transform.localScale = Vector3.one;
                RectTransform rt = go.GetComponent <RectTransform>();
                rt.anchoredPosition = new Vector2(queItems.Count * -100, 0);

                UIUnitQueItem script = go.GetComponent <UIUnitQueItem>();
                script.Init(this, item);
                queItems.Add(script);
                Debug.Log("queItems.Add " + queItems.Count.ToString() + "unitID:" + item.unitID.ToString());
            }
        }