LoadTerrainLayer.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. using System.Collections;
  3. using TerrainComposer2;
  4. public class LoadTerrainLayer : MonoBehaviour {
  5. public GameObject terrainLayerPrefab;
  6. public bool generateOnStart;
  7. public bool instantGenerate;
  8. void Start ()
  9. {
  10. InstantiateTerrainLayer();
  11. if (generateOnStart) TC_Generate.instance.Generate(instantGenerate);
  12. }
  13. public void InstantiateTerrainLayer()
  14. {
  15. if (terrainLayerPrefab == null) return;
  16. if (terrainLayerPrefab.GetComponent<TC_TerrainLayer>() == null) return;
  17. TC_Area2D area2D = TC_Area2D.current;
  18. if (area2D == null) return;
  19. // Destroy the Terrain Layer that is currently assigned
  20. if (area2D.terrainLayer != null) Destroy(area2D.terrainLayer.gameObject);
  21. // Instantiate the Terrain Layer Prefab
  22. GameObject terrainLayerGO = Instantiate(terrainLayerPrefab);
  23. area2D.terrainLayer = terrainLayerGO.GetComponent<TC_TerrainLayer>();
  24. // Assign all nodes in Terrain Layer
  25. area2D.terrainLayer.GetItems(false);
  26. }
  27. }