void FindGraph() { if (AstarPath.active != null) { var graph = AstarPath.active.data.recastGraph as NavmeshBase ?? AstarPath.active.data.navmesh; if (graph != null) { UseSpecifiedHandler(new TileHandler(graph)); handler.CreateTileTypesFromGraph(); } } }
void FindGraph() { if (AstarPath.active != null) { var graph = AstarPath.active.data.FindGraphWhichInheritsFrom(typeof(NavmeshBase)) as NavmeshBase; if (graph != null) { UseSpecifiedHandler(new TileHandler(graph)); handler.CreateTileTypesFromGraph(); } } }
void Start() { if (FindObjectsOfType(typeof(TileHandlerHelper)).Length > 1) { EB.Debug.LogError("There should only be one TileHandlerHelper per scene. Destroying."); Destroy(this); return; } #if BNICKSON_UPDATED CreateTileHandler(); instance = this; #else if (handler == null) { if (AstarPath.active == null || AstarPath.active.astarData.recastGraph == null) { EB.Debug.LogWarning("No AstarPath object in the scene or no RecastGraph on that AstarPath object"); } handler = new TileHandler(AstarPath.active.astarData.recastGraph); handler.CreateTileTypesFromGraph(); } #endif }
void Start() { // 原版, 保留之前的 // if (FindObjectsOfType(typeof(TileHandlerHelper)).Length > 1) { // Debug.LogError ("There should only be one TileHandlerHelper per scene. Destroying."); // Destroy (this); // return; // } // 删除之前的TileHandler, 便于采用最新Graph var objs = FindObjectsOfType(typeof(TileHandlerHelper)); if (objs.Length > 1) { for (int i = 0; i < objs.Length; i++) { if (objs[i] != this) { Destroy(objs[i]); } } } if (handler == null) { if (AstarPath.active == null || AstarPath.active.astarData.recastGraph == null) { Debug.LogWarning("No AstarPath object in the scene or no RecastGraph on that AstarPath object"); } handler = new TileHandler(AstarPath.active.astarData.recastGraph); handler.CreateTileTypesFromGraph(); } }
// Token: 0x06000735 RID: 1845 RVA: 0x00046804 File Offset: 0x00044C04 private void Start() { if (AstarPath.active == null) { Debug.LogWarning("No AstarPath object in the scene or no RecastGraph on that AstarPath object"); } for (int i = 0; i < AstarPath.active.astarData.graphs.Length; i++) { RecastGraph graph = (RecastGraph)AstarPath.active.astarData.graphs[i]; TileHandler tileHandler = new TileHandler(graph); tileHandler.CreateTileTypesFromGraph(); this.handlers.Add(tileHandler); } }
private void CreateTileHandler() { if (null == handler) { // changed checks around and called UpdateShortcuts to get recastGraph if (AstarPath.active == null || AstarPath.active.astarData == null) { EB.Debug.LogWarning("No AstarPath object in the scene or no astarData on that AstarPath object"); EventManager.instance.AddListener <NavMeshScanEvent>(CreateTileHandlerAndRemoveListener); return; } if (AstarPath.active.astarData.recastGraph == null) { Debug.Log("No AstarPath object in the scene or no RecastGraph on that AstarPath object, UpdateShortcuts"); AstarPath.active.astarData.UpdateShortcuts(); } if (AstarPath.active.astarData.recastGraph == null) { EB.Debug.LogWarning("No RecastGraph on that AstarPath object"); EventManager.instance.AddListener <NavMeshScanEvent>(CreateTileHandlerAndRemoveListener); return; } if (null == AstarPath.active.astarData.recastGraph.GetTiles()) { EB.Debug.LogWarning("No NavmeshTile in RecastGraph"); EventManager.instance.AddListener <NavMeshScanEvent>(CreateTileHandlerAndRemoveListener); return; } if (null == AstarPath.active.astarData.recastGraph.GetTiles()) { EB.Debug.LogWarning("CreateTileHandler() No RecastGraph in the scene"); return; } handler = new TileHandler(AstarPath.active.astarData.recastGraph); if (null == handler) { EB.Debug.LogWarning("CreateTileHandler() No TileHandler object"); return; } handler.CreateTileTypesFromGraph(); } }
void Start () { if (FindObjectsOfType(typeof(TileHandlerHelper)).Length > 1) { Debug.LogError("There should only be one TileHandlerHelper per scene. Destroying."); Destroy(this); return; } if (handler == null) { if (AstarPath.active == null || AstarPath.active.astarData.recastGraph == null) { Debug.LogWarning("No AstarPath object in the scene or no RecastGraph on that AstarPath object"); } handler = new TileHandler(AstarPath.active.astarData.recastGraph); handler.CreateTileTypesFromGraph(); } }
void Start() { if (FindObjectsOfType(typeof(TileHandlerHelper)).Length > 1) { Debug.LogError("There should only be one TileHandlerHelper per scene. Destroying."); Destroy(this); return; } if (handler == null) { if (AstarPath.active == null || AstarPath.active.astarData.recastGraph == null) { Debug.LogWarning("No AstarPath object in the scene or no RecastGraph on that AstarPath object"); } var graph = AstarPath.active.astarData.recastGraph; handler = new TileHandler(graph); graph.OnRecalculatedTiles += OnRecalculatedTiles; handler.CreateTileTypesFromGraph(); } }
public void Refresh(bool forceCreate = false) { if (!graph.enableNavmeshCutting) { if (handler != null) { handler.cuts.Clear(); handler.ReloadInBounds(new IntRect(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue)); // Make sure the updates are applied immediately. // This is important because if navmesh cutting is enabled immediately after this // then it will call CreateTileTypesFromGraph, and we need to ensure that it is not // calling that when the graph still has cuts in it as they will then be baked in. AstarPath.active.FlushGraphUpdates(); AstarPath.active.FlushWorkItems(); forcedReloadRects.ClearFast(); handler = null; } } else if ((handler == null && (forceCreate || NavmeshClipper.allEnabled.Count > 0)) || (handler != null && !handler.isValid)) { // Note: Only create a handler if there are any navmesh cuts in the scene. // We don't want to waste a lot of memory if navmesh cutting isn't actually used for anything // and even more important: we don't want to do any sporadic updates to the graph which // may clear the graph's tags or change it's structure (e.g from the delaunay optimization in the TileHandler). // The tile handler is invalid (or doesn't exist), so re-create it handler = new TileHandler(graph); for (int i = 0; i < NavmeshClipper.allEnabled.Count; i++) { AddClipper(NavmeshClipper.allEnabled[i]); } handler.CreateTileTypesFromGraph(); // Reload in huge bounds. This will cause all tiles to be updated. forcedReloadRects.Add(new IntRect(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue)); } }
/** Checks all NavmeshCut instances and updates graphs if needed. * \note This schedules updates for all necessary tiles to happen as soon as possible. * The pathfinding threads will continue to calculate the paths that they were calculating when this function * was called and then they will be paused and the graph updates will be carried out (this may be several frames into the * future and the graph updates themselves may take several frames to complete). * If you want to force all navmesh cutting to be completed in a single frame call this method * and immediately after call AstarPath.FlushWorkItems. */ public void ForceUpdate() { if (handler == null) { throw new System.Exception("Cannot update graphs. No TileHandler. Do not call this method in Awake."); } lastUpdateTime = Time.realtimeSinceStartup; // Get all navmesh cuts in the scene List <NavmeshCut> cuts = NavmeshCut.GetAll(); if (!handler.isValid) { Debug.Log("TileHandler no longer matched the underlaying RecastGraph (possibly because of a graph scan). Recreating TileHandler..."); handler = new TileHandler(handler.graph); handler.CreateTileTypesFromGraph(); // Reload in huge bounds. Cannot use infinity because that will not convert well to integers // This will cause all tiles to be updated forcedReloadBounds.Add(new Bounds(Vector3.zero, new Vector3(10000000, 10000000, 10000000))); } if (forcedReloadBounds.Count == 0) { int any = 0; // Check if any navmesh cuts need updating for (int i = 0; i < cuts.Count; i++) { if (cuts[i].RequiresUpdate()) { any++; break; } } // Nothing needs to be done for now if (any == 0) { return; } } // Start batching tile updates which is good for performance // if we are updating a lot of them bool end = handler.StartBatchLoad(); // Reload all tiles which touch the bounds in the forcedReloadBounds list for (int i = 0; i < forcedReloadBounds.Count; i++) { handler.ReloadInBounds(forcedReloadBounds[i]); } forcedReloadBounds.Clear(); // Reload all bounds touching the previous bounds and current bounds // of navmesh cuts that have moved or changed in some other way for (int i = 0; i < cuts.Count; i++) { if (cuts[i].enabled) { if (cuts[i].RequiresUpdate()) { handler.ReloadInBounds(cuts[i].LastBounds); handler.ReloadInBounds(cuts[i].GetBounds()); } } else if (cuts[i].RequiresUpdate()) { // The navmesh cut has been disabled // Make sure the tile where it was is updated handler.ReloadInBounds(cuts[i].LastBounds); } } // Notify navmesh cuts that they have been updated // This will cause RequiresUpdate to return false // until it is changed again for (int i = 0; i < cuts.Count; i++) { if (cuts[i].RequiresUpdate()) { cuts[i].NotifyUpdated(); } } if (end) { handler.EndBatchLoad(); } }