void OnSceneGUI() { LSubTerrTempTrees tar = (LSubTerrTempTrees)target; foreach (KeyValuePair <GameObject, GlobalTreeInfo> kvp in tar.m_TempMap) { if (kvp.Key != null) { string content = ""; content += "World Pos: " + kvp.Key.transform.position.ToString() + "\r\n"; content += "Terrain Pos: (" + kvp.Value._treeInfo.m_pos.x.ToString("0.0000") + ", " + kvp.Value._treeInfo.m_pos.y.ToString("0.0000") + ", " + kvp.Value._treeInfo.m_pos.z.ToString("0.0000") + ")\r\n"; content += "Terrain Key: " + kvp.Value._terrainIndex.ToString() + " (" + LSubTerrUtils.IndexToPos(kvp.Value._terrainIndex).x.ToString() + "," + LSubTerrUtils.IndexToPos(kvp.Value._terrainIndex).z.ToString() + ")\r\n"; IntVector3 cell = new IntVector3(Mathf.FloorToInt(kvp.Key.transform.position.x) % LSubTerrConstant.Size, Mathf.FloorToInt(kvp.Key.transform.position.y), Mathf.FloorToInt(kvp.Key.transform.position.z) % LSubTerrConstant.Size); int key = LSubTerrUtils.TreePosToKey(cell); content += "Tree Cell: " + cell.ToString() + "\r\n"; content += "Cell Key: " + key.ToString() + "\r\n"; content += "Tree Proto: " + kvp.Value._treeInfo.m_protoTypeIdx.ToString() + "\r\n"; content += "Tree Scale: (" + kvp.Value._treeInfo.m_widthScale.ToString("0.00") + ", " + kvp.Value._treeInfo.m_heightScale.ToString("0.00") + ")\r\n"; Handles.Label(kvp.Key.transform.position, content); } } }
public void MoveBlockGroup(BlockGroup group, IntVector3 input) { for (int i = 0; i < group.Blocks.Length; i++) { Block block = group.Blocks[i]; IntVector3 newCoordinate = block.Coordinate + input; block.Coordinate = newCoordinate; Vector3 worldPos = new Vector3(newCoordinate.x + cubeSize.x / 2f, newCoordinate.y + cubeSize.y / 2f, newCoordinate.z + cubeSize.z / 2f); block.gObj.transform.position = StartPos + worldPos; block.gObj.name = newCoordinate.ToString(); } }
public virtual Chunk GenerateChunk(IntVector3 start, IntVector3 end, int lod = 1) { Debug.WriteLine("Generating Chunk at " + start.ToString()); var chunk = new Chunk(start, end); var pos = new IntVector3(start); for (pos.X = chunk.Start.X; pos.X < chunk.End.X; pos.X += lod) for (pos.Y = chunk.Start.Y; pos.Y < chunk.End.Y; pos.Y += lod) for (pos.Z = chunk.Start.Z; pos.Z < chunk.End.Z; pos.Z += lod) chunk.SetVoxel(pos, GenerateVoxel(pos)); return chunk; }
public BlockGroup CreateNewBlockGroup() { Block[] blocks = BlockGroupTypes.GetRandom().Copy(); for (int i = 0; i < blocks.Length; i++) { IntVector3 coordinate = GetSpawnCoordinate() + blocks[i].Coordinate; Vector3 worldCoordinate = new Vector3(coordinate.x + cubeSize.x / 2f, coordinate.y + cubeSize.y / 2f, coordinate.z + cubeSize.z / 2f); Block block = new Block(coordinate); block.SetGameObject(Instantiate(blockPrefab)); block.gObj.name = coordinate.ToString(); block.gObj.GetComponent <MeshRenderer>().enabled = false; block.gObj.transform.localScale = new Vector3(cubeSize.x, cubeSize.y, cubeSize.z); block.Coordinate = coordinate; block.gObj.transform.localPosition = worldCoordinate; blocks[i] = block; } BlockGroup group = new BlockGroup(blocks); return(group); }
/// <summary> /// NOT FULLY IMPLEMENTED /// </summary> /// <param name="position"></param> /// <returns></returns> public patternOrChunk getPatternOrChunk(IntVector3 position) { patternOrChunk toMake; //map first if ((position >= mapOffset) && position < mapOffset + new IntVector3(mapSize)) { Chunk possible = map.get(position - mapOffset); if (possible != null) { toMake = new patternOrChunk(possible); if (mapGenHelper != null) { mapGenHelper[position] = toMake; } return toMake; } } //then helper //because if you do helper first, then ones generated during a run don't get acknowledged if (mapGenHelper != null) { if (mapGenHelper.ContainsKey(position)) { return mapGenHelper[position]; } } //then, check for a file String filename = position.ToString(); mapV1 mapmaker; try { //for some reason this is slow as f**k //probably because hard drives are slow //so it's commented for now //I wonder if it would be better if it was actually loading things? //mapmaker = content.Load<mapV1>(filename); } catch (ContentLoadException) { //if no file, then generate the pattern //mapmaker = Mapgen.generatePatterns(this, position); } //beyond here lies TEMP SHIT CODE //if (mapmaker.layers[0] == "ungenerated") { toMake = new patternOrChunk(OutpostLibrary.Structure.field); if (mapGenHelper != null) { mapGenHelper[position] = toMake; } return toMake; } Chunk building = new Chunk(position, graphics); //chunk loading from file goes here building.endFill(); toMake = new patternOrChunk(building); if (mapGenHelper != null) { mapGenHelper[position] = toMake; } return toMake; }
/// <summary> /// NOT FULLY IMPLEMENTED /// Loads a chunk specified by position in the world map. /// Will generate the chunk if it does not already exist. /// </summary> /// <param name="position">The position to load from.</param> /// <returns>An Octree representation of the chunk.</returns> Chunk loadChunk(IntVector3 position) { LoadingScreen.ChangeMessage("Loading chunk " + position.ToString()); String filename = position.ToString(); mapV1 mapmaker; try { //mapmaker = content.Load<mapV1>(filename); } catch (ContentLoadException) { //mapmaker = Mapgen.generatePatterns(this, position); } Chunk building = new Chunk(position, graphics); //if (mapmaker.layers[0] == "ungenerated") { lua.buildChunk(position, building); } //else { //Chunk loading from file code goes here. } return building; }