欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > A*StarPathfinding的更新地图

A*StarPathfinding的更新地图

2024/10/24 12:32:34 来源:https://blog.csdn.net/u010698150/article/details/139605908  浏览:    关键词:A*StarPathfinding的更新地图

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);}}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com