Esempio n. 1
0
        /// <summary>
        /// 寻可行走节点
        /// </summary>
        /// <param name="startPoint">起点</param>
        /// <param name="cost">可行走节点到起点的最大估价</param>
        /// <param name="rule">搜寻规则</param>
        /// <returns>结果节点组</returns>
        public List <AStarNode> WalkableNodefinding(Vector3 startPoint, int cost, AStarRule rule = null)
        {
            if (rule != null)
            {
                foreach (AStarNode node in _nodes)
                {
                    rule.Apply(node);
                }
            }

            return(WalkableNodefinding(GetNode(startPoint), cost));
        }
Esempio n. 2
0
        /// <summary>
        /// 寻路
        /// </summary>
        /// <param name="startPoint">起点</param>
        /// <param name="endPoint">终点</param>
        /// <param name="rule">搜寻规则</param>
        /// <returns>结果路径</returns>
        public List <AStarNode> Pathfinding(Vector3 startPoint, Vector3 endPoint, AStarRule rule = null)
        {
            if (rule != null)
            {
                foreach (AStarNode node in _nodes)
                {
                    rule.Apply(node);
                }
            }

            return(Pathfinding(GetNode(startPoint), GetNode(endPoint)));
        }
Esempio n. 3
0
        /// <summary>
        /// 寻可行走节点
        /// </summary>
        /// <param name="startIndex">起点</param>
        /// <param name="cost">可行走节点到起点的最大估价</param>
        /// <param name="rule">搜寻规则</param>
        /// <returns>结果节点组</returns>
        public List <AStarNode> WalkableNodefinding(Vector2Int startIndex, int cost, AStarRule rule = null)
        {
            if (startIndex.x < 0 || startIndex.x >= _nodesWidth || startIndex.y < 0 || startIndex.y >= _nodesHeight)
            {
                GlobalTools.LogWarning("A*:寻可行走节点失败,起点的索引超出了网格的大小!");
                return(null);
            }

            if (rule != null)
            {
                foreach (AStarNode node in _nodes)
                {
                    rule.Apply(node);
                }
            }

            return(WalkableNodefinding(_nodes[startIndex.x, startIndex.y], cost));
        }
Esempio n. 4
0
        /// <summary>
        /// 寻路
        /// </summary>
        /// <param name="startIndex">起点的索引</param>
        /// <param name="endIndex">终点的索引</param>
        /// <param name="rule">搜寻规则</param>
        /// <returns>结果路径</returns>
        public List <AStarNode> Pathfinding(Vector2Int startIndex, Vector2Int endIndex, AStarRule rule = null)
        {
            if (startIndex.x < 0 || startIndex.x >= _nodesWidth || startIndex.y < 0 || startIndex.y >= _nodesHeight ||
                endIndex.x < 0 || endIndex.x >= _nodesWidth || endIndex.y < 0 || endIndex.y >= _nodesHeight)
            {
                GlobalTools.LogWarning("A*:寻路失败,起点或终点的索引超出了网格的大小!");
                return(null);
            }

            if (rule != null)
            {
                foreach (AStarNode node in _nodes)
                {
                    rule.Apply(node);
                }
            }

            return(Pathfinding(_nodes[startIndex.x, startIndex.y], _nodes[endIndex.x, endIndex.y]));
        }