Exemplo n.º 1
0
 /// <summary>
 /// 测试点中的格子
 /// </summary>
 private void TestSelected()
 {
     //如果点击了鼠标左键
     if (Input.GetMouseButtonDown(0))
     {
         //计算点击位置
         Vector3 clickedWorldPos = BattleCamera.ScreenToWorldPoint(Input.mousePosition);
         clickedWorldPos.z = 0;
         //判断是否有格子被点中?
         GridUnitRenderer clicked = GetGridClicked(clickedWorldPos);
         //点中了格子
         if (clicked != null)
         {
             if (selectedGrid != null)
             {
                 if (selectedGrid.Equals(clicked))
                 {
                     //重复点中相同的格子
                     Debug.Log("点中了相同的格子");
                     return;
                 }
                 else
                 {
                     selectedGrid.GridRenderType = GridRenderType.Normal;
                 }
             }
             selectedGrid = clicked;
             selectedGrid.GridRenderType = GridRenderType.Selected;
         }
         //没有点中格子,但是当前有选中,取消选中
         else if (selectedGrid != null)
         {
             selectedGrid.GridRenderType = GridRenderType.Normal;
             selectedGrid = null;
         }
     }
 }
Exemplo n.º 2
0
        //点击了技能,在以固定地点为原点的技能情况下
        private void OnBattleUnitAndGridTouched_StateSkill_GridUnitTarget(GridUnit gridTouched, BattleUnit battleUnitTouched)
        {
            //如果当前有点中的格子
            if (selectedGridUnitRenderer != null &&
                (selectedGridUnitRenderer.Equals(gridTouched.gridUnitRenderer) || usedManualReleaseAnalysisor.battleSkill.releaseRadius <= 0))
            {
                //如果当前的释放距离为0,表示无需二次点击确认,直接释放
                if (usedManualReleaseAnalysisor.battleSkill.releaseRadius <= 0)
                {
                    ManualSkill(manualOperatingBattleUnitRenderer.battleUnit.mapGrid);
                    return;
                }

                //点中了重复的格子,判断是否有目标
                bool hasTarget = false;
                for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i)
                {
                    if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius)
                    {
                        hasTarget = true;
                        break;
                    }
                }
                //有目标,则释放
                if (hasTarget)
                {
                    ManualSkill(gridTouched);
                }
                else
                {
                    UtilityHelper.Log("范围内没有目标");
                }
            }
            else
            {
                //这个格子不在范围内
                if (manualOperatingBattleUnitRenderer.battleUnit.mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.releaseRadius)
                {
                    if (selectedGridUnitRenderer != null)
                    {
                        //取消上一个范围显示
                        SetCircularRangeRenderStateActive(false, GridRenderType.SkillEffectRange);
                        //取消可被攻击单位的显示
                        for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i)
                        {
                            usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Normal);
                        }
                    }
                    //设置新的范围显示
                    selectedGridUnitRenderer = gridTouched.gridUnitRenderer;
                    SetCircularRangeRenderStateActive(
                        true,
                        GridRenderType.SkillEffectRange,
                        gridTouched.row,
                        gridTouched.column,
                        usedManualReleaseAnalysisor.battleSkill.effectRadius
                        );
                    //设置新的可被攻击单位的显示
                    for (int i = 0; i < usedManualReleaseAnalysisor.suitableUnits.Count; ++i)
                    {
                        if (usedManualReleaseAnalysisor.suitableUnits[i].mapGrid.Distance(gridTouched) <= usedManualReleaseAnalysisor.battleSkill.effectRadius)
                        {
                            usedManualReleaseAnalysisor.suitableUnits[i].battleUnitRenderer.UpdateRenderState(BattleUnitRenderState.Selected);
                        }
                    }
                }
                else
                {
                    UtilityHelper.Log("超出区域");
                    UIViewManager.Instance.ShowView(UIViewName.BattleFieldUnitInfo, gridTouched, battleUnitTouched);
                }
            }
        }
Exemplo n.º 3
0
 private void TestNearestGrid()
 {
     //如果点击了鼠标左键
     if (Input.GetMouseButtonDown(0))
     {
         //计算点击位置
         Vector3 clickedWorldPos = BattleCamera.ScreenToWorldPoint(Input.mousePosition);
         clickedWorldPos.z = 0;
         //判断是否有格子被点中?
         GridUnitRenderer clicked = GetGridClicked(clickedWorldPos);
         //点中了格子
         if (clicked != null)
         {
             if (from == null || from.Equals(clicked))
             {
                 from = clicked;
                 from.gridUnit.battleUnit = new BattleUnit();
                 from.AppendGridRenderType(GridRenderType.Start);
             }
             else if (to == null || to.Equals(clicked))
             {
                 to = clicked;
                 to.gridUnit.battleUnit = new BattleUnit();
                 to.AppendGridRenderType(GridRenderType.End);
                 //求最近的格子
                 var nearest = battleField.battleMap.GetEmptyGrid(from.gridUnit, to.gridUnit, path, -1);
                 if (nearest == null)
                 {
                     UtilityHelper.LogError("Can not find out nearest grid.");
                     from.ResetGridRenderType();
                     to.ResetGridRenderType();
                     to.gridUnit.battleUnit   = null;
                     from.gridUnit.battleUnit = null;
                     from = null;
                     to   = null;
                 }
                 else
                 {
                     nearestGrid = nearest.gridUnitRenderer;
                     nearestGrid.AppendGridRenderType(GridRenderType.Range);
                     SetPathHighlightActive(true, path.ToArray());
                 }
             }
             else
             {
                 from.ResetGridRenderType();
                 to.ResetGridRenderType();
                 nearestGrid.ResetGridRenderType();
                 to.gridUnit.battleUnit   = null;
                 from.gridUnit.battleUnit = null;
                 from        = null;
                 to          = null;
                 nearestGrid = null;
                 SetPathHighlightActive(false, null);
                 path.Clear();
             }
         }
         //没有点中格子
         else
         {
         }
     }
 }
