void readTowerCost() { TowerCostInfo = new Dictionary <string, STowerCost>(); XmlDocument xmlDoc = new XmlDocument(); TextAsset path = Resources.Load <TextAsset>(GameConfig.DatabasePathTowerCost); xmlDoc.LoadXml(path.text); XmlNodeList listMap = xmlDoc.GetElementsByTagName("Tower"); foreach (XmlNode infoMap in listMap) { STowerCost towerCost = new STowerCost(); towerCost.Diamond = int.Parse(infoMap.SelectSingleNode("Diamond").InnerText); towerCost.Gold = int.Parse(infoMap.SelectSingleNode("Gold").InnerText); TowerCostInfo.Add(infoMap.Attributes["id"].InnerText, towerCost); } }
public void loadTowerPassive() { if (shopType == EShopType.TOWER) { return; } shopType = EShopType.TOWER; target = null; //AutoDestroy.destroyChildren(towerPanel, PlayNameHashIDs.Collider); //towerPanel.transform.localPosition = Vector3.zero; //towerPanel.GetComponent<UIPanel>().clipOffset = Vector2.zero; setSpriteButton(EShopType.TOWER); int TowersLength = ObjectManager.Instance.Towers.Length; int length = ObjectManager.Instance.TowersPassive.Length; for (int i = 0; i < length; i++) { TowerPassiveController currentTower = ObjectManager.Instance.TowersPassive[i].GetComponent <TowerPassiveController>(); GameObject _towerShop = Instantiate(towerShopModel) as GameObject; _towerShop.transform.parent = towerPanel.transform; _towerShop.transform.localScale = Vector3.one; _towerShop.name = currentTower.name; UIAnchor anchor = _towerShop.GetComponent <UIAnchor>(); anchor.container = towerPanel.gameObject; anchor.relativeOffset = new Vector2(PlayConfig.TowerShopAnchor.PanelAnchorStart + (i + TowersLength) * PlayConfig.TowerShopAnchor.PanelAnchorDistance, 0); TowerShopController towerShopController = _towerShop.GetComponent <TowerShopController>(); towerShopController.Index = i; towerShopController.ID = currentTower.ID; towerShopController.Name.text = currentTower.attribute.Name.Split()[0]; //set background stretch foreach (Transform child in _towerShop.transform) { if (child.name == "Background") { child.GetComponent <UIStretch>().container = towerPanel; break; } } //set diamond and gold STowerCost cost = ReadDatabase.Instance.TowerCostInfo[towerShopController.ID.Type.ToString()]; towerShopController.Money = cost.Gold; towerShopController.Diamond = cost.Diamond; string s = GameConfig.PathTowerIcon + currentTower.ID.Type.ToString() + "-" + currentTower.ID.Level; towerShopController.icon.mainTexture = Resources.Load <Texture>(s); towerShopController.setColor(false); towerShopController.icon.keepAspectRatio = UIWidget.AspectRatioSource.Free; Vector2 localSize = new Vector2(towerShopController.icon.mainTexture.width, towerShopController.icon.mainTexture.height); towerShopController.icon.SetDimensions((int)localSize.x, (int)localSize.y); towerShopController.icon.keepAspectRatio = UIWidget.AspectRatioSource.BasedOnHeight; UIStretch uiStretch = towerShopController.icon.GetComponent <UIStretch>(); uiStretch.enabled = true; if (target == null) { target = _towerShop; } if (!initWhenStart) { towerShopType[i] = WaveController.Instance.infoMap.TowerUsed.ToUpper().Contains(currentTower.ID.Type.ToString()) ? ETowerShopState.TOWER_BUY_DEFAULT : ETowerShopState.TOWER_BUY_ENABLE; } _towerShop.GetComponentInChildren <UITowerShop>().type = towerShopType[i]; } if (target != null) { target.GetComponentInChildren <TowerShopController>().setColor(true); } loadInfoTowerPassive(); if (!initWhenStart) { initWhenStart = true; } }
void readTowerCost() { TowerCostInfo = new Dictionary<string, STowerCost>(); XmlDocument xmlDoc = new XmlDocument(); TextAsset path = Resources.Load<TextAsset>(GameConfig.DatabasePathTowerCost); xmlDoc.LoadXml(path.text); XmlNodeList listMap = xmlDoc.GetElementsByTagName("Tower"); foreach (XmlNode infoMap in listMap) { STowerCost towerCost = new STowerCost(); towerCost.Diamond = int.Parse(infoMap.SelectSingleNode("Diamond").InnerText); towerCost.Gold = int.Parse(infoMap.SelectSingleNode("Gold").InnerText); TowerCostInfo.Add(infoMap.Attributes["id"].InnerText, towerCost); } }