Graph Updates during Runtime - A* Pathfinding Project (arongranberg.com)
1、Scan:直接更新整个场景的地图,地图复杂动画,时间会比较长,场景会卡至烘焙完成
AstarPath.active.Scan();
2、UpdateGraphs:异步刷新指定Bounds的
void ZoneUpdateBounds (Collider[] list){time = Time.realtimeSinceStartup;foreach (var item in list){Bounds bounds = item.bounds;AstarPath.active.UpdateGraphs(bounds);}}
3、SaveToFile / LoadFromFile:加载已经保存的资源,此方法最快,但需要将变化的物体设置到对应的位置上
void ZoneLoadFromFile(){time = Time.realtimeSinceStartup;string path = @"D:\Testing\2\2.bytes";try{byte[] bytes = Pathfinding.Serialization.AstarSerializer.LoadFromFile(path);DeserializeGraphs(bytes);}catch (System.Exception e){Debug.LogError("Could not load from file at '" + path + "'\n" + e);}}private void DeserializeGraphs(byte[] bytes){try{AstarPath.active.data.DeserializeGraphs(bytes);for (int i = 0; i < AstarPath.active.graphs.Length; i++){var data = (AstarPath.active.graphs[i] as IGraphInternals).SerializedEditorSettings;if (data != null) Pathfinding.Serialization.TinyJsonDeserializer.Deserialize(data, AstarPath.active.graphs[i].GetType(), AstarPath.active.graphs[i], AstarPath.active.gameObject);}}catch (System.Exception e){Debug.LogError("Failed to deserialize graphs");Debug.LogException(e);AstarPath.active.data.SetData(null);}}