azrith001

WorldChunk.cs

Aug 14th, 2020
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5. using Unity.Mathematics;
  6.  
  7. [System.Serializable]
  8. public class WorldChunk
  9. {
  10.     // Position Data
  11.     public int2 Position;
  12.     private int ChunkSize = 0;
  13.     // Internal Data for Terrain
  14.     public int[,] Data;
  15.     public float[,] Sample;
  16.     // Enabled State and Child
  17.     public bool enabled = true;
  18.    
  19.  
  20.     // Initialize Chunk and Size
  21.     public WorldChunk(int chunkSize = 16){
  22.         // Add one to make world Symetrical in coords
  23.         Data = new int[chunkSize+1, chunkSize+1];
  24.         Sample = new float[chunkSize+1, chunkSize+1];
  25.         ChunkSize = chunkSize;
  26.     }
  27.  
  28.     //===============
  29.     // Used to Check Position is valid
  30.     //===============
  31.     public bool PositionIs(int x, int y){
  32.         return (Position.x == x && Position.y == y);
  33.     }
  34.  
  35.     public bool PositionIs(int2 pos){
  36.         return PositionIs(pos.x, pos.y);
  37.     }
  38.  
  39.  
  40.     //===============
  41.     // Get Cell Position in the world
  42.     //===============
  43.     public int2 CellPosition(int x, int y){
  44.         return new int2((int)(ChunkWorldPosition.x - ChunkSize/2f) + x, (int)(ChunkWorldPosition.y - ChunkSize/2f) + y);
  45.     }
  46.  
  47.     //===============
  48.     // Get Vector Position in the world
  49.     //===============
  50.     public Vector2 VectorCellPosition(int x, int y){
  51.         return new Vector2((int)(ChunkWorldPosition.x - ChunkSize/2f) + x, (int)(ChunkWorldPosition.y - ChunkSize/2f) + y);
  52.     }
  53.  
  54.     //===============
  55.     // Used get Chunk World Position (instead of (-1, 0) would be (-chunkSize, 0)) used for Graphical Offsets
  56.     //===============
  57.     public int2 ChunkWorldPosition{
  58.         get{
  59.             return new int2(Position.x * ChunkSize, Position.y * ChunkSize);
  60.         }
  61.     }
  62. }
  63.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×