public Vector3 GetOffset(Vector3 position) { Vector3 shiftedOffset = offset; if (offsetRandom) { shiftedOffset += WorldRand.GetVector3(position, offsetRandomRange, -0.5f); } return(shiftedOffset); }
void InitChunkManager() { if (chunksPool == null) { chunksPool = new VoxelChunk[maxChunks]; } cachedChunks = new Dictionary <int, CachedChunk> (CHUNKS_CREATION_BUFFER_SIZE); chunkRequests = new Octree[CHUNKS_CREATION_BUFFER_SIZE]; chunkRequestLast = -1; linkedChunks = new LinkedChunk[CHUNKS_RENDER_BUFFER_SIZE]; chunkQueueRoot = 0; tempLightmapPos = new int[16 * 16 * 16 * 9]; InitOctrees(); InitHeightMap(); InitBiomes(); NoiseTools.seedOffset = WorldRand.GetVector3(Misc.vector3zero, 1024); frustumCheckIteration = 1; forceChunkSqrDistance = (forceChunkDistance * 16) * (forceChunkDistance * 16); if (updatedChunks == null) { updatedChunks = new List <VoxelChunk> (50); } else { updatedChunks.Clear(); } if (world != null) { if (world.terrainGenerator == null) { world.terrainGenerator = Resources.Load <TerrainDefaultGenerator> ("VoxelPlay/Defaults/NullTerrainGenerator"); } world.terrainGenerator.Initialize(); worldHasDetailGenerators = world.detailGenerators != null && world.detailGenerators.Length > 0; if (worldHasDetailGenerators) { for (int d = 0; d < world.detailGenerators.Length; d++) { if (world.detailGenerators [d] == null) { Debug.LogWarning("Voxel Play: one world detail generator is missing!"); world.detailGenerators = Misc.PackArray <VoxelPlayDetailGenerator> (world.detailGenerators); d--; continue; } world.detailGenerators [d].Init(); } } } ClearStats(); // Prepare scene root object if (chunkPlaceholderPrefab == null) { chunkPlaceholderPrefab = Resources.Load <GameObject> ("VoxelPlay/Prefabs/ChunkGEO"); } if (chunksRoot == null) { chunksRoot = transform.Find(CHUNKS_ROOT); if (chunksRoot != null) { DestroyImmediate(chunksRoot.gameObject); } } if (chunksRoot == null) { GameObject cr = new GameObject(CHUNKS_ROOT); cr.hideFlags = HideFlags.DontSave; chunksRoot = cr.transform; chunksRoot.hierarchyCapacity = 20000; chunksRoot.SetParent(worldRoot, false); } chunksRoot.gameObject.SetActive(true); }