コード例 #1
0
        /// <summary>
        /// Used to initialize the navigation mesh so it will allow building tiles
        /// This will store the build settings and create the amount of layers corresponding to the number of NavigationAgentSettings
        /// </summary>
        /// <param name="buildSettings"></param>
        /// <param name="agentSettings">Agent setting to use</param>
        public void Initialize(NavigationMeshBuildSettings buildSettings, NavigationAgentSettings[] agentSettings)
        {
            BuildSettings = buildSettings;

            // Remove layers that are no longer needed
            if (LayersInternal.Count > agentSettings.Length)
            {
                LayersInternal.RemoveRange(agentSettings.Length, LayersInternal.Count - agentSettings.Length);
            }

            // Initialize layers
            for (int i = 0; i < agentSettings.Length; i++)
            {
                NavigationMeshLayer layer;
                if (LayersInternal.Count <= i)
                {
                    layer = new NavigationMeshLayer();
                    LayersInternal.Add(layer);
                }
                else
                {
                    layer = LayersInternal[i];
                }
                layer.AgentSettings = agentSettings[i];
                layer.BuildSettings = buildSettings;
            }
        }
コード例 #2
0
        /// <summary>
        /// Clamps X-Z coordinates to a navigation mesh tile
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="boundingBox"></param>
        /// <param name="tileCoord"></param>
        /// <returns></returns>
        public static BoundingBox ClampBoundingBoxToTile(NavigationMeshBuildSettings settings, BoundingBox boundingBox, Point tileCoord)
        {
            float tcs = settings.TileSize * settings.CellSize;
            Vector2 tileMin = new Vector2(tileCoord.X * tcs, tileCoord.Y * tcs);
            Vector2 tileMax = tileMin + new Vector2(tcs);

            boundingBox.Minimum.X = tileMin.X;
            boundingBox.Minimum.Z = tileMin.Y;
            boundingBox.Maximum.X = tileMax.X;
            boundingBox.Maximum.Z = tileMax.Y;

            // Snap Y to tile height to avoid height differences between tiles
            boundingBox.Minimum.Y = (float)Math.Floor(boundingBox.Minimum.Y / settings.CellHeight) * settings.CellHeight;
            boundingBox.Maximum.Y = (float)Math.Ceiling(boundingBox.Maximum.Y / settings.CellHeight) * settings.CellHeight;

            return boundingBox;
        }
コード例 #3
0
 /// <summary>
 /// Check which tiles overlap a given bounding box
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="boundingBox"></param>
 /// <returns></returns>
 public static List<Point> GetOverlappingTiles(NavigationMeshBuildSettings settings, BoundingBox boundingBox)
 {
     List<Point> ret = new List<Point>();
     float tcs = settings.TileSize * settings.CellSize;
     Vector2 start = boundingBox.Minimum.XZ() / tcs;
     Vector2 end = boundingBox.Maximum.XZ() / tcs;
     Point startTile = new Point(
         (int)Math.Floor(start.X),
         (int)Math.Floor(start.Y));
     Point endTile = new Point(
         (int)Math.Ceiling(end.X),
         (int)Math.Ceiling(end.Y));
     for (int y = startTile.Y; y < endTile.Y; y++)
     {
         for (int x = startTile.X; x < endTile.X; x++)
         {
             ret.Add(new Point(x, y));
         }
     }
     return ret;
 }
コード例 #4
0
 public bool Equals(NavigationMeshBuildSettings other)
 {
     return(CellHeight.Equals(other.CellHeight) && CellSize.Equals(other.CellSize) && TileSize == other.TileSize && MinRegionArea.Equals(other.MinRegionArea) &&
            RegionMergeArea.Equals(other.RegionMergeArea) && MaxEdgeLen.Equals(other.MaxEdgeLen) && MaxEdgeError.Equals(other.MaxEdgeError) &&
            DetailSamplingDistance.Equals(other.DetailSamplingDistance) && MaxDetailSamplingError.Equals(other.MaxDetailSamplingError));
 }
コード例 #5
0
 public bool Equals(NavigationMeshBuildSettings other)
 {
     return CellHeight.Equals(other.CellHeight) && CellSize.Equals(other.CellSize) && TileSize == other.TileSize && MinRegionArea.Equals(other.MinRegionArea) &&
            RegionMergeArea.Equals(other.RegionMergeArea) && MaxEdgeLen.Equals(other.MaxEdgeLen) && MaxEdgeError.Equals(other.MaxEdgeError) &&
            DetailSamplingDistance.Equals(other.DetailSamplingDistance) && MaxDetailSamplingError.Equals(other.MaxDetailSamplingError);
 }