TerrainLoader.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class TerrainLoader : MonoBehaviour
  5. {
  6. void Start()
  7. {
  8. StartCoroutine(LoadTerrain());
  9. }
  10. IEnumerator LoadTerrain()
  11. {
  12. WaitForEndOfFrame wait = new WaitForEndOfFrame();
  13. WWW www = WWW.LoadFromCacheOrDownload($"{Application.streamingAssetsPath}/terrainv2",0);
  14. yield return www;
  15. if (www.isDone)
  16. {
  17. var tempAb = www.assetBundle;
  18. GameObject terrain_di = tempAb.LoadAsset<GameObject>("Di");
  19. Instantiate(terrain_di, this.transform);
  20. for (int i = 0; i < 8; i++)
  21. {
  22. for (int j = 2; j < 8; j++)
  23. {
  24. GameObject terrain_tempQuad = tempAb.LoadAsset<GameObject>($"Mount_Rainier_x{i}_y{j}");
  25. Instantiate(terrain_tempQuad, this.transform);
  26. yield return wait;
  27. }
  28. }
  29. }
  30. else
  31. {
  32. Debug.LogError($"TerrainV2下载失败:{www.error}");
  33. }
  34. www.Dispose();
  35. }
  36. }