示例#1
0
 private void LightPathByNeighbour(GridPosition.NeighbourGrid neighbourGrid)
 {
     if (this.neighbourGrid != neighbourGrid)
     {
         this.neighbourGrid = neighbourGrid;
         ExtinguishPath();
         if (weakGrids.Contains(mousePosition.GetNeighbour(neighbourGrid)))
         {
             LightPath(mousePosition.GetNeighbour(neighbourGrid));
         }
     }
 }
示例#2
0
 public void MakePath()
 {
     if (Input.mousePresent)
     {
         Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 300f))  //Physics.Raycast(ray, out hit, 300f, LayerMask.NameToLayer("Chess Grid")) 按理说可以过滤其他层,可是这时只有离摄像头近的有效,很奇怪
         {
             Debug.DrawLine(ray.origin, hit.point);
             GridPosition newPosition = new GridPosition(hit.point);
             Pair         UV          = new Pair(newPosition);
             if (!UV.Equals(turnPair) && grids[UV].activeSelf /*hit.collider.CompareTag("Grid") 效果不好*/)  //Pair的其他值可能不一样要用自定义的Equals
             {
                 if (!mousePosition.Equals(newPosition))
                 {
                     mousePosition = newPosition;
                     ExtinguishPath();
                     if (!grids[UV].GetComponent <GridAttribute>().isUnit)
                     {
                         LightPath(new Pair(mousePosition));
                     }
                     if (neighbourGrid != GridPosition.NeighbourGrid.M)
                     {
                         neighbourGrid = GridPosition.NeighbourGrid.M;
                     }
                 }
                 else if (grids[UV].GetComponent <GridAttribute>().isUnit) //处理敌方单位
                 {
                     if (attackFlag)                                       //近战攻击
                     {
                         if (Input.GetMouseButton(0))                      //进行攻击
                         {
                             turnControler.MoveUnit(gridQueue.ToArray());
                             attackUV = new Pair(mousePosition);
                             turnControler.AttackUnit(attackUV);
                             ExtinguishPath();
                             SleepGrid();
                             flag = true;
                         }
                         else                            //攻击前选择方向
                         {
                             Vector3 gridVector = mousePosition.GetPosition();
                             if (hit.point.x < gridVector.x - 0.16f && hit.point.z < gridVector.z - 0.16f)
                             {
                                 LightPathByNeighbour(GridPosition.NeighbourGrid.SW);
                             }
                             else if (hit.point.x + hit.point.z <= 1f && hit.point.x <= gridVector.x + 0.16f && hit.point.z <= gridVector.z + 0.16f)
                             {
                                 if (hit.point.x >= hit.point.z)
                                 {
                                     LightPathByNeighbour(GridPosition.NeighbourGrid.S);
                                 }
                                 else
                                 {
                                     LightPathByNeighbour(GridPosition.NeighbourGrid.W);
                                 }
                             }
                             else if (hit.point.x < gridVector.x - 0.16f && hit.point.z > gridVector.z + 0.16f)
                             {
                                 LightPathByNeighbour(GridPosition.NeighbourGrid.NW);
                             }
                             else if (hit.point.x > gridVector.x + 0.16f && hit.point.z < gridVector.z - 0.16f)
                             {
                                 LightPathByNeighbour(GridPosition.NeighbourGrid.SE);
                             }
                             else if (hit.point.x > gridVector.x + 0.16f && hit.point.z > gridVector.z + 0.16f)
                             {
                                 LightPathByNeighbour(GridPosition.NeighbourGrid.NE);
                             }
                             else
                             {
                                 if (hit.point.x >= hit.point.z)
                                 {
                                     LightPathByNeighbour(GridPosition.NeighbourGrid.E);
                                 }
                                 else
                                 {
                                     LightPathByNeighbour(GridPosition.NeighbourGrid.N);
                                 }
                             }
                         }
                     }
                     else                                              //远程攻击
                     {
                         turnControler.exceptMelee();
                     }
                 }
                 else if (Input.GetMouseButton(0))
                 {
                     turnControler.MoveUnit(gridQueue.ToArray());
                     ExtinguishPath();
                     SleepGrid();
                     flag = true;
                 }
             }
             else
             {
                 ExtinguishPath();
             }
         }
     }
 }