Esempio n. 1
0
        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;
        }