Beispiel #1
0
        public GameObject LoadTerrainModel(TerrainElement terrainElement, Transform parentTransform)
        {
            if (terrainMaterials == null || terrainModel == null)
            {
                if (InitializeTerrainMaterials() == false)
                {
                    Debug.LogError("Could not initialize terrain materials.", gameObject);
                    return(null);
                }
            }
            if (terrainElement.terrainType == TerrainType.Empty)
            {
                return(null);
            }
            GameObject newTerrainModel = Instantiate(terrainModel, parentTransform);

            if (terrainMaterials.ContainsKey(terrainElement.terrainType))
            {
                MeshRenderer meshRenderer = newTerrainModel.GetComponent <MeshRenderer>();
                if (meshRenderer == null)
                {
                    Debug.LogError("Terrain model prefab is missing MeshRenderer component.", gameObject);
                    return(newTerrainModel);
                }
                meshRenderer.material = terrainMaterials[terrainElement.terrainType];
            }
            newTerrainModel.name = $"{terrainElement.terrainType.ToString()} Model";
            return(newTerrainModel);
        }
Beispiel #2
0
 public void InitializeTerrain(TerrainElement terrainElement)
 {
     this.terrainElement = terrainElement;
     currentTerrainType  = terrainElement.terrainType;
     InitializeMapElement(terrainElement.mapElement);
     isInitialized = true;
 }