Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. private void Update()
  2. {
  3. //If this feature is disable don't load/unload
  4. if (enableThisFeature == false) return;
  5.  
  6. //if player is moving, dont load//unload
  7. if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
  8. {
  9. //do nothing when player is moving
  10. return;
  11. }
  12.  
  13. DeactivateDistantTiles();
  14. }
  15.  
  16. private void DeactivateDistantTiles()
  17. {
  18. playerPosition = transform.position;
  19. playerPosition = cameraController.currentActiveCam.transform.position; //transform.position;
  20.  
  21. checkPlayerPositionChangeing = playerPosition.z != playerLastPos.z || playerPosition.x != playerLastPos.x;
  22.  
  23. if (checkPlayerPositionChangeing)
  24. {
  25. ABLoadUnloadLoopCall();
  26. }
  27.  
  28. //playerLastPos = this.gameObject.transform.position;
  29. playerLastPos = cameraController.currentActiveCam.transform.position;
  30.  
  31.  
  32.  
  33. }
  34. Vector3 tilePosition;
  35. float xDistance;
  36. float zDistance;
  37. public void ABLoadUnloadLoopCall()
  38. {
  39.  
  40. //old
  41. //foreach (SingleABLoader tile in tiles)
  42. //{
  43. // Debug.Log("ABLoadUnloadLoopCall 123");
  44. // Vector3 tilePosition = tile.gameObject.transform.position + (tileSize / 2f);
  45.  
  46. // float xDistance = Mathf.Abs(tilePosition.x - playerPosition.x);
  47. // float zDistance = Mathf.Abs(tilePosition.z - playerPosition.z);
  48.  
  49. // if (xDistance + zDistance > maxDistance)
  50. // {
  51. // /*If you don't want to destroy the object on unload then use below line otherwise use DestroyBundleObject with true pararmeter */
  52. // //tile.DestroyBundleObject();
  53. // tile.DestroyBundleObject(true);
  54. // }
  55. // else
  56. // {
  57. // tile.StartDownloadingAB();
  58. // }
  59.  
  60. //}
  61. //new
  62. for(int i = 0; i < tiles.Length; i++)
  63. {
  64.  
  65. tilePosition = tiles[i].gameObject.transform.position + (tileSize / 2f);
  66.  
  67. xDistance = Mathf.Abs(tilePosition.x - playerPosition.x);
  68. zDistance = Mathf.Abs(tilePosition.z - playerPosition.z);
  69.  
  70. if (xDistance + zDistance > maxDistance)
  71. {
  72.  
  73. /*If you don't want to destroy the object on unload then use below line otherwise use DestroyBundleObject with true pararmeter */
  74. //tiles[i].DestroyBundleObject();
  75. tiles[i].DestroyBundleObject(true);
  76.  
  77. }
  78. else
  79. {
  80. tiles[i].StartDownloadingAB();
  81. }
  82.  
  83. }
  84.  
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement