public void CreateChunk(Chunk chunk) { GameObject newChunkObj = Instantiate(chunkPrefab, new Vector3(chunk.pos.x, chunk.pos.y, chunk.pos.z), Quaternion.identity) as GameObject; ChunkContainer newChunkContainer = newChunkObj.GetComponent <ChunkContainer>(); newChunkContainer.chunk = chunk; newChunkContainer.chunk.container = newChunkContainer; }
public Chunk(ChunkContainer container) { _Container = container; ColumnLoaded = false; BlocksLoaded = false; DeleteRequested = false; MeshDataLoaded = false; Busy = false; }
private ChunkContainer HandleMoreColumnsThanExpected(ChunkContainer columns) { if (_additionalColumnsProcessing == AdditionalColumnsProcessing.Merge) { return MergeAdditionalTrailingColumns(columns); } return SkipAdditionalTrailingColumns(columns); }
public ChunkContainer Transform(ChunkContainer source) { if (source == null) { throw new ArgumentNullException("source"); } return Transformer(source); }
private ChunkContainer MergeAdditionalTrailingColumns(ChunkContainer collection) { ChunkContainer toKeepSplitted = collection.GetRange(0, _numberOfColumns - 1); ChunkContainer toMerge = collection.GetRange(_numberOfColumns - 1, collection.Count - _numberOfColumns + 1); string mergedColumns = string.Join(string.Empty, toMerge.ToArray()); ChunkContainer result = toKeepSplitted.Add(mergedColumns); return result; }
private ChunkContainer HandleLessColumnsThanExpected(ChunkContainer columns) { var emptyColumns = (string[]) Array.CreateInstance(typeof (string), _numberOfColumns - columns.Count); for (int i = 0; i < emptyColumns.Length; i++) { emptyColumns[i] = string.Empty; } return columns.Add(emptyColumns); }
private static ChunkContainer Trimmer(ChunkContainer source) { var chunks = new List<string>(); foreach (string data in source.ToArray()) { chunks.Add(data.Trim()); } return new ChunkContainer(chunks); }
private void finishChunk(ChunkData chunkData) { GameObject chunkObject = new GameObject(); chunkObject.name = "Chunk PosIJ:" + chunkData.startPosIJ.x + " " + chunkData.startPosIJ.y; chunkObject.transform.parent = asteroidFieldData.gameObject.transform; chunkObject.transform.position = new Vector3(chunkData.startPosXY.x, chunkData.startPosXY.y, 0); ChunkContainer chunkContainer = chunkObject.AddComponent <ChunkContainer>(); chunkData.chunkContainer = chunkContainer; chunkContainer.chunkData = chunkData; foreach (Triangle triangle in chunkData.visableTriangle) { BuildItem copyItem = triangle.item; triangle.item = (BuildItem)ScriptableObject.CreateInstance("BuildItem"); triangle.item.name = copyItem.name; triangle.item.Icon = copyItem.Icon; triangle.item.discription = copyItem.discription; triangle.item.player = copyItem.player; triangle.item.duribility = copyItem.duribility; triangle.item.maxduribility = copyItem.maxduribility; triangle.item.UV0s = copyItem.UV0s; triangle.item.mass = copyItem.mass; } chunkData.mesh = new Mesh(); chunkData.mesh.vertices = chunkData.vertices; chunkData.mesh.triangles = chunkData.indices; chunkData.mesh.uv = chunkData.uv; chunkData.mesh.uv2 = chunkData.uv1; chunkData.mesh.colors = chunkData.colors; chunkData.meshFilter = chunkObject.AddComponent <MeshFilter>(); chunkData.meshFilter.mesh = chunkData.mesh; chunkData.meshRenderer = chunkObject.AddComponent <MeshRenderer>(); chunkData.meshRenderer.material = buildMaterial; chunkData.polygonCollider2D = chunkObject.AddComponent <PolygonCollider2D>(); chunkData.polygonCollider2D.pathCount = chunkData.colliderPaths.Count; int i = 0; foreach (Vector2[] path in chunkData.colliderPaths) { chunkData.polygonCollider2D.SetPath(i, path); i++; } chunkData.state++; }
public StarterRoom() { sColor = new SerializedColor(Microsoft.Xna.Framework.Color.Red); color = sColor.getColor(); chunks = new ChunkContainer(); //chunks.Add(new SquareChunk(-2, 1000)); for(byte i = 0; i < 5; i++) { chunks.Add(new TorchChunk(i, 100)); } }
public Room(int height, int chunkPos, Dungeon dungeon) { if (Dungeon.getDeserializing()) return; baseHeight = height; random = new Random(this.GetHashCode()); sColor = new SerializedColor(random.Next(256), random.Next(256), random.Next(256)); color = sColor.getColor(); chunks = new ChunkContainer(); this.chunkPos = chunkPos; if (GetType().Equals(typeof(Room))) generateRoom(); }
public TavernRoom(Vector2 vector) { sColor = new SerializedColor(Color.DarkGoldenrod); color = sColor.getColor(); chunks = new ChunkContainer(); int i = 0; chunks.Add(new PortalChunk(i++, 100, DungeonManager.getInstance().getCurrentDungeon(), vector)); for (int j = 0; i < 5; i++ ) chunks.Add(new SquareChunk(i, 100)); chunks.Add(new StairChunk(i++, 100)); int max = i + 5; for (int j = 0; i < max; i++) chunks.Add(new SquareChunk(i, 140)); }
public void Roundtrip12() { var expected = new ChunkContainer { Chunk = new FormChunk { TypeId = "PTCH", Chunks = new List <ChunkContainer> { new ChunkContainer { Chunk = new CatChunk { TypeId = "REFS", Chunks = new List <ChunkContainer> { new ChunkContainer(new RefeChunk { SomeStuffInThisChunk = "hello" }), new ChunkContainer(new RefeChunk { SomeStuffInThisChunk = "worlds" }) } } } } } }; Roundtrip(expected, new[] { (byte)'F', (byte)'O', (byte)'R', (byte)'M', (byte)0, (byte)0, (byte)0, (byte)44, (byte)'P', (byte)'T', (byte)'C', (byte)'H', (byte)'C', (byte)'A', (byte)'T', (byte)' ', (byte)0, (byte)0, (byte)0, (byte)32, (byte)'R', (byte)'E', (byte)'F', (byte)'S', (byte)'R', (byte)'E', (byte)'F', (byte)'E', (byte)0, (byte)0, (byte)0, (byte)5, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o', (byte)0, (byte)'R', (byte)'E', (byte)'F', (byte)'E', (byte)0, (byte)0, (byte)0, (byte)6, (byte)'w', (byte)'o', (byte)'r', (byte)'l', (byte)'d', (byte)'s' }); }
public void Roundtrip12() { var expected = new ChunkContainer { Chunk = new FormChunk { TypeId = "PTCH", Chunks = new List<ChunkContainer> { new ChunkContainer { Chunk = new CatChunk { TypeId = "REFS", Chunks = new List<ChunkContainer> { new ChunkContainer(new RefeChunk {SomeStuffInThisChunk = "hello"}), new ChunkContainer(new RefeChunk {SomeStuffInThisChunk = "worlds"}), } } } } } }; Roundtrip(expected, new[] { (byte)'F', (byte)'O', (byte)'R', (byte)'M', (byte)0, (byte)0, (byte)0, (byte)44, (byte)'P', (byte)'T', (byte)'C', (byte)'H', (byte)'C', (byte)'A', (byte)'T', (byte)' ', (byte)0, (byte)0, (byte)0, (byte)32, (byte)'R', (byte)'E', (byte)'F', (byte)'S', (byte)'R', (byte)'E', (byte)'F', (byte)'E', (byte)0, (byte)0, (byte)0, (byte)5, (byte)'h', (byte)'e', (byte)'l', (byte)'l', (byte)'o', (byte)0, (byte)'R', (byte)'E', (byte)'F', (byte)'E', (byte)0, (byte)0, (byte)0, (byte)6, (byte)'w', (byte)'o', (byte)'r', (byte)'l', (byte)'d', (byte)'s' }); }
public void Test() { var source = new ChunkContainer { ChunkType = "TEST", Chunk = new TestChunk { Customs = new[] { new CustomSerializable { Value = 1 }, new CustomSerializable { Value = 2 } } } }; Roundtrip(source); var serializer = new BinarySerializer(); var outputStream = new MemoryStream(); serializer.Serialize(outputStream, source); outputStream.Seek(0, SeekOrigin.Begin); var inputStream = new LooksLikeANetworkStream(outputStream); //non-seekable stream //var inputStream = outputStream; //successful var roundtrip = serializer.Deserialize <ChunkContainer>(inputStream); //Assert.That(roundtrip.Chunk, Is.InstanceOf<TestChunk>()); //var sourceChunk = (TestChunk)source.Chunk; //var testChunk = (TestChunk)roundtrip.Chunk; //Assert.That(testChunk.Customs.Length, Is.EqualTo(sourceChunk.Customs.Length)); //Assert.That(testChunk.Customs.ElementAt(0).Value, Is.EqualTo(sourceChunk.Customs.ElementAt(0).Value)); //Assert.That(testChunk.Customs.ElementAt(1).Value, Is.EqualTo(sourceChunk.Customs.ElementAt(1).Value)); }
private ChunkContainer SkipAdditionalTrailingColumns(ChunkContainer collection) { return collection.GetRange(0, _numberOfColumns); }
// Start is called before the first frame update void Start() { _prefabObj = Instantiate(new GameObject(), transform); _prefabObj.name = "Prefabs"; _prefabObj.SetActive(false); _prefabObj.transform.position = new Vector3(0, 0, 10); Prefabs = new Dictionary <string, GameObject>() { { "tile:grass", (GameObject)Instantiate(Resources.Load("Prefabs/Tile/Tile_Env_Grass"), _prefabObj.transform) }, { "tile:stone", (GameObject)Instantiate(Resources.Load("Prefabs/Tile/Tile_Env_Stone"), _prefabObj.transform) }, { "tile:water", (GameObject)Instantiate(Resources.Load("Prefabs/Tile/Tile_Env_Water"), _prefabObj.transform) }, { "tile:sand", (GameObject)Instantiate(Resources.Load("Prefabs/Tile/Tile_Env_Sand"), _prefabObj.transform) }, { "overlay:tree", (GameObject)Instantiate(Resources.Load("Prefabs/Overlay/Overlay_Env_Tree"), _prefabObj.transform) }, { "entity:human.friendly.male", (GameObject)Instantiate(Resources.Load("Prefabs/Entity/Human/Entity_Human_Male"), _prefabObj.transform) }, { "ui:selector", (GameObject)Instantiate(Resources.Load("Prefabs/UI/UI_Selector"), _prefabObj.transform) } }; foreach (var obj in Prefabs) { obj.Value.transform.position = new Vector3(0, 0, 10); //var renderer = obj.Value.GetComponent<SpriteRenderer>(); //var clr = renderer.color; //renderer.color = new Color(clr.r, clr.g, clr.b, 0.2f); obj.Value.SetActive(false); obj.Value.name = obj.Key + ";PREFAB"; } Entities = new EntityContainer(transform); Chunks = new ChunkContainer(transform); var seed = Random.Range(0.0F, 10000000.0F); Mapper = new WorldMapperSettings(80, 100, 105, 200); Generator = new Generator(0.01F, seed, 16, new WorldMapper(Mapper)); Debug.Log("Seed: " + seed.ToString()); var playerObj = GameObject.FindWithTag("Player"); if (playerObj != null) { Player = playerObj.GetComponent <PlayerManager>(); Player.Location = new Point(0, 0); } else { Debug.LogError("Could not find Player Object"); } StartupGenerate(); InputEvents input = GetComponent <InputEvents>(); input.OnMovementKeyPressed += OnMovement; input.OnScroll += OnScroll; input.OnKeyPressed += OnKeyPress; input.OnMouseClick += OnClick; }
public void LoadChunk(int2 chunkPosition) { if (allChunks.TryGetValue(chunkPosition, out var existingChunkContainer)) { loadedChunks.Add(chunkPosition, existingChunkContainer); return; } var chunkRenderer = Instantiate(chunkPrefab, transform, true); chunkRenderer.transform.position = ChunkScale * new Vector3(chunkPosition.x, chunkPosition.y); chunkRenderer.transform.localScale = new Vector3(ChunkScale, ChunkScale, 1); var outputRenderTexture = new RenderTexture(ChunkSize, ChunkSize, 32) { enableRandomWrite = true, useMipMap = false, filterMode = FilterMode.Point }; outputRenderTexture.Create(); var chunk = new Chunk(Allocator.Persistent); var cellsComputeBuffer = new ComputeBuffer(chunk.Cells.Length, SizeOfCell); chunkRenderer.SetTexture(outputRenderTexture); if (chunkPosition.y == 0) { for (var cellX = 0; cellX < ChunkSize; cellX++) { for (var cellY = 0; cellY < ChunkSize; cellY++) { chunk.SetCell(int2(cellX, cellY), (Random.value > 0.5f) ? Cell.EmptyCell : SandCellImplementation.CreateSandCell(ref random)); } } } else if (chunkPosition.y < 0) { for (var cellX = 0; cellX < ChunkSize; cellX++) { for (var cellY = 0; cellY < ChunkSize; cellY++) { chunk.SetCell(int2(cellX, cellY), SandCellImplementation.CreateSandCell(ref random)); } } } var chunkContainer = new ChunkContainer { Chunk = chunk, ChunkBehaviour = chunkRenderer, CellsComputeBuffer = cellsComputeBuffer, OutputRenderTexture = outputRenderTexture }; allChunks.Add(chunkPosition, chunkContainer); loadedChunks.Add(chunkPosition, chunkContainer); }