12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace KairoEngine.Chunks
- {
- [System.Serializable]
- public struct Chunk<TChunkBlock>
- {
- private bool initialized;
- public bool isInitialized() => initialized;
- private Vector3Int size;
- public Vector3Int position { get; private set; }
- public TChunkBlock[ , , ] blocks;
- public Chunk(Vector3Int size, Vector3Int position, Func<Chunk<TChunkBlock>, Vector3Int, TChunkBlock> createChunkBlock,
- bool debug = false)
- {
- this.size = size;
- this.position = position;
- this.blocks = new TChunkBlock[size.x, size.y, size.z];
- this.initialized = true;
- for (int x = 0; x < size.x; x++)
- {
- for (int y = 0; y < size.y; y++)
- {
- for (int z = 0; z < size.z; z++)
- {
- blocks[x, y, z] = createChunkBlock(this, new Vector3Int(x, y, z));
- }
-
- }
- }
-
- }
- public TChunkBlock GetBlock(Vector3Int pos)
- {
- if(pos.x > size.x || pos.x < 0) return default(TChunkBlock);
- if(pos.y > size.y || pos.y < 0) return default(TChunkBlock);
- if(pos.z > size.z || pos.z < 0) return default(TChunkBlock);
- return blocks[pos.x, pos.y, pos.z];
- }
- public void SetBlock(Vector3Int pos, TChunkBlock data)
- {
- if(pos.x > size.x || pos.x < 0) return;
- if(pos.y > size.y || pos.y < 0) return;
- if(pos.z > size.z || pos.z < 0) return;
- blocks[pos.x, pos.y, pos.z] = data;
- }
- }
- }
|