public override void OnCreate (Chunk chunk, Coord coord) { //creating gameobject GameObject go = new GameObject(); go.name = "Terrain " + coord.x + "," + coord.z; go.transform.parent = MapMagic.instance.transform; go.transform.localPosition = coord.ToVector3(MapMagic.instance.terrainSize); //creating terrain chunk.terrain = go.AddComponent<Terrain>(); TerrainCollider terrainCollider = go.AddComponent<TerrainCollider>(); TerrainData terrainData = new TerrainData(); chunk.terrain.terrainData = terrainData; terrainCollider.terrainData = terrainData; terrainData.size = new Vector3(MapMagic.instance.terrainSize, MapMagic.instance.terrainHeight, MapMagic.instance.terrainSize); //chunk settings chunk.coord = coord; chunk.SetSettings(); chunk.clear = true; //if (!instance.isEditor || instance.instantGenerate) { chunk.start = true; } MapMagic.CallRepaintWindow(); //if (MapMagic.instance.isEditor) if (RepaintWindow != null) RepaintWindow(); }
public void DrawGizmo() { #if UNITY_EDITOR Vector3 s = size.ToVector3(1); Vector3 o = offset.ToVector3(1); Gizmos.DrawWireCube(o + s / 2, s); #endif }
public override void OnMove (Chunk chunk, Coord newCoord) { //chunk.terrain.gameObject.SetActive(false); //wrapper.terrain.enabled = false; chunk.coord = newCoord; chunk.terrain.transform.localPosition = newCoord.ToVector3(instance.terrainSize); //stopping all generate and all apply (they will be resumed in processthread) chunk.stop = true; MapMagic.instance.StopAllCoroutines(); MapMagic.instance.applyRunning = false; //resetting results chunk.results.Clear(); chunk.ready.Clear(); chunk.clear = true; //for (int i=0; i<generators.Length; i++) // if (wrapper.generated.Contains(generators[i])) wrapper.generated.Remove(generators[i]); //generators.array[i].SetGenerated(wrapper, false); //if (!instance.isEditor || instance.instantGenerate) { chunk.start = true; } }
public void DrawSelectionFrame (Coord coord, float width=3f) { float margins = 3; int numSteps = 50; float sideSize = MapMagic.instance.terrainSize - margins*2f; float stepDist = sideSize / numSteps; Vector3 start = coord.ToVector3(MapMagic.instance.terrainSize) + new Vector3(margins,0,margins) + MapMagic.instance.transform.position; Chunk chunk = MapMagic.instance.chunks[coord]; if (chunk==null || chunk.terrain==null) { Handles.DrawAAPolyLine( width, new Vector3[] { start, start+new Vector3(sideSize,0,0), start+new Vector3(sideSize,0,sideSize), start+new Vector3(0,0,sideSize), start} ); } else { //DrawTerrainFrame(terrain.terrain, margins, numSteps:50, width:width); DrawLineOnTerrain(chunk.terrain, start, new Vector3(stepDist,0,0), numSteps+1, width); DrawLineOnTerrain(chunk.terrain, start+new Vector3(0,0,sideSize), new Vector3(stepDist,0,0), numSteps+1, width); DrawLineOnTerrain(chunk.terrain, start, new Vector3(0,0,stepDist), numSteps+1, width); DrawLineOnTerrain(chunk.terrain, start+new Vector3(sideSize,0,0), new Vector3(0,0,stepDist), numSteps+1, width); } }