Exemplo n.º 4
0
        private void TestNavigation()
        {
            //如果点击了鼠标左键
            if (Input.GetMouseButtonDown(0))
            {
                //计算点击位置
                Vector3 clickedWorldPos = BattleCamera.ScreenToWorldPoint(Input.mousePosition);
                clickedWorldPos.z = 0;
                //判断是否有格子被点中?
                GridUnitRenderer clicked = GetGridClicked(clickedWorldPos);
                //点中了格子
                if (clicked != null)
                {
                    if (clicked.gridUnit.GridType == GridType.Obstacle)
                    {
                        //点中了障碍物!
                        Debug.Log("Clicked obstacle.");
                        return;
                    }
                    if (from == null)
                    {
                        //当前还没有选择起始地点
                        from = clicked;
                        from.AppendGridRenderType(GridRenderType.Start);
                    }
                    else if (to == null)
                    {
                        //两次点中了起点
                        if (from.Equals(clicked))
                        {
                            return;
                        }

                        //当前没有选择终点
                        to = clicked;
                        to.AppendGridRenderType(GridRenderType.End);
                        UtilityHelper.TimerStart();
                        int navTimes = 999;
                        int count    = navTimes;
                        while (count > 0)
                        {
                            //有起点有终点,开始导航
                            if (MapNavigator.Instance.Navigate(battleField.battleMap, from.gridUnit, to.gridUnit, path, searched))
                            {
                            }
                            else
                            {
                                //没有找到路径
                                Debug.LogError("Navitation failed. No path.");
                                return;
                            }
                            --count;
                        }
                        SetPathHighlightActive(true, path.ToArray());
                        UtilityHelper.Log(string.Format("Nav times:{0}, timeCost{1:00}", navTimes, UtilityHelper.TimerEnd()));
                    }
                    else
                    {
                        from.ResetGridRenderType();
                        from = null;
                        to.ResetGridRenderType();
                        to = null;
                        foreach (var item in searched)
                        {
                            battleField.battleMap.mapGrids[item.column, item.row].gridUnitRenderer.ResetGridRenderType();
                        }

                        foreach (var item in path)
                        {
                            battleField.battleMap.mapGrids[item.column, item.row].gridUnitRenderer.ResetGridRenderType();
                        }
                    }
                }
                //没有点中格子
                else
                {
                    if (from != null)
                    {
                        from.ResetGridRenderType();
                        from = null;
                    }
                    if (to != null)
                    {
                        to.ResetGridRenderType();
                        to = null;
                    }

                    foreach (var item in searched)
                    {
                        battleField.battleMap.mapGrids[item.column, item.row].gridUnitRenderer.ResetGridRenderType();
                    }

                    foreach (var item in path)
                    {
                        battleField.battleMap.mapGrids[item.column, item.row].gridUnitRenderer.ResetGridRenderType();
                    }
                }
            }
        }
Exemplo n.º 5
0
 private void TestNearestGrid()
 {
     //如果点击了鼠标左键
     if (Input.GetMouseButtonDown(0))
     {
         //计算点击位置
         Vector3 clickedWorldPos = BattleCamera.ScreenToWorldPoint(Input.mousePosition);
         clickedWorldPos.z = 0;
         //判断是否有格子被点中?
         GridUnitRenderer clicked = GetGridClicked(clickedWorldPos);
         //点中了格子
         if (clicked != null)
         {
             if (from == null || from.Equals(clicked))
             {
                 from = clicked;
                 from.gridUnit.battleUnit = new BattleUnit();
                 from.GridRenderType      = GridRenderType.Start;
             }
             else if (to == null || to.Equals(clicked))
             {
                 to = clicked;
                 to.gridUnit.battleUnit = new BattleUnit();
                 to.GridRenderType      = GridRenderType.End;
                 //求最近的格子
                 var nearest = battleField.battleMap.GetEmptyGrid(from.gridUnit, to.gridUnit, path, -1);
                 if (nearest == null)
                 {
                     UtilityHelper.LogError("Can not find out nearest grid.");
                     from.GridRenderType      = GridRenderType.Normal;
                     to.GridRenderType        = GridRenderType.Normal;
                     to.gridUnit.battleUnit   = null;
                     from.gridUnit.battleUnit = null;
                     from = null;
                     to   = null;
                 }
                 else
                 {
                     nearestGrid = nearest.gridUnitRenderer;
                     nearestGrid.GridRenderType = GridRenderType.Range;
                     foreach (var item in path)
                     {
                         if (item.Equals(to.gridUnit) || item.Equals(nearestGrid.gridUnit))
                         {
                             continue;
                         }
                         item.gridUnitRenderer.GridRenderType = GridRenderType.Path;
                     }
                 }
             }
             else
             {
                 from.GridRenderType        = GridRenderType.Normal;
                 to.GridRenderType          = GridRenderType.Normal;
                 nearestGrid.GridRenderType = GridRenderType.Normal;
                 to.gridUnit.battleUnit     = null;
                 from.gridUnit.battleUnit   = null;
                 from        = null;
                 to          = null;
                 nearestGrid = null;
                 foreach (var item in path)
                 {
                     item.gridUnitRenderer.GridRenderType = GridRenderType.Normal;
                 }
                 path.Clear();
             }
         }
         //没有点中格子
         else
         {
         }
     }
 }