示例#1
0
    public void createBrick(int brickX, int brickY, int brickZ)
    {
        Vector3i cell = new Vector3i(brickX, brickY, brickZ);

        int cellHash = cell.GetHashCode();

        if (chunkDictionary.ContainsKey(cell.GetHashCode()))
        {
            chunkPool.Release(chunkDictionary[cell.GetHashCode()]);
        }

        Material material = Resources.Load("Materials/TestMaterial", typeof(Material)) as Material;

        ChunkFromOctreeRequest request = extractRequestPool.Catch();
        Chunk chunk = request.ReInitialize(voxelTree, extractor, material, brickX, brickY, brickZ, chunkPool, extractRequestPool);

        chunk.gameObject.transform.parent = gameObject.transform;
        chunk.gameObject.hideFlags        = (HideFlags)0;
        requestHandlers.Grab().QueueRequest(request);

        if (chunkDictionary.ContainsKey(cell.GetHashCode()))
        {
            chunkDictionary[cell.GetHashCode()] = chunk;
        }
        else
        {
            chunkDictionary.Add(cell.GetHashCode(), chunk);
        }
    }
示例#2
0
    public void createBrick(int brickX, int brickY, int brickZ)
    {
        Material material = Resources.Load("Materials/TestMaterial", typeof(Material)) as Material;
        ChunkFromOctreeRequest request = extractRequestPool.Catch();
        Chunk chunk = request.ReInitialize(brickTree, extractor, material, brickX, brickY, brickZ, chunkPool, extractRequestPool);

        requestHandlers.Grab().QueueRequest(request);
        chunkDictionary.Add(new Vector3i(brickX * 16, brickY * 16, brickZ * 16).GetHashCode(), chunk);
    }
示例#3
0
    public void Update()
    {
        requestHandlers.Update();


        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            currentBrush    = setBrush;
            currentMaterial = materialAtlas.GetVoxelMaterial(0);
        }

        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            currentBrush    = setAdjacentBrush;
            currentMaterial = materialAtlas.GetVoxelMaterial(1);
        }


        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            currentBrush    = setAdjacentBrush;
            currentMaterial = materialAtlas.GetVoxelMaterial(2);
        }

        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            currentBrush    = setAdjacentBrush;
            currentMaterial = materialAtlas.GetVoxelMaterial(3);
        }

        if (!Input.GetMouseButton(0))
        {
            return;
        }


        GameObject camera = GameObject.FindGameObjectsWithTag("Player")[0];

        Ray ray = camera.GetComponent <Camera>().ScreenPointToRay(Input.mousePosition);

        Queue <OctreeEntry <Brick> > changed = new Queue <OctreeEntry <Brick> >();


        Bounds bounds = new Bounds();

        bounds.SetMinMax(new Vector3(0, 0, 0), new Vector3(worldDimensions.x, worldDimensions.y, worldDimensions.z));

        if (currentBrush.Stroke(ray, brickTree, currentMaterial, materialAtlas, materialAtlas.airMaterials, changed, bounds))
        {
            while (changed.Count > 0)
            {
                OctreeEntry <Brick> entry = changed.Dequeue();

                Vector3i cell = new Vector3i((int)entry.bounds.min.x, (int)entry.bounds.min.y, (int)entry.bounds.min.z);

                Material material = Resources.Load("Materials/TestMaterial", typeof(Material)) as Material;

                if (chunkDictionary.ContainsKey(cell.GetHashCode()))
                {
                    chunkPool.Release(chunkDictionary[cell.GetHashCode()]);
                }

                ChunkFromOctreeRequest request = extractRequestPool.Catch();
                Chunk chunk = request.ReInitialize(brickTree, extractor, material, entry.cell.x, entry.cell.y, entry.cell.z, chunkPool, extractRequestPool);
                requestHandlers.Grab().QueueRequest(request);

                int hash = cell.GetHashCode();
                if (chunkDictionary.ContainsKey(cell.GetHashCode()))
                {
                    chunkDictionary[cell.GetHashCode()] = chunk;
                }
                else
                {
                    chunkDictionary.Add(cell.GetHashCode(), chunk);
                }
            }
        }
    }