public static BENumber Gold; // total gold number void Awake() { instance = this; Gold = new BENumber(BENumber.IncType.VALUE, "#,##0.00", 0, 10000000000, 2000); // default user gold id 2000 //PlayerPrefs.DeleteAll(); Load(); }
void Awake() { instance = this; // initialize BENumber class and set ui element Exp = new BENumber(BENumber.IncType.VALUE, 0, 100000000, 0); Exp.AddUIImage(BEUtil.GetObject("PanelOverlay/LabelExp/Fill").GetComponent <Image>()); Gold = new BENumber(BENumber.IncType.VALUE, 0, 200000, 10000); // initial gold count is 1000 Gold.AddUIText(BEUtil.GetObject("PanelOverlay/LabelGold/Text").GetComponent <Text>()); Gold.AddUIImage(BEUtil.GetObject("PanelOverlay/LabelGold/Fill").GetComponent <Image>()); Elixir = new BENumber(BENumber.IncType.VALUE, 0, 300000, 10000); // initial elixir count is 1000 Elixir.AddUIText(BEUtil.GetObject("PanelOverlay/LabelElixir/Text").GetComponent <Text>()); Elixir.AddUIImage(BEUtil.GetObject("PanelOverlay/LabelElixir/Fill").GetComponent <Image>()); Gem = new BENumber(BENumber.IncType.VALUE, 0, 100000000, 1000); // initial gem count is 100 0 Gem.AddUIText(BEUtil.GetObject("PanelOverlay/LabelGem/Text").GetComponent <Text>()); HouseInfo = BEUtil.GetObject("PanelOverlay/LabelHouse/Text").GetComponent <Text>(); Shield = new BENumber(BENumber.IncType.TIME, 0, 100000000, 0); Shield.AddUIText(BEUtil.GetObject("PanelOverlay/LabelShield/Text").GetComponent <Text>()); // For camera fade animation, set cameras initial positions goCameraRoot.transform.position = new Vector3(-5.5f, 0, -5); goCamera.transform.localPosition = new Vector3(0, 0, -128.0f); InFade = true; // 游戏开始时放大 FadeAge = 0.0f; }
// start upgrade public bool Upgrade() { if (InUpgrade) { return(false); } if (bt.LevelMax <= Level) { return(false); } if (defNext == null) { return(false); } // check whether user has enough resources or not // decrease user's resource PayType payTypeReturn = PayforBuild(defNext); if (payTypeReturn != PayType.None) { if (payTypeReturn == PayType.Gold) { UIDialogMessage.Show("Insufficient Gold", "Ok", "Error"); } else if (payTypeReturn == PayType.Elixir) { UIDialogMessage.Show("Insufficient Elixir", "Ok", "Error"); } else if (payTypeReturn == PayType.Gem) { UIDialogMessage.Show("Insufficient Gem", "Ok", "Error"); } else { } return(false); } // prepare upgrade UpgradeCompleted = false; InUpgrade = true; // if upgrade time is zero(like wall) then upgrade immediately if (UpgradeTimeTotal > 0) { UpgradeTimeLeft = UpgradeTimeTotal; uiInfo.TimeLeft.text = BENumber.SecToString(Mathf.CeilToInt(UpgradeTimeLeft)); uiInfo.Progress.fillAmount = (UpgradeTimeTotal - UpgradeTimeLeft) / UpgradeTimeTotal; BETween.alpha(uiInfo.groupProgress.gameObject, 0.3f, 0.0f, 1.0f); uiInfo.groupProgress.gameObject.SetActive(true); } else { UpgradeEnd(); } return(true); }
void Update() { if (!Initialized) { return; } // show progress and left time Progress.fillAmount = ((float)item.at.TrainingTime - item.timeLeft) / (float)item.at.TrainingTime; TimeLeft.text = BENumber.SecToString((int)item.timeLeft); Count.text = item.Count.ToString() + "x"; }
void Start() { // set range of numbers and type BESetting.Gold.AddUIText(textGold); Win = new BENumber(BENumber.IncType.VALUE, "#,##0.00", 0, 10000000000, 0); Win.AddUIText(textTotalWin); //set saved user gold count to slotgame Slot.Gold = (float)BESetting.Gold.Target(); //set win value to zero Win.ChangeTo(0); UpdateUI(); //double button show only user win btnDouble.gameObject.SetActive(false); textInfo.text = ""; }
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"; }
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); }
// initialize with building public void Init(BuildingType _bt) { bt = _bt; Name.text = bt.Name; Info.text = bt.Info; // check if current building count of this type is larger then max count int CountMax = (_bt.ID == 1) ? 5 : BEGround.instance.GetBuildingCountMax(bt.ID); int Count = BEGround.instance.GetBuildingCount(bt.ID); if (Count >= CountMax) { // if can't create more building CountAvailable = false; // get next available townhall level int NextTownLevel = bt.GetMoreBuildTownLevel(Count); if (NextTownLevel == -1) { DisabledInfo.text = "Reach Maximum Count"; } else { DisabledInfo.text = "Upgrade Town Hall to level " + NextTownLevel.ToString() + " to build more"; } goDisabled.SetActive(true); } bd = bt.Defs[0]; // if building type is house (house's price is related to current house count) // change price if (_bt.ID == 1) { if (Count == 1) { bd.BuildGemPrice = 400; } else if (Count == 2) { bd.BuildGemPrice = 800; } else if (Count == 3) { bd.BuildGemPrice = 1600; } else if (Count == 4) { bd.BuildGemPrice = 3200; } else { } } // set ui info bd.PriceInfoApply(PriceIcon, Price); BuildTimeInfo.text = "Build time:"; BuildTime.text = BENumber.SecToString(bd.BuildTime); BuildCountInfo.text = "Built:"; BuildCount.text = Count.ToString() + "/" + CountMax.ToString(); Border.color = CountAvailable ? new Color32(0, 150, 186, 255) : new Color32(133, 119, 108, 255); Icon.sprite = Resources.Load <Sprite>("Icons/Building/" + bt.Name); Icon.color = CountAvailable ? new Color32(255, 255, 255, 255) : new Color32(133, 119, 108, 255); }
void Reset() { //bd = null; bt = TBDatabase.GetBuildingType(building.Type); //bd = bt.GetDefine(building.Level); bdNext = bt.GetDefine(building.Level + 1); //bdLast = bt.GetDefLast(); textTitle.text = "Upgrade " + bt.Name + " to Level " + (building.Level + 1).ToString() + " ?"; imgIcon.sprite = Resources.Load <Sprite>("Icons/Building/" + bt.Name); for (int i = 0; i < progresses.Length; ++i) { progresses[i].gameObject.SetActive(true); } // display progresses of building by building type if (bt.ID == 0) { // incase building si town hall, show gold capacity, elixir capacit and hitpoint building.UIFillProgressWithNext(progresses[0], BDInfo.CapacityGold); building.UIFillProgressWithNext(progresses[1], BDInfo.CapacityElixir); building.UIFillProgressWithNext(progresses[2], BDInfo.HitPoint); } else if (bt.ID == 1) { // incase building is house, only show hitpoint, and disable other progresses building.UIFillProgressWithNext(progresses[0], BDInfo.HitPoint); progresses[1].gameObject.SetActive(false); progresses[2].gameObject.SetActive(false); } else if (bt.ID == 2) { building.UIFillProgressWithNext(progresses[0], BDInfo.HitPoint); progresses[1].gameObject.SetActive(false); progresses[2].gameObject.SetActive(false); } else if ((bt.ID == 3) || (bt.ID == 4)) { building.UIFillProgressWithNext(progresses[0], BDInfo.Capacity); building.UIFillProgressWithNext(progresses[1], BDInfo.ProductionRate); building.UIFillProgressWithNext(progresses[2], BDInfo.HitPoint); } else if ((bt.ID == 5) || (bt.ID == 6)) { building.UIFillProgressWithNext(progresses[0], BDInfo.StorageCapacity); building.UIFillProgressWithNext(progresses[1], BDInfo.HitPoint); progresses[2].gameObject.SetActive(false); } else if (bt.ID == 7) { //"Training Capacity : 0/20"; //"HitPoint" } else if (bt.ID == 8) { //"Total troop Capacity : 0/20"; //"HitPoint" // show troops icon (click to remove unit) "Remove Troops?" } else if (bt.ID == 9) { //"Damage per second:15"; //"HitPoint" //Range : 9 Tiles //Damage Type: Single Target //Targets: Ground //Favorite target: Any } else if (bt.ID == 10) { } else { } // get townhall to check upgrade requires next townhall Building buildingTown = BEGround.instance.Buildings[0][0]; if (bdNext.TownHallLevelRequired > buildingTown.Level) { goNote.SetActive(true); NoteInfo.text = "To upgrade this building, you first need\n Town Hall Level " + bdNext.TownHallLevelRequired.ToString() + "!"; TownLevelOk = false; goNormal.SetActive(false); } else { goNote.SetActive(false); TownLevelOk = true; goNormal.SetActive(true); // set infos about upgrade bdNext.PriceInfoApply(PriceIcon, Price); textBuildTime.text = BENumber.SecToString(bdNext.BuildTime); GemCount = (bdNext.BuildTime + 1) / 60; // 1 gem per minute PriceGem.text = GemCount.ToString("#,##0"); PriceGem.color = (SceneTown.Gem.Target() < GemCount) ? Color.red : Color.white; } }