private void Start() { Debug.Log("generating new world using seed: " + VoxelData.seed); worldData = WorldSaveSystem.LoadWorld(WorldSaveSystem.name, VoxelData.seed); string settingsImport = File.ReadAllText(Application.dataPath + "/game.cfg"); settings = JsonUtility.FromJson <UserSettings>(settingsImport); Random.InitState(VoxelData.seed); Shader.SetGlobalFloat("MinGlobalLightLevel", VoxelData.minLightLevel); Shader.SetGlobalFloat("MaxGlobalLightLevel", VoxelData.maxLightLevel); LoadWorld(); SetGlobalLightValue(); spawnPosition = new Vector3(VoxelData.worldCentre, VoxelData.chunkHeight - 50f, VoxelData.worldCentre); player.position = spawnPosition; CheckViewDistance(); playerLastChunkPos = GetChunkCoordFromPosition(player.position); if (settings.enableMultiThreading) { _chunkUpdateThread = new Thread(new ThreadStart(ThreadedUpdate)); _chunkUpdateThread.Start(); } }
public static void SaveModifiedChunks(WorldData world) { List <ChunkData> chunks = new List <ChunkData>(world.modifiedChunks); world.modifiedChunks.Clear(); int count = 0; foreach (ChunkData chunk in chunks) { WorldSaveSystem.SaveChunk(chunk, world.worldName); count++; } Debug.Log(count + " chunks saved."); }
private void GetPlayerInputs() { horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical"); mouseHorizontal = Input.GetAxis("Mouse X"); mouseVertical = Input.GetAxis("Mouse Y"); if (Input.GetKeyDown(KeyCode.Escape)) { WorldSaveSystem.SaveWorld(World.Instance.worldData); Application.Quit(); } if (Input.GetButtonDown("Sprint")) { isSprinting = true; } if (Input.GetButtonUp("Sprint")) { isSprinting = false; } if (isGrounded && Input.GetButtonDown("Jump")) { jumpRequest = true; } if (selectedBlock.gameObject.activeSelf) { //destroy block if (Input.GetMouseButtonDown(0)) { world.GetChunkFromPosition(selectedBlock.position).EditVoxelData(selectedBlock.position, 0); } //create and place new block if (Input.GetMouseButtonDown(1)) { if (toolbar.slots[toolbar.slotIndex].HasItem) { world.GetChunkFromPosition(placeBlock.position).EditVoxelData(placeBlock.position, toolbar.slots[toolbar.slotIndex].itemSlot.stack.id); toolbar.slots[toolbar.slotIndex].itemSlot.UpdateAmount(1); } } } }
public void LoadChunk(Vector2Int pos) { if (chunks.ContainsKey(pos)) { return; } ChunkData chunk = WorldSaveSystem.LoadChunk(worldName, pos); if (chunk != null) { chunks.Add(pos, chunk); return; } chunks.Add(pos, new ChunkData(pos)); chunks[pos].Populate(); }
private void Update() { playerChunkPos = GetChunkCoordFromPosition(player.position); if (!playerChunkPos.Equals(playerLastChunkPos)) { CheckViewDistance(); } if (chunksToDraw.Count > 0) { chunksToDraw.Dequeue().CreateMesh(); } if (!settings.enableMultiThreading) { if (!modsApplying) { ApplyModifications(); } if (chunksToUpdate.Count > 0) { UpdateChunks(); } } if (Input.GetKeyDown(KeyCode.F3)) { debug.SetActive(!debug.activeSelf); } if (Input.GetKeyDown(KeyCode.F1)) { WorldSaveSystem.SaveWorld(worldData); } }
public void QuitGame() { WorldSaveSystem.SaveWorld(World.Instance.worldData); Application.Quit(); }