Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- using Unity.Mathematics;
- [System.Serializable]
- public class WorldChunk
- {
- // Position Data
- public int2 Position;
- private int ChunkSize = 0;
- // Internal Data for Terrain
- public int[,] Data;
- public float[,] Sample;
- // Enabled State and Child
- public bool enabled = true;
- // Initialize Chunk and Size
- public WorldChunk(int chunkSize = 16){
- // Add one to make world Symetrical in coords
- Data = new int[chunkSize+1, chunkSize+1];
- Sample = new float[chunkSize+1, chunkSize+1];
- ChunkSize = chunkSize;
- }
- //===============
- // Used to Check Position is valid
- //===============
- public bool PositionIs(int x, int y){
- return (Position.x == x && Position.y == y);
- }
- public bool PositionIs(int2 pos){
- return PositionIs(pos.x, pos.y);
- }
- //===============
- // Get Cell Position in the world
- //===============
- public int2 CellPosition(int x, int y){
- return new int2((int)(ChunkWorldPosition.x - ChunkSize/2f) + x, (int)(ChunkWorldPosition.y - ChunkSize/2f) + y);
- }
- //===============
- // Get Vector Position in the world
- //===============
- public Vector2 VectorCellPosition(int x, int y){
- return new Vector2((int)(ChunkWorldPosition.x - ChunkSize/2f) + x, (int)(ChunkWorldPosition.y - ChunkSize/2f) + y);
- }
- //===============
- // Used get Chunk World Position (instead of (-1, 0) would be (-chunkSize, 0)) used for Graphical Offsets
- //===============
- public int2 ChunkWorldPosition{
- get{
- return new int2(Position.x * ChunkSize, Position.y * ChunkSize);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement