Exemple #1
0
        void Update()
        {
            // use BETime to revise times
            float deltaTime = BETime.deltaTime;

            // if building is in selected state, keep color animation
            if (!Landed && (goCenter != null))
            {
                float fColor  = Mathf.PingPong(Time.time * 1.5f, 1) * 0.5f + 0.5f;
                Color clrTemp = new Color(fColor, fColor, fColor, 1);
                BEUtil.SetObjectColor(goCenter, clrTemp);
                BEUtil.SetObjectColor(goXInc, clrTemp);
                BEUtil.SetObjectColor(goZInc, clrTemp);
            }

            // if building can produce resources
            if (Landed && !InUpgrade && (def != null) && (def.eProductionType != PayType.None))
            {
                Production += (float)def.ProductionRate * deltaTime;

                // check maximum capacity
                if ((int)Production >= def.Capacity[(int)def.eProductionType])
                {
                    Production = def.Capacity[(int)def.eProductionType];
                }

                // is minimum resources generated, then ser collectable flagand show dialog
                if (((int)Production >= 10) && !uiInfo.groupCollect.gameObject.activeInHierarchy)
                {
                    Collectable = true;
                    uiInfo.CollectIcon.sprite = TBDatabase.GetPayTypeIcon(def.eProductionType);
                    BETween.alpha(uiInfo.groupCollect.gameObject, 0.2f, 0.0f, 1.0f);
                    uiInfo.groupCollect.gameObject.SetActive(true);
                    uiInfo.groupInfo.gameObject.SetActive(false);
                }

                if (Collectable)
                {
                    // when production count is reach to max count, then change dialog color to red
                    uiInfo.CollectDialog.color = (Production == def.Capacity[(int)def.eProductionType]) ? Color.red : Color.white;
                }
            }

            // if in upgrade
            if (InUpgrade)
            {
                // if upgrading proceed
                if (!UpgradeCompleted)
                {
                    // decrease left time
                    UpgradeTimeLeft -= deltaTime;

                    // if upgrading done
                    if (UpgradeTimeLeft < 0.0f)
                    {
                        UpgradeTimeLeft  = 0.0f;
                        UpgradeCompleted = true;

                        // if building is selected, then update command dialog
                        if (UICommand.Visible && (SceneTown.buildingSelected == this))
                        {
                            UICommand.Show(this);
                        }
                    }
                }

                // update ui info
                uiInfo.TimeLeft.text       = UpgradeCompleted ? "Completed!" : BENumber.SecToString(Mathf.CeilToInt(UpgradeTimeLeft));
                uiInfo.Progress.fillAmount = (UpgradeTimeTotal - UpgradeTimeLeft) / UpgradeTimeTotal;
                uiInfo.groupProgress.alpha = 1;
                uiInfo.groupProgress.gameObject.SetActive(true);
            }

            UnitGenUpdate(deltaTime);
        }