예제 #1
0
        // check tiles of building is vacant and set color of grid object
        public void CheckLandable()
        {
            bool IsVacant = ground.IsVacant(tilePos, tileSize);

            Debug.Log("CheckLandable Vacant" + IsVacant.ToString());
            Color clrTemp = IsVacant ? new Color(0, 1, 0, 0.5f) : new Color(1, 0, 0, 0.5f);

            BEUtil.SetObjectColor(goGrid, "_TintColor", clrTemp);
            Landable = IsVacant;
        }
예제 #2
0
        public void Land(bool landed, bool animate)
        {
            if (Landed == landed)
            {
                return;
            }

            if (landed && !Landable)
            {
                if (((int)tilePosOld.x == -1) && ((int)tilePosOld.y == -1))
                {
                    return;
                }

                tilePos = tilePosOld;
                //Debug.Log ("Land RecoverOldPos: "+TilePosOldX.ToString()+","+TilePosOldY.ToString());
                ground.Move(gameObject, tilePos, tileSize);
                CheckLandable();

                if (!Landable)
                {
                    return;
                }
            }

            Landed = landed;
            ground.OccupySet(this);

            if (!Landed)
            {
                tilePosOld = tilePos;
                //Debug.Log ("Land Save OldPos: "+TilePosOldX.ToString()+","+TilePosOldY.ToString());
            }
            else
            {
                if (!OnceLanded)
                {
                    OnceLanded = true;
                }
            }

            CheckLandable();
            goGrid.SetActive(Landed ? false : true);
            if (goArrowRoot != null)
            {
                goArrowRoot.SetActive(Landed ? false : true);
            }

            if (uiInfo != null)
            {
                //uiInfo.groupProgress.alpha = 0;

                if (animate)
                {
                    if (Landed)
                    {
                        BETween.alpha(uiInfo.groupInfo.gameObject, 0.1f, 1.0f, 0.0f);
                        BETween.enable(uiInfo.groupInfo.gameObject, 0.1f, true, false);
                    }
                    else
                    {
                        BETween.alpha(uiInfo.groupInfo.gameObject, 0.1f, 0.0f, 1.0f);
                        uiInfo.groupInfo.gameObject.SetActive(true);
                    }
                }
                else
                {
                    uiInfo.groupInfo.alpha = Landed ? 0 : 1;
                    uiInfo.groupInfo.gameObject.SetActive(Landed ? false : true);
                }
            }

            // if building is wall, check neighbor
            if (Type == 2)
            {
                CheckNeighbor();
            }

            if (Landed && (goCenter != null))
            {
                SceneTown.instance.Save();
                BEUtil.SetObjectColor(goCenter, Color.white);
                BEUtil.SetObjectColor(goXInc, Color.white);
                BEUtil.SetObjectColor(goZInc, Color.white);
            }

            UpjustYByState();
            if (!SceneTown.instance.InLoading && (BEWorkerManager.instance != null))
            {
                BEWorkerManager.instance.OnTileInfoChanged();
            }
        }
예제 #3
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);
        }