Exemplo n.º 1
0
 public void AddNextNavmeshLink(NavmeshTileLink link)
 {
     if (link == null)
     {
         return;
     }
     _nextTileLinkList.Add(link);
 }
Exemplo n.º 2
0
        private void GenerateTileLink(ObjectPool linkPool, ref NavmeshTile tileFrom, ref NavmeshTile tileTo)
        {
            int linkCount = 0;

            //float sampleRadius = _offset;
            //for (int j = 0; j < 10; j++)
            //{
            //    float heightOffset = j * sampleRadius;
            for (int i = 0; i < _sampleCount; i++)
            {
                bool hasNavmeshAtStartPos = NavMesh.SamplePosition(_samplePosArrayOne[i], out NavMeshHit hitResultOne, _offset, RuntimePathfinding.areaMaskBakeLink);
                bool hasNavmeshAtEndPos   = NavMesh.SamplePosition(_samplePosArrayTwo[i], out NavMeshHit hitResultTwo, _offset, RuntimePathfinding.areaMaskBakeLink);
                if (hasNavmeshAtStartPos && hasNavmeshAtEndPos)
                {
                    bool hasPath = NavMesh.CalculatePath(hitResultOne.position, hitResultTwo.position, RuntimePathfinding.areaMaskBakeLink, _navmeshPath);
                    if (hasPath)
                    {
                        NavmeshTileLink link = linkPool.GetObject <NavmeshTileLink>();
                        link.Init();
                        if (tileFrom.ContainsPosition2D(hitResultOne.position))
                        {
                            link.SetLinkPoint(hitResultOne.position, hitResultTwo.position);
                        }
                        else
                        {
                            link.SetLinkPoint(hitResultTwo.position, hitResultOne.position);
                        }
                        tileFrom.AddNextNavmeshLink(link);
                        linkCount++;
                    }
                }
            }
            //}

            if (linkCount == 0)
            {
                Debug.LogError("No link generate -> " + tileFrom + " " + tileTo);
            }
        }