Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Update()
- {
- //If this feature is disable don't load/unload
- if (enableThisFeature == false) return;
- //if player is moving, dont load//unload
- if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
- {
- //do nothing when player is moving
- return;
- }
- DeactivateDistantTiles();
- }
- private void DeactivateDistantTiles()
- {
- playerPosition = transform.position;
- playerPosition = cameraController.currentActiveCam.transform.position; //transform.position;
- checkPlayerPositionChangeing = playerPosition.z != playerLastPos.z || playerPosition.x != playerLastPos.x;
- if (checkPlayerPositionChangeing)
- {
- ABLoadUnloadLoopCall();
- }
- //playerLastPos = this.gameObject.transform.position;
- playerLastPos = cameraController.currentActiveCam.transform.position;
- }
- Vector3 tilePosition;
- float xDistance;
- float zDistance;
- public void ABLoadUnloadLoopCall()
- {
- //old
- //foreach (SingleABLoader tile in tiles)
- //{
- // Debug.Log("ABLoadUnloadLoopCall 123");
- // Vector3 tilePosition = tile.gameObject.transform.position + (tileSize / 2f);
- // float xDistance = Mathf.Abs(tilePosition.x - playerPosition.x);
- // float zDistance = Mathf.Abs(tilePosition.z - playerPosition.z);
- // if (xDistance + zDistance > maxDistance)
- // {
- // /*If you don't want to destroy the object on unload then use below line otherwise use DestroyBundleObject with true pararmeter */
- // //tile.DestroyBundleObject();
- // tile.DestroyBundleObject(true);
- // }
- // else
- // {
- // tile.StartDownloadingAB();
- // }
- //}
- //new
- for(int i = 0; i < tiles.Length; i++)
- {
- tilePosition = tiles[i].gameObject.transform.position + (tileSize / 2f);
- xDistance = Mathf.Abs(tilePosition.x - playerPosition.x);
- zDistance = Mathf.Abs(tilePosition.z - playerPosition.z);
- if (xDistance + zDistance > maxDistance)
- {
- /*If you don't want to destroy the object on unload then use below line otherwise use DestroyBundleObject with true pararmeter */
- //tiles[i].DestroyBundleObject();
- tiles[i].DestroyBundleObject(true);
- }
- else
- {
- tiles[i].StartDownloadingAB();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement