Пример #1
0
        //
        public void UnitGenUpdate(float deltaTime)
        {
            for (int i = 0; i < queUnitGen.Count; ++i)
            {
                GenQueItem item = queUnitGen[i];
                if (item.Count == 0)
                {
                    //Debug.Log ("Building::UnitGenUpdate delete "+item.unitID.ToString());
                    UIDialogTraining.instance.ItemRemove(item.unitID);
                    queUnitGen.RemoveAt(i);
                    break;
                }
            }

            while (queUnitGen.Count > 0)
            {
                GenQueItem item = queUnitGen[0];
                deltaTime = item.Update(deltaTime);
                if (item.Count == 0)
                {
                    //Debug.Log ("Building::UnitGenUpdate delete "+item.unitID.ToString());
                    UIDialogTraining.instance.ItemRemove(item.unitID);
                    queUnitGen.RemoveAt(0);
                }

                if (deltaTime < 0.01f)
                {
                    return;
                }
            }
        }
Пример #2
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);
        }
Пример #3
0
        // load building info to xml format
        public void Load(XmlElement e)
        {
            Type      = int.Parse(e.GetAttribute("Type"));
            Level     = int.Parse(e.GetAttribute("Level"));
            tilePos.x = float.Parse(e.GetAttribute("TilePosX"));
            tilePos.y = float.Parse(e.GetAttribute("TilePosY"));

            InUpgrade        = bool.Parse(e.GetAttribute("InUpgrade"));
            UpgradeCompleted = bool.Parse(e.GetAttribute("UpgradeCompleted"));
            UpgradeTimeLeft  = float.Parse(e.GetAttribute("UpgradeTimeLeft"));

            Production = float.Parse(e.GetAttribute("Production"));

            ground.Move(gameObject, tilePos, tileSize);
            CheckLandable();
            Land(true, false);

            for (int i = 0; i < 10; ++i)
            {
                GenUnitCount[i] = 0;
            }

            queUnitGen.Clear();

            XmlNodeList list = e.ChildNodes;

            foreach (XmlElement ele in list)
            {
                if (ele.Name == "Unit")
                {
                    int type  = int.Parse(ele.GetAttribute("Type"));
                    int Count = int.Parse(ele.GetAttribute("Count"));
                    GenUnitCount[type] = Count;
                }
                else if (ele.Name == "GenQue")
                {
                    int   unitID   = int.Parse(ele.GetAttribute("unitID"));
                    int   Count    = int.Parse(ele.GetAttribute("Count"));
                    float timeLeft = float.Parse(ele.GetAttribute("timeLeft"));

                    GenQueItem item = UnitGenAdd(unitID, Count);
                    item.timeLeft = timeLeft;
                }
                else
                {
                }
            }
        }
Пример #4
0
        // save building info to xml format
        public void Save(XmlDocument d)
        {
            XmlElement ne = d.CreateElement("Building");

            ne.SetAttribute("Type", Type.ToString());
            ne.SetAttribute("Level", Level.ToString());
            ne.SetAttribute("TilePosX", tilePos.x.ToString());
            ne.SetAttribute("TilePosY", tilePos.y.ToString());

            ne.SetAttribute("InUpgrade", InUpgrade.ToString());
            ne.SetAttribute("UpgradeCompleted", UpgradeCompleted.ToString());
            ne.SetAttribute("UpgradeTimeLeft", UpgradeTimeLeft.ToString());

            ne.SetAttribute("Production", Production.ToString());

            d.DocumentElement.AppendChild(ne);

            // if barrack
            if (Type == 7)
            {
                for (int i = 0; i < queUnitGen.Count; ++i)
                {
                    GenQueItem item   = queUnitGen[i];
                    XmlElement neUnit = d.CreateElement("GenQue");
                    neUnit.SetAttribute("unitID", item.unitID.ToString());
                    neUnit.SetAttribute("Count", item.Count.ToString());
                    neUnit.SetAttribute("timeLeft", item.timeLeft.ToString());
                    ne.AppendChild(neUnit);
                }
            }
            // if army camp
            else if (Type == 8)
            {
                for (int i = 0; i < 10; ++i)
                {
                    XmlElement neUnit = d.CreateElement("Unit");
                    neUnit.SetAttribute("Type", i.ToString());
                    neUnit.SetAttribute("Count", GenUnitCount[i].ToString());
                    ne.AppendChild(neUnit);
                }
            }
            else
            {
            }
        }
Пример #5
0
        // if user cancel training unit, decrease count of training unit
        public bool UnitGenRemove(int unitID, int Count)
        {
            //Debug.Log ("Building::UnitGenAdd "+unitID.ToString()+"x"+Count.ToString());
            // search unit que list with given unit id
            int idx = queUnitGen.FindIndex(x => x.unitID == unitID);

            if (idx != -1)
            {
                GenQueItem item = queUnitGen[idx];
                item.Count -= Count;
                //Debug.Log ("Building::UnitGenRemove decrease unitID:"+unitID.ToString()+" Count:"+item.Count.ToString());
                if (item.Count < 0)
                {
                    item.Count = 0;
                }
                return(false);
            }

            //Debug.Log ("Building::UnitGenRemove decrease unitID:"+unitID.ToString()+" Not Found");
            return(false);
        }
Пример #6
0
        // if building can training unit
        // add unit to training aue
        public GenQueItem UnitGenAdd(int unitID, int Count)
        {
            //Debug.Log ("Building::UnitGenAdd "+unitID.ToString()+"x"+Count.ToString());
            // search unit que list with given unit id
            int idx = queUnitGen.FindIndex(x => x.unitID == unitID);

            if (idx == -1)
            {
                GenQueItem item = new GenQueItem(this, unitID, Count);
                queUnitGen.Add(item);
                //Debug.Log ("Building::UnitGenAdd create GenQueItem unitID:"+unitID.ToString());
                return(item);
            }
            else
            {
                GenQueItem item = queUnitGen[idx];
                item.Count += Count;
                //Debug.Log ("Building::UnitGenAdd increase GenQueItem unitID:"+unitID.ToString()+" Count:"+item.Count.ToString());
                return(item);
            }
        }
Пример #7
0
        void Update()
        {
            if (!UIDialogMessage.IsShow() && Input.GetKeyDown(KeyCode.Escape))
            {
                _Hide();
            }

            int GenCountTotal = 0;
            int GenTimeTotal  = 0;

            for (int i = 0; i < building.queUnitGen.Count; ++i)
            {
                GenQueItem item = building.queUnitGen[i];
                GenCountTotal += item.Count;
                GenTimeTotal  += item.GetGenLeftTime();
            }

            TrainingInfo.text = "Train Troops " + GenCountTotal.ToString() + "/" + bd.TrainingQueueMax.ToString();
            CapacityInfo.text = "Troop capacity after training: 51 / 200";
            TimeLeft.text     = BENumber.SecToString(GenTimeTotal);
            GemCount.text     = "10,000";
        }
Пример #8
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());
            }
        }
Пример #9
0
 public void UnitGenRemove(GenQueItem item)
 {
     item.Count -= 1;
 }
Пример #10
0
 public void Init(UIDialogTraining _uiTraining, GenQueItem _item)
 {
     uiTraining  = _uiTraining;
     item        = _item;
     Initialized = true;
 }