public void saveTopologyLayer() { if (topology == null) { topology = GameObject.FindGameObjectWithTag("Topology").GetComponent <TopologyMesh>(); } LandData topologyData = GameObject.FindGameObjectWithTag("Land").transform.Find("Topology").GetComponent <LandData>(); TerrainMap <int> topologyMap = new TerrainMap <int>(topology.top, 1); float[,,] splatMap = TypeConverter.singleToMulti(topologyData.splatMap, 2); for (int i = 0; i < topologyMap.res; i++) { for (int j = 0; j < topologyMap.res; j++) { if (splatMap[i, j, 0] > 0) { topologyMap[i, j] = topologyMap[i, j] | (int)oldTopologyLayer; } if (splatMap[i, j, 1] > 0) { topologyMap[i, j] = topologyMap[i, j] & ~(int)oldTopologyLayer; } } } topology.top = topologyMap.ToByteArray(); }
public void changeLandLayer() { if (topology == null) { topology = GameObject.FindGameObjectWithTag("Topology").GetComponent <TopologyMesh>(); } if (selectedLandLayer != null) { selectedLandLayer.save(); } switch (landLayer.ToLower()) { case "ground": selectedLandLayer = GameObject.FindGameObjectWithTag("Land").transform.Find("Ground").GetComponent <LandData>(); break; case "biome": selectedLandLayer = GameObject.FindGameObjectWithTag("Land").transform.Find("Biome").GetComponent <LandData>(); break; case "alpha": selectedLandLayer = GameObject.FindGameObjectWithTag("Land").transform.Find("Alpha").GetComponent <LandData>(); break; case "topology": //updated topology values //selectedLandLayer.splatMap; saveTopologyLayer(); selectedLandLayer = GameObject.FindGameObjectWithTag("Land").transform.Find("Topology").GetComponent <LandData>(); selectedLandLayer.setData(topology.getSplatMap((int)topologyLayer), "topology"); break; } selectedLandLayer.setLayer(); }
public void Load(WorldSerialization blob) { if (topology == null) { topology = GameObject.FindGameObjectWithTag("Topology").GetComponent <TopologyMesh>(); } Debug.Log("Map hash: " + blob.Checksum); cleanUpMap(); var terrainSize = new Vector3(blob.world.size, 1000, blob.world.size); var terrainPosition = 0.5f * terrainSize; LandData groundLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Ground").GetComponent <LandData>(); LandData biomeLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Biome").GetComponent <LandData>(); LandData alphaLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Alpha").GetComponent <LandData>(); LandData topologyLandData = GameObject.FindGameObjectWithTag("Land").transform.Find("Topology").GetComponent <LandData>(); Terrain land = GameObject.FindGameObjectWithTag("Land").GetComponent <Terrain>(); Terrain water = GameObject.FindGameObjectWithTag("Water").GetComponent <Terrain>(); TopologyMesh topography = GameObject.FindGameObjectWithTag("Topology").GetComponent <TopologyMesh>(); WorldConverter.MapInfo terrains = WorldConverter.worldToTerrain(blob); topography.InitMesh(terrains.topology); land.terrainData.heightmapResolution = terrains.resolution; land.terrainData.size = terrains.size; water.terrainData.heightmapResolution = terrains.resolution; water.terrainData.size = terrains.size; land.terrainData.SetHeights(0, 0, terrains.land.heights); water.terrainData.SetHeights(0, 0, terrains.water.heights); land.terrainData.alphamapResolution = terrains.resolution; //land.terrainData.baseMapResolution = terrains.resolution; //land.terrainData.SetDetailResolution(terrains.resolution,8); land.terrainData.size = terrains.size; groundLandData.setData(terrains.splatMap, "ground"); biomeLandData.setData(terrains.biomeMap, "biome"); alphaLandData.setData(terrains.alphaMap, "alpha"); topologyLandData.setData(topology.getSplatMap((int)topologyLayer), "topology"); changeLandLayer(); Transform prefabsParent = GameObject.FindGameObjectWithTag("Prefabs").transform; GameObject defaultObj = Resources.Load <GameObject>("Prefabs/DefaultPrefab"); for (int i = 0; i < terrains.prefabData.Length; i++) { GameObject newObj = spawnPrefab(defaultObj, terrains.prefabData[i], prefabsParent); newObj.GetComponent <PrefabDataHolder>().prefabData = terrains.prefabData[i]; } Transform pathsParent = GameObject.FindGameObjectWithTag("Paths").transform; GameObject pathObj = Resources.Load <GameObject>("Paths/Path"); for (int i = 0; i < terrains.pathData.Length; i++) { Vector3 averageLocation = Vector3.zero; for (int j = 0; j < terrains.pathData[i].nodes.Length; j++) { averageLocation += terrains.pathData[i].nodes[j]; } averageLocation /= terrains.pathData[i].nodes.Length; GameObject newObject = Instantiate(pathObj, averageLocation + terrainPosition, Quaternion.identity, pathsParent); newObject.GetComponent <PathDataHolder>().pathData = terrains.pathData[i]; newObject.GetComponent <PathDataHolder>().offset = terrainPosition; } }