Parcourir la source

Initial commit

James Peret il y a 2 ans
commit
a673588caa

+ 71 - 0
.gitignore

@@ -0,0 +1,71 @@
+# This .gitignore file should be placed at the root of your Unity project directory
+#
+# Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
+#
+/[Ll]ibrary/
+/[Tt]emp/
+/[Oo]bj/
+/[Bb]uild/
+/[Bb]uilds/
+/[Ll]ogs/
+/[Uu]ser[Ss]ettings/
+
+# MemoryCaptures can get excessive in size.
+# They also could contain extremely sensitive data
+/[Mm]emoryCaptures/
+
+# Asset meta data should only be ignored when the corresponding asset is also ignored
+!/[Aa]ssets/**/*.meta
+
+# Uncomment this line if you wish to ignore the asset store tools plugin
+# /[Aa]ssets/AssetStoreTools*
+
+# Autogenerated Jetbrains Rider plugin
+/[Aa]ssets/Plugins/Editor/JetBrains*
+
+# Visual Studio cache directory
+.vs/
+
+# Gradle cache directory
+.gradle/
+
+# Autogenerated VS/MD/Consulo solution and project files
+ExportedObj/
+.consulo/
+*.csproj
+*.unityproj
+*.sln
+*.suo
+*.tmp
+*.user
+*.userprefs
+*.pidb
+*.booproj
+*.svd
+*.pdb
+*.mdb
+*.opendb
+*.VC.db
+
+# Unity3D generated meta files
+*.pidb.meta
+*.pdb.meta
+*.mdb.meta
+
+# Unity3D generated file on crash reports
+sysinfo.txt
+
+# Builds
+*.apk
+*.aab
+*.unitypackage
+
+# Crashlytics generated file
+crashlytics-build.properties
+
+# Packed Addressables
+/[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin*
+
+# Temporary auto-generated Android Assets
+/[Aa]ssets/[Ss]treamingAssets/aa.meta
+/[Aa]ssets/[Ss]treamingAssets/aa/*

+ 8 - 0
Runtime.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 892cb3b7ae5e0f2409f19d019b34fc6d
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 55 - 0
Runtime/Chunk.cs

@@ -0,0 +1,55 @@
+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;
+        }
+    }
+}

+ 11 - 0
Runtime/Chunk.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 45b24616c9dfebe4f8f4ff205ccd6ded
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 58 - 0
Runtime/ChunkSystem.cs

@@ -0,0 +1,58 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace KairoEngine.Chunks
+{
+    public class ChunkSystem<TChunkBlock>
+    {
+        public Vector3Int chunkSize = new Vector3Int(16, 16, 16);
+        public Dictionary<Vector3Int, Chunk<TChunkBlock>> chunks;
+
+        public ChunkSystem(Vector3Int chunkSize, bool debug = false)
+        {
+            this.chunkSize = chunkSize;
+            this.chunks = new Dictionary<Vector3Int, Chunk<TChunkBlock>>();
+        }
+
+        public void CreateChunk(Vector3Int position, Func<Chunk<TChunkBlock>, Vector3Int, TChunkBlock> createChunkBlock)
+        {
+            Chunk<TChunkBlock> chunk = new Chunk<TChunkBlock>(chunkSize, position, createChunkBlock);
+            chunks.Add(position, chunk);
+        }
+
+        public TChunkBlock GetBlock(Vector3Int position)
+        {
+            Chunk<TChunkBlock> chunk = GetChunk(position);
+            if(!chunk.isInitialized()) return default(TChunkBlock);
+            Vector3Int pos = new Vector3Int();
+            pos.x = position.x - (Mathf.FloorToInt(position.x / chunkSize.x ) * chunkSize.x);
+            pos.y = position.y - (Mathf.FloorToInt(position.y / chunkSize.y ) * chunkSize.y);
+            pos.z = position.z - (Mathf.FloorToInt(position.z / chunkSize.z ) * chunkSize.z);
+            return chunk.GetBlock(pos);
+        }
+
+        public void SetBlock(Vector3Int position, TChunkBlock data)
+        {
+            Chunk<TChunkBlock> chunk = GetChunk(position);
+            if(!chunk.isInitialized()) return;
+            Vector3Int pos = new Vector3Int();
+            pos.x = position.x - (Mathf.FloorToInt(position.x / chunkSize.x ) * chunkSize.x);
+            pos.y = position.y - (Mathf.FloorToInt(position.y / chunkSize.y ) * chunkSize.y);
+            pos.z = position.z - (Mathf.FloorToInt(position.z / chunkSize.z ) * chunkSize.z);
+            chunk.SetBlock(pos, data);
+        }
+
+        public Chunk<TChunkBlock> GetChunk(Vector3Int position)
+        {
+            Vector3Int pos = new Vector3Int();
+            pos.x = Mathf.FloorToInt(position.x / chunkSize.x ) * chunkSize.x;
+            pos.y = Mathf.FloorToInt(position.y / chunkSize.y ) * chunkSize.y;
+            pos.z = Mathf.FloorToInt(position.z / chunkSize.z ) * chunkSize.z;
+            Chunk<TChunkBlock> chunk;
+            chunks.TryGetValue(pos, out chunk);
+            return chunk;
+        }
+    }
+}

+ 11 - 0
Runtime/ChunkSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 62a01857bd658234386054c3c2ae6584
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 17 - 0
Runtime/KairoEngine.Chunks.asmdef

@@ -0,0 +1,17 @@
+{
+    "name": "KairoEngine.Chunks",
+    "rootNamespace": "",
+    "references": [
+        "GUID:7e5ae6a38d1532248b4c890eca668b06",
+        "GUID:e048eeec9bdb9d30448017b829deb3f6"
+    ],
+    "includePlatforms": [],
+    "excludePlatforms": [],
+    "allowUnsafeCode": false,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Runtime/KairoEngine.Chunks.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 22b3fea425824d6448cb89ed3c76c9a8
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: