Example #1
0
 private bool CheckCanConnection(GridMapNode node1, GridMapNode node2)
 {
     if (node1.Walkable == false || node2.Walkable == false)
     {
         return(false);
     }
     return(true);
 }
Example #2
0
 private void CalculateNodePro(GridMapNode node)
 {
     if (node == null)
     {
         Debug.LogError("MapNode == null");
         return;
     }
     //node.Position = (FPVector3)(this.m_Transform.position + new Vector3(node.XIndex + 0.5f,0,node.ZIndex + 0.5f));
     node.Walkable = this.m_oData.Walkable[node.GridIndex];
 }
Example #3
0
 public void Scan()
 {
     this.m_listNodes = new MapNode[this.m_oData.Width * this.m_oData.Height];
     for (int i = 0; i < this.m_oData.Height; i++)
     {
         for (int j = 0; j < this.m_oData.Width; j++)
         {
             var index = this.CaculateIndex(j, i);
             var node  = new GridMapNode();
             node.GridIndex = index;
             node.XIndex    = j;
             node.ZIndex    = i;
             this.CalculateNodePro(node);
         }
     }
 }
Example #4
0
        public void StartFind(MapNode startNode, MapNode endNode)
        {
            var startPathNode = this.GetPathNode(startNode);
            var endPathNode   = this.GetPathNode(endNode);

            this.CaculatePathNode(startNode, endNode, ref startPathNode);
            //然后加入到二叉堆中
            var heap    = new NativeBinaryHeap(128);
            var offsets = this.m_oMap.GetNeighbourOffsets();

            for (int i = 0; i < 8; i++)
            {
                if (startNode.HasConnectInDir(i))
                {
                    //如果i方向的Node连通的话
                    var         index = startNode.NodeIndex + offsets[i];
                    GridMapNode other = this.m_oMap.GetMapNode(index) as GridMapNode;
                    if (other != null)
                    {
                    }
                }
            }
        }
Example #5
0
 private void CaculateConnection(GridMapNode node)
 {
     if (node == null)
     {
         return;
     }
     if (node.Walkable == false)
     {
         node.SetAllNoConnect();
         return;
     }
     if (this.m_oData.neighboursType == ENeighboursType.Eight ||
         this.m_oData.neighboursType == ENeighboursType.Four)
     {
         byte fourDirConnectFlags = 0;
         for (int i = 0; i < 4; i++)
         {
             var offset = this.neighbourOffsets[i];
             int nx     = node.XIndex + offset.x;
             int nz     = node.ZIndex + offset.y;
             if (nx >= 0 && nz >= 0 &&
                 nx < this.m_oData.Width && nz < this.m_oData.Height)
             {
                 var nNode = this.m_listNodes[this.CaculateIndex(nx, nz)] as GridMapNode;
                 if (nNode != null)
                 {
                     if (this.CheckCanConnection(nNode, node))
                     {
                         fourDirConnectFlags |= (byte)(1 << i);
                         //0001
                         //0011....1111
                     }
                 }
             }
         }
         if (this.m_oData.neighboursType == ENeighboursType.Eight)
         {
             byte diagConns = 0;//斜边方向是否有连接
             for (int i = 0; i < 4; i++)
             {
                 var offset = this.neighbourOffsets[i];
                 int nx     = node.XIndex + offset.x;
                 int nz     = node.ZIndex + offset.y;
                 if (nx >= 0 && nz >= 0 &&
                     nx < this.m_oData.Width && nz < this.m_oData.Height)
                 {
                     var nNode = this.m_listNodes[this.CaculateIndex(nx, nz)] as GridMapNode;
                     if (nNode != null)
                     {
                         if (this.CheckCanConnection(nNode, node))
                         {
                             fourDirConnectFlags |= (byte)(1 << i);
                             //0001
                             //0011....1111
                         }
                     }
                 }
             }
         }
     }
 }