/// <summary> /// 同步更新战争状态 /// </summary> /// <param name="_newDefence">新战争状态</param> public void UpdateFighting(bool _fighting) { CountryObj selfCountry = WorldObj.MatchCountry(nationality); if (selfCountry) { uiController = selfCountry.GetComponent <UIController>(); uiController.ScoutInfoShow(nationality, WorldObj.AnimatorAction.Victory, WorldObj.ScoutInfoType.CityBeAttacked, this.gameObject); } photonView.RPC("UpdateFightingRPC", PhotonTargets.All, _fighting); }
//关闭建造窗口并提示建造 void CloseSelectAndHintBuild() { //关闭建造窗口 uiController.CloseAllPanels(); //打开世界UI WorldUI.gameObject.SetActive(!cityController.BuildWeaponPanel.gameObject.GetActive()); //队伍提示面板关闭 teamPanel.gameObject.SetActive(false); //提示选择位置建造信息 uiController.ScoutInfoShow(selfCountry.nationality, WorldObj.AnimatorAction.Victory, WorldObj.ScoutInfoType.WhereBuild, teamController.teamObj.gameObject); //生成提示建造模型 if (model) { Transform aHintModel = teamController.teamObj.hintModel; if (aHintModel) { Destroy(teamController.teamObj.hintModel.gameObject); } //生成提示模型 aHintModel = Instantiate(model, teamController.teamObj.transform.position + new Vector3(0f, 1.5f, 2f), Quaternion.Euler(20f, 0f, 0f)); //按配件信息字符串数组激活模型的部分配件 cityController.SetActiveParts(aHintModel, teamController.teamObj.partsnames); //删除提示模型上的组件 Destroy(aHintModel.GetComponent <Animator>()); Destroy(aHintModel.GetComponent <Collider>()); Destroy(aHintModel.GetComponent <ModelController>()); Destroy(aHintModel.GetComponentInChildren <Animator>()); Destroy(aHintModel.GetComponentInChildren <Animation>()); //使提示模型半透明 /* * MeshRenderer[] meshRenderers = teamController.hintModel.GetComponentsInChildren<MeshRenderer>(); * foreach (var item in meshRenderers) * { * foreach (var child in item.materials) * { * child.shader = Shader.Find("Transparent/Diffuse"); * Color c = child.color; * c = new Color(c.r, c.g, c.b, c.a*2/ 5); * child.color = c; * } * } */ //一定时间后删除 //Destroy(teamController.hintModel.gameObject,10f); //模型跟随闪烁提示建造 teamController.ModelFlashHint(aHintModel, teamController.teamObj.transform); teamController.teamObj.hintModel = aHintModel; } }
private void FixedUpdate() { if (!photonView.isMine) { return; } //如果更换场景摄像头被Destroy了则playercamera指向新场景的摄像头 if (!playercamera) { playercamera = FindObjectOfType <Camera>().transform; } if (!Ground) { Ground = GameObject.Find("Ground(Clone)").transform; } cooltime += Time.deltaTime; if (cooltime >= 0.2f) { cooltime = 0f; //每10帧判断敌人队伍是否应该被看见 foreach (var item in WorldObj.allTeams) { //判断每一支非己方的TeamObj是否该被看见 if (item.nationality != nationality) { bool seen = false; //是否该被看见变量 GameObject infoSource = null; foreach (var team in WorldObj.allTeams) { if (team.nationality == nationality) { if (Vector3.Distance(item.transform.position, team.transform.position) < WorldObj.SkillDistance) { seen = true; infoSource = team.gameObject; break; } } } foreach (var eachcity in WorldObj.allCities) { if (eachcity && eachcity.nationality == nationality) { if (Vector3.Distance(item.transform.position, eachcity.transform.position) < WorldObj.SkillDistance) { seen = true; infoSource = eachcity.gameObject; break; } } } //根据判断结果使敌人消失或者显形(包括敌人血条teamHealthCanvas) if (seen && !item.visible) //使显形 { item.visible = true; StartCoroutine(Funcs.SlowDisappearIE(item.teamHealthCanvas, 2f, 100f, true)); StartCoroutine(Funcs.SlowDisappearIE(item.transform, 2f, 100f, true)); try { //侦查信息显示 uiController.ScoutInfoShow(nationality, WorldObj.AnimatorAction.Victory, WorldObj.ScoutInfoType.EnemyBeFound, infoSource); } catch (Exception) { } } else if (!seen && item.visible)//使消失 { item.visible = false; StartCoroutine(Funcs.SlowDisappearIE(item.teamHealthCanvas, 2f, 100f, false)); StartCoroutine(Funcs.SlowDisappearIE(item.transform, 2f, 100f, false)); } } } } //如果正在操作界面的城市受到攻击,则关闭UI if (cityController.cityObj && cityController.cityObj.fighting && WorldObj.UIRun) { uiController.CloseAllPanels(); } //如果城市的敌人列表中的队伍不再攻城或者已经不存在,则从列表中清除该队伍 foreach (var item in WorldObj.allCities) { if (item && item.fighting) { for (int i = 0; i < item.enemies.Count; i++) { TeamObj fightTeam = null; foreach (var eachTeam in WorldObj.allTeams) { if (eachTeam.hero == item.enemies[i]) { fightTeam = eachTeam; } } if ((fightTeam && !fightTeam.enemies.Contains(item.word)) || !fightTeam) { item.UpdateEnemies(item.enemies[i], false); } if (item.enemies.Count == 0) { item.UpdateFighting(false); } } } } }
IEnumerator GoAndBuildIE(int _builderIndex, Vector3 _buildPosition) { UIController uiController = countryObj.GetComponent <UIController>(); //测试是否能建造 if (!CanBuild(_builderIndex, _buildPosition)) { uiController.ScoutInfoShow(countryObj.nationality, WorldObj.AnimatorAction.Victory, WorldObj.ScoutInfoType.CannotBuild, builders[_builderIndex].gameObject); //无法建造警告 CannotBuildWarning(_builderIndex, _buildPosition); //则设置该标志为真,使得再次点击可以直接重选建造位置 countryObj.reGoBuild = true; yield break; } //开始行走向建造目标位置,移动提示模型到该位置并使其半透明 if (builders[_builderIndex].hintModel) { builders[_builderIndex].hintModel.position = _buildPosition; StopCoroutine(builders[_builderIndex].coroutineHintModelFlash); builders[_builderIndex].coroutineHintModelFlash = null; //使模型可见 Funcs.SetObjectVisuality(builders[_builderIndex].hintModel, true); //使模型半透明 Funcs.ChangeObjectAlphaValue(builders[_builderIndex].hintModel, 0.4f); } //队伍开始行走直到接近目标位置 builders[_builderIndex].GetComponent <NavMeshAgent>().SetDestination(_buildPosition); uiController.ScoutInfoShow(countryObj.nationality, WorldObj.AnimatorAction.Victory, WorldObj.ScoutInfoType.GoBuild, builders[_builderIndex].gameObject); while (Vector3.Distance(builders[_builderIndex].transform.position, _buildPosition) > 1.2f) { yield return(new WaitForSeconds(Time.deltaTime * 75)); } //测试是否能建造 //开始建造 if (!CanBuild(_builderIndex, _buildPosition)) { uiController.ScoutInfoShow(countryObj.nationality, WorldObj.AnimatorAction.Victory, WorldObj.ScoutInfoType.CannotBuild, builders[_builderIndex].gameObject); yield break; } cityController.BuildNewTeam(builders[_builderIndex].nationality, 1000, "", WorldObj.SoldierType.Tank, builders[_builderIndex].partsnames, _buildPosition); //保存并得到保存的已建造的队伍序号 photonView.RPC("SaveNewTeamRPC", PhotonTargets.All, null); //马上取出该序号防止其他进程改变其值 int thisNewTeamIndex = newTeamIndex; //将Work带的配件表赋值给新建造的队伍,以便在新建队伍的初始化中调用 photonView.RPC("GivePartsNamesRPC", PhotonTargets.All, builders[_builderIndex].partsnames); //开始建造后,使得工程队转向建造位置,静止不动并不可选取 builders[_builderIndex].transform.LookAt(new Vector3(_buildPosition.x, builders[_builderIndex].transform.position.y, _buildPosition.z)); //锁住队伍 LockUnLockTeam(builders[_builderIndex], true); //准备建造模型逐步建造 photonView.RPC("PrepareStepBuildRPC", PhotonTargets.All, WorldObj.SoldierType.Tank, builders[_builderIndex].nationality); //逐步建造队伍模型 StepBuild(thisNewTeamIndex, _builderIndex, builders[_builderIndex].partsnames, 10f); //删除提示模型 if (builders[_builderIndex].hintModel) { Destroy(builders[_builderIndex].hintModel.gameObject); } //协程结束则清空协程变量 builders[_builderIndex].coroutineGoAndBuild = null; }