Exemplo n.º 1
0
        public void Test_RemoteRange(GridUnit gridUnit)
        {
            if (releaserGrid == null)
            {
                releaserGrid = gridUnit;
                releaserGrid.gridUnitRenderer.AppendGridRenderType(GridRenderType.Start);

                battleField.battleMap.GetCircularGrids(releaserGrid.row, releaserGrid.column,
                                                       motionRadius, 0, true, releaseRange);

                foreach (var item in releaseRange)
                {
                    item.gridUnitRenderer.AppendGridRenderType(GridRenderType.SkillReleaseRange);
                }
            }
            else if (targetGrid == null)
            {
                UtilityHelper.TimerStart();

                targetGrid = gridUnit;
                targetGrid.gridUnitRenderer.AppendGridRenderType(GridRenderType.End);

                for (int i = 0; i < 1000; ++i)
                {
                    battleField.battleMap.GetCircularGrids(releaserGrid.row, releaserGrid.column,
                                                           motionRadius, 0, true, skillRange, delegate(GridUnit _gridUnit)
                    {
                        return(_gridUnit.Distance(targetGrid) <= effectRadius);
                    });
                }

                foreach (var item in skillRange)
                {
                    item.gridUnitRenderer.AppendGridRenderType(GridRenderType.SkillEffectRange);
                }

                UtilityHelper.Log("Test_RemoteRange cost:" + UtilityHelper.TimerEnd());
            }
            else
            {
                releaserGrid.gridUnitRenderer.ResetGridRenderType();
                targetGrid.gridUnitRenderer.ResetGridRenderType();
                foreach (var item in releaseRange)
                {
                    item.gridUnitRenderer.ResetGridRenderType();
                }
                foreach (var item in skillRange)
                {
                    item.gridUnitRenderer.ResetGridRenderType();
                }
                releaserGrid = null;
                targetGrid   = null;
                releaseRange.Clear();
                skillRange.Clear();
            }
        }
Exemplo n.º 2
0
        //点击了地块、战斗单位
        private void Test_Nav(GridUnit gridTouched)
        {
            if (start == null)
            {
                start = gridTouched;
                start.gridUnitRenderer.AppendGridRenderType(GridRenderType.Start);
            }
            else if (end == null)
            {
                end = gridTouched;
                end.gridUnitRenderer.AppendGridRenderType(GridRenderType.End);

                //Nav

                UtilityHelper.TimerStart();
                for (int i = 0; i < 1000; i++)
                {
                    //SetCircularRangeRenderStateActive(true, GridRenderType.SkillEffectRange, start.row, start.column, 3);
                    MapNavigator.Instance.Navigate(battleField.battleMap,
                                                   start,
                                                   end,
                                                   lastPath, null, -1, 2);
                }

                Debug.Log("TimeCost:" + UtilityHelper.TimerEnd());
                //foreach (var item in lastSearched)
                //{
                //    item.gridUnitRenderer.AppendGridRenderType(GridRenderType.Searched);
                //}
                foreach (var item in lastPath)
                {
                    item.gridUnitRenderer.AppendGridRenderType(GridRenderType.Path);
                }
            }
            else
            {
                start.gridUnitRenderer.ResetGridRenderType();
                end.gridUnitRenderer.ResetGridRenderType();
                foreach (var item in lastPath)
                {
                    item.gridUnitRenderer.ResetGridRenderType();
                }
                foreach (var item in lastSearched)
                {
                    item.gridUnitRenderer.ResetGridRenderType();
                }
                start = null;
                end   = null;
                SetCircularRangeRenderStateActive(false, GridRenderType.SkillEffectRange);
            }
        }
Exemplo n.º 3
0
        private void Test_Range(GridUnit gridTouched)
        {
            if (lastUnits.Count > 0)
            {
                foreach (var item in lastUnits)
                {
                    item.gridUnitRenderer.ResetGridRenderType();
                }
            }

            UtilityHelper.TimerStart();
            for (int i = 0; i < 100; i++)
            {
                battleField.battleMap.GetCircularGrids(gridTouched.row, gridTouched.column, 3, 0, false, lastUnits);
            }

            Debug.Log("TimeCost:" + UtilityHelper.TimerEnd());
            foreach (var item in lastUnits)
            {
                item.gridUnitRenderer.AppendGridRenderType(GridRenderType.MoveRange);
            }
        }
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();
                    }
                }
            }
        }