//--------------------------------------------- 按钮点击触发 --------------------------------------------------------- //土地被点击 private void LandOnClick(GameObject go) { byte landPos = byte.Parse(go.name.Split('-') [1]); LandVo landVo = Singleton <FarmMode> .Instance.farmInfo.landInfo [landPos]; FarmInfo farmInfo = Singleton <FarmMode> .Instance.farmInfo; //判断是否可以收获果实 if (landVo.seedId != 0 && landVo.remainTime == 0) { Singleton <FarmMode> .Instance.ApplyFarmOpe(farmInfo.id, landPos, 0); //获得果实 // this.UpdateFarmInfo (farmInfo.id); } else if (landVo.status != 0) { Singleton <FarmMode> .Instance.ApplyFarmOpe(farmInfo.id, landPos, landVo.status); //操作农场 // this.UpdateFarmInfo (farmInfo.id); } else if (landVo.seedId == 0) { if (farmInfo.id == MeVo.instance.Id) { Singleton <FarmMode> .Instance.selectedLandPos = landPos; Singleton <MySeedsView> .Instance.OpenView(); //打开我的种子背包 } } }
//----------------------------------- 数据更新 ------------------------------------------// //更新农场信息 public void UpdateFarmInfo(uint id, uint lvl, uint exp, uint expful, List <PLand> landList) { _farmInfo.id = id; _farmInfo.level = lvl; _farmInfo.exp = exp; _farmInfo.expful = expful; _farmInfo.landInfo.Clear(); LandVo land; for (int i = 0; i < landList.Count; ++i) { land = new LandVo(); land.pos = landList[i].pos; land.color = landList[i].color; land.seedId = landList[i].seedId; land.remainTime = landList[i].remainTime; land.num = landList[i].num; land.status = landList[i].status; _farmInfo.landInfo.Add(land.pos, land); } DataUpdate(UPDATE_FARM_INFO); }
//展示已开垦土地 private void ShowOpenedLand(LandVo landVo) { Transform land; land = lands.FindChild(landVo.pos.ToString()); //关闭未开垦土地效果,开启土地点击检测 land.FindChild("close").gameObject.SetActive(false); land.FindChild("colider-" + land.name).gameObject.SetActive(true); //显示土地 switch (landVo.color) { case 1: land.GetComponent <UISprite>().color = LAND1_COLOR; break; case 2: land.GetComponent <UISprite>().color = LAND2_COLOR; break; case 3: land.GetComponent <UISprite>().color = LAND3_COLOR; break; default: Log.error(this, "土地颜色参数错误"); break; } //根据田地状态显示效果.0普通状态 1除虫 2除草 3浇水 switch (landVo.status) { case (byte)LandStatu.NORMAL: land.FindChild("state").gameObject.SetActive(false); break; case (byte)LandStatu.KILL_WORM: land.FindChild("state").gameObject.SetActive(true); land.FindChild("state").GetComponent <UISprite>().spriteName = "1_chuchong"; break; case (byte)LandStatu.CUT_GRASS: land.FindChild("state").gameObject.SetActive(true); land.FindChild("state").GetComponent <UISprite>().spriteName = "1_gecao"; break; case (byte)LandStatu.WATER: land.FindChild("state").gameObject.SetActive(true); land.FindChild("state").GetComponent <UISprite>().spriteName = "1_jiaoshui"; break; } //显示农作物 if (landVo.seedId != 0) { // land.FindChild("plant").gameObject.SetActive(false); //农作物未成熟 if (landVo.remainTime > 0) { //显示剩余时间 land.FindChild("CD").gameObject.SetActive(true); UIUtils.ShowTimeToHMS((int)landVo.remainTime, land.FindChild("CD/Value").GetComponent <UILabel>()); UILabel remainTime = land.FindChild("CD/Value").GetComponent <UILabel>(); if (remainTimeDic.ContainsKey(remainTime)) { remainTimeDic[remainTime] = landVo.remainTime; } else { remainTimeDic.Add(remainTime, landVo.remainTime); } //显示未成熟的农作物 land.FindChild("plant").GetComponent <UISprite>().spriteName = "tree"; land.FindChild("plant").GetComponent <UISprite>().MakePixelPerfect(); } else { land.FindChild("CD").gameObject.SetActive(false); //显示成熟的农作物 land.FindChild("plant").GetComponent <UISprite>().spriteName = "fruit"; land.FindChild("plant").GetComponent <UISprite>().MakePixelPerfect(); //显示可收获提示 land.FindChild("state").gameObject.SetActive(true); land.FindChild("state").GetComponent <UISprite>().spriteName = "1_shouhuo"; } land.FindChild("plant").gameObject.SetActive(true); } else { land.FindChild("plant").gameObject.SetActive(false); land.FindChild("CD").gameObject.SetActive(false); } //显示是否可偷 if (landVo.canSteal) { land.FindChild("state").gameObject.SetActive(true); land.FindChild("state").GetComponent <UISprite>().spriteName = "1_shouhuo"; } }