Exemple #1
0
        public ChunkManager(Graphics graphics)
        {
            _chunkDrawer  = new ChunkDrawer(graphics.Device);
            Chunks        = new ConcurrentDictionary <Int2, Chunk>();
            _queuedChunks = new ConcurrentDictionary <Int2, object>();
            _pipeline     = new PipelineProvider(graphics.Device).CreatePipeline(InitialDegreeOfParallelism, Finalize, out _neighborAssignerPipelineBlock);
            _chunkUpdater = new ChunkUpdater(graphics, this);

            QueueChunksByIndex(Int2.Zero);
        }
Exemple #2
0
    public ChunkDrawer GetChunkAtLocation(Vector3 position)
    {
        if (position.x < 0 || position.z < 0 || Mathf.FloorToInt(position.x) >= currentFloor.GetLength(0) || Mathf.FloorToInt(position.z) >= currentFloor.GetLength(1))
        {
            return(null);
        }
        int chunkX = Mathf.FloorToInt(position.x / map.ChunkSize);
        int chunkZ = Mathf.FloorToInt(position.z / map.ChunkSize);

        ChunkDrawer chunk = GameObject.Find("chunk_" + activeLevel + "_" + chunkX + "_" + chunkZ).GetComponent <ChunkDrawer>();

        return(chunk);
    }
Exemple #3
0
    public void RebuildFloor(int startX, int endX, int startZ, int endZ)
    {
        for (int i = startX / map.ChunkSize; i <= endX / map.ChunkSize; i++)
        {
            for (int j = startZ / map.ChunkSize; j <= endZ / map.ChunkSize; j++)
            {
                ChunkDrawer chunk = GameObject.Find("chunk_" + activeLevel + "_" + i + "_" + j).GetComponent <ChunkDrawer>();
                chunk.BuildMesh();
            }
        }

        map.IsDirty = true;
    }
Exemple #4
0
    public IEnumerator RebuildFloor(int startX, int endX, int startZ, int endZ, int level)
    {
        for (int i = startX / map.ChunkSize; i <= endX / map.ChunkSize; i++)
        {
            for (int j = startZ / map.ChunkSize; j <= endZ / map.ChunkSize; j++)
            {
                ChunkDrawer chunk = GameObject.Find("chunk_" + level + "_" + i + "_" + j).GetComponent <ChunkDrawer>();
                chunk.BuildMesh();
                yield return(null);
            }
        }

        map.IsDirty = true;
    }
Exemple #5
0
    void Awake()
    {
        mergedObjects = new ObjectMeshCombination(transform);

        Objects    = new Item[objectPrototypes.Length + 1];
        Objects[0] = new Item("Remove", -1);
        for (int i = 1; i < Objects.Length; ++i)
        {
            int protoIndex = i - 1;
            Objects[i] = new Item(objectPrototypes[protoIndex].name, protoIndex);
        }

        editorPlane = new Plane(Vector3.down, 0);

        GameObject go = new GameObject("editor_chunk");

        go.transform.SetParent(transform);

        chunkDrawer      = go.AddComponent <ChunkDrawer>();
        chunkDrawer.Info = chunkInfo;

        data = new Volume <Tile.Data>(10, 1, 10);
        InitData();
        chunkDrawer.TileData = data;

        objectRoot = new GameObject("object_root").transform;
        objectRoot.SetParent(transform);
        objectRoot.localPosition = new Vector3(0, ObjectPlacementOffset, 0);

        placedObjects = new List <PlacedObject>();

        int   colNum = chunkDrawer.TileData.XLength;
        int   rowNum = chunkDrawer.TileData.ZLength;
        float sizeX  = colNum * CellSize;
        float sizeZ  = rowNum * CellSize;

        StartPos = new Vector2(-sizeX * 0.5f, -sizeZ * 0.5f);
        Place(chunkDrawer);
    }
Exemple #6
0
 private void Place(ChunkDrawer chunk)
 {
     chunk.transform.localPosition = new Vector3(StartPos.x, 0, StartPos.y);
 }