// Methods
        private void OnDrawGizmos()
        {
            if (astar != null)
            {
                AStarGrid grid = astar.Grid;
                for (int i = 0; i < grid.NumCols; i++)
                {
                    for (int j = 0; j < grid.NumRows; j++)
                    {
                        AStarGridNode nodeAtPosition = grid.GetNodeAtPosition(i, j);
                        if (drawNodesCenter)
                        {
                            Gizmos.color = Color.cyan;
                            Gizmos.DrawWireSphere((Vector3)nodeAtPosition.Position, centerSize);
                        }
                    }
                }

                ArrayList path = astar.Path;
                if (path != null)
                {
                    for (int k = 0; k < path.Count; k++)
                    {
                        AStarGridNode node2 = path[k] as AStarGridNode;
                        if ((node2 != null) && drawPathNodesCenter)
                        {
                            Gizmos.color = Color.blue;
                            Gizmos.DrawWireSphere((Vector3)node2.Position, centerSize);
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// 初始化函数
        /// </summary>
        /// <param name="g">进行A*计算的网格信息</param>
        public void InitWithGrid(AStarGrid g)
        {
            Grid = g;

            // 就是根号2的值
            mDiagonalCost = 1.414;
            // 直线行进的成本,表示一个格子的成本为1
            mStraightCost = 1.0;

            // 启发函数类型
            mHeuristicType = Heuristic.MANHATTAN;

            mOpenTable   = new ArrayList();
            mClosedTable = new ArrayList();
            Path         = new ArrayList();
        }