Advertisement
Guest User

NavMeshBuilder caching and updating

a guest
Apr 10th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1.     IEnumerator Start() // Step one, beginning with caching data before going into the update loop
  2.     {
  3.         m_NavMesh = new NavMeshData();
  4.         m_Instance = NavMesh.AddNavMeshData(m_NavMesh);
  5.         if (m_Tracked == null)
  6.             m_Tracked = transform;
  7.  
  8.         VoxelMapNavMeshSourceTag.Collect(ref m_Sources); //Populating the sources array and the array with moving objects helper class
  9.  
  10.         defaultBuildSettings = NavMesh.GetSettingsByID(0);
  11.         bounds = QuantizedBounds();
  12.  
  13.         while (true)
  14.         {
  15.             UpdateNavMesh(true); //Pasted below
  16.             yield return m_Operation;
  17.         }
  18.     }
  19.  
  20.     void UpdateNavMesh(bool asyncUpdate = false) //Update loop, first updating moving sources, followed by NavMesh rebuild
  21.     {
  22.         VoxelMapNavMeshSourceTag.UpdatePositions(m_Sources); //Iterates through the moving objects array, pasted below
  23.  
  24.         if (asyncUpdate)
  25.             m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
  26.         else
  27.             NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
  28.     }
  29.  
  30.     public static void UpdatePositions(List<NavMeshBuildSource> sourcesArray) //Content of the UpdatePositions method
  31.     {
  32.         for (var i = 0; i < sourcePositionUpdaters.Count; i++)
  33.         {
  34.             sourcesArray[sourcePositionUpdaters[i].index] = sourcePositionUpdaters[i].CloneSource(); // <- This works fine,                 creates new instance of the source and replaces the old one in the sources array at the same index
  35.             //sourcePositionUpdaters[i].UpdatePosition();// <- This doesn't work (updating existing sources transform)
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement