/// <summary> /// Creates the world simulation /// </summary> public void GenerateWorld() { //Clean up terrain if it exists if (this.TerrainActor != null) { UnityEngine.Object.DestroyImmediate(this.TerrainActor.gameObject); this.TerrainActor = null; } this.World = null; var terrainGameObject = new UnityEngine.GameObject("Terrain Actor"); terrainGameObject.transform.parent = this.transform; switch (this.TerrainType) { //If test, instantiate test terrain but not world case TerrainTypes.Test: { terrainGameObject.AddComponent <Terrain.TestTerrainActor>(); this.TerrainActor = terrainGameObject.GetComponent <Terrain.TerrainActor>(); break; } //If simple, instantiate terrain and world case TerrainTypes.Simple: { terrainGameObject.AddComponent <Terrain.SimpleTerrainActor>(); this.TerrainActor = terrainGameObject.GetComponent <Terrain.TerrainActor>(); this.World = new World(TerrainActor.Terrain); break; } default: { throw new System.NotImplementedException(); } } }
public void Start() { //Search for an existing terrain actor string terrainName = "Terrain Actor"; var terrainTransform = transform.Find(terrainName); UnityEngine.GameObject terrainGameObject = terrainTransform != null ? terrainTransform.gameObject : null; //If none found, create new if (terrainGameObject == null) { this.GenerateWorld(); } //Else couple with existing else { this.TerrainActor = terrainGameObject.GetComponent <Terrain.TerrainActor>(); this.World = new World(TerrainActor.Terrain); } }