示例#1
0
        public static void SpawnChunks(Vector3 position)
        {
            Index index = Engine.PositionToChunkIndex(position);

            Engine.ChunkManagerInstance.TrySpawnChunks(index);
        }
示例#2
0
        // ==== initialization ====
        public void Awake()
        {
            Engine.EngineInstance = this;
            Engine.ChunkManagerInstance = GetComponent<ChunkManager>();

            WorldName = lWorldName;
            UpdateWorldPath();

            BlocksPath = lBlocksPath;
            Engine.Blocks = lBlocks;

            TargetFPS = lTargetFPS;
            MaxChunkSaves = lMaxChunkSaves;
            MaxChunkDataRequests = lMaxChunkDataRequests;

            TextureUnit = lTextureUnit;
            TexturePadding = lTexturePadding;
            GenerateColliders = lGenerateColliders;
            ShowBorderFaces = lShowBorderFaces;
            EnableMultiplayer = lEnableMultiplayer;
            MultiplayerTrackPosition = lMultiplayerTrackPosition;
            SaveVoxelData = lSaveVoxelData;
            GenerateMeshes = lGenerateMeshes;

            ChunkSpawnDistance = lChunkSpawnDistance;
            HeightRange = lHeightRange;
            ChunkDespawnDistance = lChunkDespawnDistance;

            SendCameraLookEvents = lSendCameraLookEvents;
            SendCursorEvents = lSendCursorEvents;

            ChunkSideLength = lChunkSideLength;
            SquaredSideLength = lChunkSideLength * lChunkSideLength;

            ChunkDataFiles.LoadedRegions = new Dictionary<string, string[]>();
            ChunkDataFiles.TempChunkData = new Dictionary<string, string>();

            if (lChunkTimeout <= 0.00001f)	{
            EnableChunkTimeout = false;
            }
            else {
            EnableChunkTimeout = true;
            ChunkTimeout = lChunkTimeout;
            }

            if (Application.isWebPlayer) {
            lSaveVoxelData = false;
            SaveVoxelData = false;
            }

            // set layer
            if (LayerMask.LayerToName (26) != "" && LayerMask.LayerToName (26) != "UniblocksNoCollide") {
            Debug.LogWarning ("Uniblocks: Layer 26 is reserved for Uniblocks; it is automatically set to ignore collision with all layers.");
            }
            for (int i=0; i<31; i++) {
            Physics.IgnoreLayerCollision (i, 26);
            }

            // check block array
            if (Engine.Blocks.Length < 1) {
            Debug.LogError ("Uniblocks: The blocks array is empty! Use the Block Editor to update the blocks array.");
            Debug.Break();
            }

            if (Engine.Blocks[0] == null) {
            Debug.LogError ("Uniblocks: Cannot find the empty block prefab (id 0)!");
            Debug.Break();
            }
            else if (Engine.Blocks[0].GetComponent<Voxel>() == null) {
            Debug.LogError ("Uniblocks: Voxel id 0 does not have the Voxel component attached!");
            Debug.Break();
            }

            // check settings
            if (Engine.ChunkSideLength < 1) {
            Debug.LogError ("Uniblocks: Chunk side length must be greater than 0!");
            Debug.Break();
            }

            if (Engine.ChunkSpawnDistance < 1) {
            Engine.ChunkSpawnDistance = 0;
            Debug.LogWarning ("Uniblocks: Chunk spawn distance is 0. No chunks will spawn!");
            }

            if (Engine.HeightRange < 0) {
            Engine.HeightRange = 0;
            Debug.LogWarning ("Uniblocks: Chunk height range can't be a negative number! Setting chunk height range to 0.");
            }

            if (Engine.MaxChunkDataRequests < 0) {
            Engine.MaxChunkDataRequests = 0;
            Debug.LogWarning ("Uniblocks: Max chunk data requests can't be a negative number! Setting max chunk data requests to 0.");
            }

            // check materials
            GameObject chunkPrefab = GetComponent<ChunkManager>().ChunkObject;
            int materialCount = chunkPrefab.GetComponent<Renderer>().sharedMaterials.Length-1;

            for (ushort i=0; i<Engine.Blocks.Length; i++) {

            if (Engine.Blocks[i] != null) {
                Voxel voxel = Engine.Blocks[i].GetComponent<Voxel>();

                if (voxel.VSubmeshIndex < 0) {
                    Debug.LogError ("Uniblocks: Voxel "+i+" has a material index lower than 0! Material index must be 0 or greater.");
                    Debug.Break();
                }

                if (voxel.VSubmeshIndex > materialCount) {
                    Debug.LogError ("Uniblocks: Voxel "+i+" uses material index "+voxel.VSubmeshIndex +", but the chunk prefab only has "+(materialCount+1)+ " material(s) attached. Set a lower material index or attach more materials to the chunk prefab.");
                    Debug.Break();
                }
            }
            }

            // check anti-aliasing
            if (QualitySettings.antiAliasing > 0) {
            Debug.LogWarning ("Uniblocks: Anti-aliasing is enabled. This may cause seam lines to appear between blocks. If you see lines between blocks, try disabling anti-aliasing, switching to deferred rendering path, or adding some texture padding in the engine settings.");
            }

            Engine.Initialized = true;
        }
示例#3
0
        public static void SpawnChunks(float x, float y, float z)
        { // take world pos, convert to chunk index
            Index index = Engine.PositionToChunkIndex(new Vector3(x, y, z));

            Engine.ChunkManagerInstance.TrySpawnChunks(index);
        }