Beispiel #1
0
 /// <summary>
 /// 入城,队伍解散,士兵归城
 /// </summary>
 /// <param name="_city">要进入的城市</param>
 public void GoInCity(CityObj _city)
 {
     //如果是己方城市或者是未被占领城市,则入城(Tank队伍不能入城)
     if ((_city.nationality == teamObj.nationality || _city.nationality == WorldObj.Nationality.none) &&
         teamObj.soldiertype != WorldObj.SoldierType.Tank)
     {
         teamObj.CaptureCity(_city);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 向城市行军或入城
 /// </summary>
 /// <param name="_city">城市</param>
 public void TeamToCity(CityObj _city)
 {
     if (teamObj)
     {
         if (Vector3.Distance(teamObj.transform.position, _city.transform.position) > WorldObj.TeamGoinCityDistance)
         {
             GoToPosition(_city.transform.position);
         }
         else
         {
             GoInCity(_city);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// 给出起始城市
        /// </summary>
        void BeginCity()
        {
            cityBegin = WorldObj.allCities[0];
            float xTemp = 0;

            foreach (var item in WorldObj.allCities)
            {
                switch (nationality)
                {
                case WorldObj.Nationality.none:
                    break;

                case WorldObj.Nationality.red:
                    if (item.transform.position.x < xTemp)
                    {
                        cityBegin = item;
                        xTemp     = item.transform.position.x;
                    }
                    break;

                case WorldObj.Nationality.blue:
                    if (item.transform.position.x > xTemp)
                    {
                        cityBegin = item;
                        xTemp     = item.transform.position.x;
                    }
                    break;

                case WorldObj.Nationality.monster:
                    break;

                default:
                    break;
                }
            }
            cities.Clear();
            cities.Add(cityBegin.word);
            cityBegin.GiveNationality(nationality);
            //给起始城市国籍标志
            cityBegin.GiveFlag();
        }
Beispiel #4
0
        void Update()
        {
            if (!photonView.isMine)
            {
                return;
            }


            //测试用代码
            if (Input.GetMouseButtonDown(1))
            {
            }



            //鼠标或触摸屏的输入操作
            if (Input.GetMouseButtonDown(0) || Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                Vector3 pos;
                if (Input.GetMouseButtonDown(0))
                {
                    pos = Input.mousePosition;
                }
                else
                {
                    pos = Input.GetTouch(0).deltaPosition;
                }

                //从摄像头发送射线指定屏幕位置到场景位置
                RaycastHit hit = Funcs.RayScreenPoint(playercamera, pos);
                if (!hit.collider)
                {
                    Debug.Log("未点击到任何物体!");
                    return;
                }
                Transform obj = hit.collider.transform;

                //如果UI没有在运行
                if (!WorldObj.UIRun)
                {
                    //摄像头移动的操作
                    if (!teamSelected && obj.parent && !obj.parent.GetComponent <TeamObj>() &&
                        (pos.x < Screen.width / 4 || pos.x > Screen.width * 3 / 4))   //  || pos.y < Screen.height / 3 || pos.y > Screen.height * 2 / 3))
                    {
                        float newx = (pos.x - Screen.width / 2) / 100f;
                        //float newy = (pos.y - Screen.height / 2) / 100f;

                        if (obj)
                        {
                            newx = hit.point.x;
                        }

                        //如果没到左右边界,或者到了左右边界但点击的位置不会让摄像头移出边界,则赋值新目标位置cameraNewPosition
                        if (Mathf.Abs(playercamera.position.x) >= (Ground.localScale.x * 10 / 2 - Screen.width / 2 / screenSizeCoefficient))
                        {
                            if (Mathf.Abs(newx) < Mathf.Abs(playercamera.position.x))
                            {
                                cameraNewPosition = new Vector3(newx, playercamera.position.y, playercamera.position.z); //newy);
                            }
                        }
                        else
                        {
                            cameraNewPosition = new Vector3(newx, playercamera.position.y, playercamera.position.z); //newy);
                        }
                    }
                    else
                    {
                        cameraNewPosition = playercamera.position;
                    }



                    //如果点到城市并且没有事先选择队伍
                    if (!teamSelected && obj.parent && obj.parent.GetComponent <CityObj>())
                    {
                        CityObj aCity = obj.parent.GetComponent <CityObj>();
                        if (aCity.nationality == nationality && !aCity.fighting)
                        {
                            //teamController.CityGetSpotlight(aCity); //城市获得聚光灯
                            cityController.cityObj = aCity;
                            cityController.CityMenu();
                        }
                    }
                    //如果点到队伍并且没有事先选择队伍
                    else if (!teamSelected && obj.parent && obj.parent.GetComponent <TeamObj>())
                    {
                        selectedTeam = obj.parent.GetComponent <TeamObj>();
                        //如果是敌对队伍或带队英雄被沉默,则队伍不可操作
                        HeroObj teamHero = WorldObj.MatchHero(selectedTeam.hero);
                        if (selectedTeam.nationality != nationality ||
                            (!teamHero || teamHero.heroskill == WorldObj.HeroSkill.none) || selectedTeam.hero == "")
                        {
                            return;
                        }
                        teamController.teamObj = selectedTeam;
                        //打开信息提示,使已选择标志为真
                        teamController.TeamHint();
                        teamSelected = true;
                    }
                    //如果点到城市并且事先选择了队伍
                    else if (teamSelected && obj.parent && obj.parent.GetComponent <CityObj>())
                    {
                        if (teamController.clickSkill)
                        {
                            return;
                        }

                        if (selectedTeam)
                        {
                            selectedTeam.targetCity = obj.parent.GetComponent <CityObj>();
                            selectedTeam.targetTeam = null;
                        }
                        teamController.TeamToCity(obj.parent.GetComponent <CityObj>());
                        //关闭信息提示,使已选择标志为假
                        teamSelected = false;
                        teamController.TeamHintClose();
                    }
                    //如果点到队伍并且事先选择了队伍
                    else if (teamSelected && obj.parent && obj.parent.GetComponent <TeamObj>())
                    {
                        if (selectedTeam && obj.parent.GetComponent <TeamObj>() != selectedTeam)
                        {
                            selectedTeam.targetTeam = obj.parent.GetComponent <TeamObj>();
                            selectedTeam.targetCity = null;
                        }
                        //teamController.GoToPosition(hit.point);

                        /*
                         * switch (selectedTeam.soldiertype)
                         * {
                         *  case WorldObj.SoldierType.SwordMan:
                         *  case WorldObj.SoldierType.Archer:
                         *  case WorldObj.SoldierType.Cavalry:
                         *  case WorldObj.SoldierType.Tank:
                         *      teamController.GoToPosition(hit.point);
                         *
                         *      break;
                         *  //是工程兵则走到指定位置开始建造
                         *  case WorldObj.SoldierType.Worker:
                         *      teamController.GoAndBuild(hit.point);
                         *      break;
                         *  case WorldObj.SoldierType.Griffin:
                         *      break;
                         *  default:
                         *      break;
                         * }
                         */
                        switch (selectedTeam.soldiertype)
                        {
                        case WorldObj.SoldierType.SwordMan:
                        case WorldObj.SoldierType.Archer:
                        case WorldObj.SoldierType.Cavalry:
                        case WorldObj.SoldierType.Tank:
                        case WorldObj.SoldierType.Worker:
                            if (!teamController.clickSkill)
                            {
                                teamController.TeamToTeam(obj.parent.GetComponent <TeamObj>());
                            }
                            break;

                        case WorldObj.SoldierType.Griffin:
                            break;

                        default:
                            break;
                        }

                        teamSelected = false;
                        //使用英雄技能
                        TeamObj objTeam = obj.parent.GetComponent <TeamObj>();
                        teamController.HeroUseSkill(objTeam);
                        teamController.TeamHintClose();
                    }
                    //如果点到地上并且事先选择了队伍
                    else if (teamSelected && obj && obj == Ground)
                    {
                        if (selectedTeam)
                        {
                            selectedTeam.targetTeam = null;
                            selectedTeam.targetCity = null;
                        }

                        switch (selectedTeam.soldiertype)
                        {
                        case WorldObj.SoldierType.SwordMan:
                        case WorldObj.SoldierType.Archer:
                        case WorldObj.SoldierType.Cavalry:
                        case WorldObj.SoldierType.Tank:
                            teamController.GoToPosition(hit.point);
                            break;

                        //是工程兵则走到指定位置开始建造
                        case WorldObj.SoldierType.Worker:
                            teamController.GoAndBuild(hit.point);
                            break;

                        case WorldObj.SoldierType.Griffin:
                            break;

                        default:
                            break;
                        }

                        teamSelected = false;

                        teamController.TeamHintClose();

                        //如果工兵队发现位置不可建造,则重新选择建造地点
                        if (reGoBuild)
                        {
                            teamSelected = true;
                            teamController.clickSkill = true;
                            reGoBuild = false;
                        }
                    }
                    //如果点到侦查模型上
                    else if (obj && obj == teamScout)
                    {
                        teamSelected = false;
                        teamController.TeamHintClose();
                        //如果有信息来源,则聚光信息来源,摄像头移动到其位置
                        if (WorldObj.scoutInfoSourceObj)
                        {
                            TeamObj teamInfoSource = WorldObj.scoutInfoSourceObj.GetComponent <TeamObj>();
                            CityObj cityInfoSource = WorldObj.scoutInfoSourceObj.GetComponent <CityObj>();
                            if (teamInfoSource) //如果是队伍信息来源
                            {
                                //teamController.TeamGetSpotlight(teamInfoSource);
                                cameraNewPosition.x = teamInfoSource.transform.position.x;
                            }
                            else if (cityInfoSource) //如果是城市信息来源
                            {
                                //teamController.CityGetSpotlight(cityInfoSource);
                                cameraNewPosition.x = cityInfoSource.transform.position.x;
                            }
                        }
                    }
                }
            }
        }