public void _Show(Building script) { building = script; Reset(); Visible = true; // if newly create building was selected if (building.OnceLanded == false) { // only show 'create','cancel' button AddButton(Resources.Load <Sprite>("Icons/CheckedMark"), "Ok", PayType.None, 0, CommandType.Create); AddButton(Resources.Load <Sprite>("Icons/Multiplication"), "Cancel", PayType.None, 0, CommandType.CreateCancel); } else { // if building is not in creation, show 'info' button if (building.Level != 0) { AddButton(Resources.Load <Sprite>("Icons/Info"), "Info", PayType.None, 0, CommandType.Info); } // if building can upgrade to next level if (building.defNext != null) { // if in upgrading if (building.InUpgrade) { if (!building.UpgradeCompleted) { // shows 'Cancel','Finish' buttons AddButton(Resources.Load <Sprite>("Icons/Multiplication"), "Cancel", PayType.None, 0, CommandType.UpgradeCancel); int FinishGemCount = building.GetFinishGemCount(); AddButton(Resources.Load <Sprite>("Icons/Gem"), "Finish\nNow", PayType.Gem, FinishGemCount, CommandType.UpgradeFinish); } } else { // get price to upgrade PayType payType = PayType.None; int BuyPrice = 0; if (building.defNext.BuildGoldPrice != 0) { payType = PayType.Gold; BuyPrice = building.defNext.BuildGoldPrice; } else if (building.defNext.BuildElixirPrice != 0) { payType = PayType.Elixir; BuyPrice = building.defNext.BuildElixirPrice; } else if (building.defNext.BuildGemPrice != 0) { payType = PayType.Gem; BuyPrice = building.defNext.BuildGemPrice; } else { } // add 'upgrade' button AddButton(Resources.Load <Sprite>("Icons/UpArrow"), "Upgrade", payType, BuyPrice, CommandType.Upgrade); } } // is building is barrack if ((building.Type == 7) && !building.InUpgrade) { // add'Train' button AddButton(Resources.Load <Sprite>("Icons/Bullet"), "Train\nTroops", 0, 0, CommandType.Training); } } ButtonReposition(); Info.text = TBDatabase.GetBuildingName(building.Type) + " Level " + building.Level.ToString(); //BETween.anchoredPosition3D(gameObject, 0.2f, new Vector3(0,-250,0), new Vector3(0,0,0));//.method = BETweenMethod.easeOut; StartCoroutine(TweenMov(GetComponent <RectTransform>(), new Vector2(0, -250), new Vector2(0, 0), 0.2f, 0)); }
// initialize building public void Init(int type, int level) { Type = type; Level = level; // delete old meshes if (goCenter != null) { Destroy(goCenter); goCenter = null; } if (goXInc != null) { Destroy(goXInc); goXInc = null; } if (goZInc != null) { Destroy(goZInc); goZInc = null; } bt = TBDatabase.GetBuildingType(type); // get mesh path type and level int displayLevel = (level == 0) ? 1 : level; string meshPath = "Prefabs/Building/" + bt.Name + "_" + displayLevel.ToString(); //Debug.Log ("Loading Mesh "+meshPath); // instantiate mesh and set to goCenter GameObject prefabMesh = Resources.Load(meshPath) as GameObject; goCenter = (GameObject)Instantiate(prefabMesh, Vector3.zero, Quaternion.identity); goCenter.transform.SetParent(gameObject.transform); goCenter.transform.localPosition = Vector3.zero; goCenter.transform.localRotation = Quaternion.Euler(0, -90, 0); // if wall if (type == 2) { // create x,z side mesh string meshSidePath = meshPath + "Side"; GameObject prefabMeshSide = Resources.Load(meshSidePath) as GameObject; goXInc = (GameObject)Instantiate(prefabMeshSide, Vector3.zero, Quaternion.identity); goXInc.transform.SetParent(gameObject.transform); goXInc.transform.localPosition = Vector3.zero; goXInc.transform.localRotation = Quaternion.Euler(0, 180, 0); // rotate to x direction goZInc = (GameObject)Instantiate(prefabMeshSide, Vector3.zero, Quaternion.identity); goZInc.transform.SetParent(gameObject.transform); goZInc.transform.localPosition = Vector3.zero; goZInc.transform.localRotation = Quaternion.Euler(0, 90, 0); // rotate to z direction } // set tile size tileSize = new Vector2(bt.TileX, bt.TileZ); // set proper material to gogrid goGrid.GetComponent <Renderer>().material = Resources.Load("Materials/Tile" + bt.TileX.ToString() + "x" + bt.TileZ.ToString()) as Material; goGrid.transform.localScale = new Vector3(bt.TileX, 1, bt.TileZ); goArrowXMinus.transform.localPosition = new Vector3(-(0.4f + (float)bt.TileX * 0.5f), 0.01f, 0); goArrowXPlus.transform.localPosition = new Vector3((0.4f + (float)bt.TileX * 0.5f), 0.01f, 0); goArrowZMinus.transform.localPosition = new Vector3(0, 0.01f, -(0.4f + (float)bt.TileX * 0.5f)); goArrowZPlus.transform.localPosition = new Vector3(0, 0.01f, (0.4f + (float)bt.TileX * 0.5f)); goArea.transform.localScale = new Vector3(bt.TileX, 1, bt.TileZ); // get ui if (transform.Find("UIBuilding")) { uiInfo = transform.Find("UIBuilding").transform.Find("UIInfo").GetComponent <UIInfo>(); } else { uiInfo = UIInGame.instance.AddInGameUI(prefUIInfo, transform, new Vector3(0, 1.5f, 0)).GetComponent <UIInfo>(); } uiInfo.groupInfo.gameObject.SetActive(false); uiInfo.groupProgress.gameObject.SetActive(false); uiInfo.groupCollect.gameObject.SetActive(false); uiInfo.Name.text = TBDatabase.GetBuildingName(Type); uiInfo.Level.text = "Level " + displayLevel.ToString(); uiInfo.building = this; // currently not used goRangeIn.SetActive(false); goRangeOut.SetActive(false); // initialize values tilePosOld = tilePos; CheckLandable(); CheckNeighbor(); def = TBDatabase.GetBuildingDef(Type, Level); defNext = bt.GetDefine(Level + 1); defLast = bt.GetDefLast(); UpgradeTimeTotal = (defNext != null) ? defNext.BuildTime : 0; }