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; }
public void Save() { string xmlFilePath = BEUtil.pathForDocumentsFile(dbFilename); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml("<Database><name>wrench</name></Database>"); { xmlDocument.DocumentElement.RemoveAll(); // Version { XmlElement ne = xmlDocument.CreateElement("ConfigVersion"); ne.SetAttribute("value", ConfigVersion.ToString()); xmlDocument.DocumentElement.AppendChild(ne); } XmlElement buildingRoot = xmlDocument.CreateElement("Building"); xmlDocument.DocumentElement.AppendChild(buildingRoot); foreach (BuildingType bt in Buildings) { bt.Save(xmlDocument, buildingRoot); } // ####### Encrypt the XML ####### // If you want to view the original xml file, turn of this piece of code and press play. if (xmlDocument.DocumentElement.ChildNodes.Count >= 1) { xmlDocument.Save(xmlFilePath); } // ############################### } }
// 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; }
// Do not save town when script quit. // save when action is occured // (for example, when building created, when start upgrade, when colled product, when training start) public void Save() { if (InLoading) { return; } string xmlFilePath = BEUtil.pathForDocumentsFile(configFilename); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml("<item><name>wrench</name></item>"); { xmlDocument.DocumentElement.RemoveAll(); // Version { XmlElement ne = xmlDocument.CreateElement("ConfigVersion"); ne.SetAttribute("value", ConfigVersion.ToString()); xmlDocument.DocumentElement.AppendChild(ne); } { XmlElement ne = xmlDocument.CreateElement("Time"); ne.SetAttribute("value", DateTime.Now.ToString()); xmlDocument.DocumentElement.AppendChild(ne); } { XmlElement ne = xmlDocument.CreateElement("ExpTotal"); ne.SetAttribute("value", ExpTotal.ToString()); xmlDocument.DocumentElement.AppendChild(ne); } { XmlElement ne = xmlDocument.CreateElement("Gem"); ne.SetAttribute("value", Gem.Target().ToString()); xmlDocument.DocumentElement.AppendChild(ne); } { XmlElement ne = xmlDocument.CreateElement("Gold"); ne.SetAttribute("value", Gold.Target().ToString()); xmlDocument.DocumentElement.AppendChild(ne); } { XmlElement ne = xmlDocument.CreateElement("Elixir"); ne.SetAttribute("value", Elixir.Target().ToString()); xmlDocument.DocumentElement.AppendChild(ne); } { XmlElement ne = xmlDocument.CreateElement("Shield"); ne.SetAttribute("value", Shield.Target().ToString()); xmlDocument.DocumentElement.AppendChild(ne); } Transform trDecoRoot = BEGround.instance.trDecoRoot; //List<GameObject> goTiles=new List<GameObject>(); foreach (Transform child in trDecoRoot) { Building script = child.gameObject.GetComponent <Building>(); if (script != null) { script.Save(xmlDocument); } } // ####### Encrypt the XML ####### // If you want to view the original xml file, turn of this piece of code and press play. if (xmlDocument.DocumentElement.ChildNodes.Count >= 1) { if (UseEncryption) { string data = BEUtil.Encrypt(xmlDocument.DocumentElement.InnerXml); xmlDocument.DocumentElement.RemoveAll(); xmlDocument.DocumentElement.InnerText = data; } xmlDocument.Save(xmlFilePath); } // ############################### } }
public void Load() { string xmlFilePath = BEUtil.pathForDocumentsFile(configFilename); if (!File.Exists(xmlFilePath)) { Save(); bFirstRun = true; } else { bFirstRun = false; } InLoading = true; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(xmlFilePath); // ####### Encrypt the XML ####### // If the Xml is encrypted, so this piece of code decrypt it. if (xmlDocument.DocumentElement.ChildNodes.Count <= 1) { if (UseEncryption) { string data = BEUtil.Decrypt(xmlDocument.DocumentElement.InnerText); xmlDocument.DocumentElement.InnerXml = data; } } //################################ if (xmlDocument != null) { XmlElement element = xmlDocument.DocumentElement; XmlNodeList list = element.ChildNodes; foreach (XmlElement ele in list) { if (ele.Name == "ConfigVersion") { ConfigVersion = int.Parse(ele.GetAttribute("value")); } else if (ele.Name == "Time") { DateTime dtNow = DateTime.Now; DateTime dtSaved = DateTime.Parse(ele.GetAttribute("value")); //Debug.Log ("dtNow:"+dtNow.ToString()); //Debug.Log ("dtSaved:"+dtSaved.ToString()); TimeSpan timeDelta = dtNow.Subtract(dtSaved); //Debug.Log ("TimeSpan:"+timeDelta.ToString()); BETime.timeAfterLastRun = timeDelta.TotalSeconds; } else if (ele.Name == "ExpTotal") { ExpTotal = int.Parse(ele.GetAttribute("value")); } else if (ele.Name == "Gem") { Gem.ChangeTo(double.Parse(ele.GetAttribute("value"))); } else if (ele.Name == "Gold") { Gold.ChangeTo(double.Parse(ele.GetAttribute("value"))); } else if (ele.Name == "Elixir") { Elixir.ChangeTo(double.Parse(ele.GetAttribute("value"))); } else if (ele.Name == "Shield") { Shield.ChangeTo(double.Parse(ele.GetAttribute("value"))); } else if (ele.Name == "Building") { int Type = int.Parse(ele.GetAttribute("Type")); int Level = int.Parse(ele.GetAttribute("Level")); //Debug.Log ("Building Type:"+Type.ToString()+" Level:"+Level.ToString()); Building script = BEGround.instance.BuildingAdd(Type, Level); script.Load(ele); } else { } } } InLoading = false; }
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(); } }
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); }
void Awake() { instance = this; }