From 4f3e09cdaec23ed200a4db86f7723557f87e166c Mon Sep 17 00:00:00 2001 From: Jens Pitkanen Date: Mon, 20 Apr 2020 12:31:15 +0300 Subject: [PATCH] Fix lorax culler --- Assets/Scripts/LoraxCuller.cs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Assets/Scripts/LoraxCuller.cs b/Assets/Scripts/LoraxCuller.cs index 64c043d..fdf1f86 100644 --- a/Assets/Scripts/LoraxCuller.cs +++ b/Assets/Scripts/LoraxCuller.cs @@ -7,31 +7,38 @@ public class LoraxCuller : MonoBehaviour { public Transform ChunkKeepAliveTransformsParent; private List ChunkKeepAliveTransforms = new List(); - private GameObject[,] EnabledChunks; + private List[] EnabledChunks; private void Awake() { + EnabledChunks = new List[Loraces.Length]; foreach (Transform Child in ChunkKeepAliveTransformsParent) { ChunkKeepAliveTransforms.Add(Child); } - EnabledChunks = new GameObject[Loraces.Length, ChunkKeepAliveTransforms.Count]; + for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) { + EnabledChunks[LoraxIndex] = new List(); + for (int ChunkIndex = 0; ChunkIndex < ChunkKeepAliveTransforms.Count; ChunkIndex++) { + EnabledChunks[LoraxIndex].Add(null); + } + } } private void Update() { + for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) { + for (int ChunkIndex = 0; ChunkIndex < ChunkKeepAliveTransforms.Count; ChunkIndex++) { + GameObject OldChunk = EnabledChunks[LoraxIndex][ChunkIndex]; + if (OldChunk != null) { + OldChunk.SetActive(false); + } + } + } + for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) { Lorax Lorax = Loraces[LoraxIndex]; for (int ChunkIndex = 0; ChunkIndex < ChunkKeepAliveTransforms.Count; ChunkIndex++) { Vector3 KeepAlivePosition = ChunkKeepAliveTransforms[ChunkIndex].position; - - Debug.DrawLine(KeepAlivePosition, KeepAlivePosition + Vector3.up * 5, Color.red); GameObject NewChunk = Lorax.GetChunkAt(KeepAlivePosition.x, KeepAlivePosition.z); - - if (EnabledChunks[LoraxIndex, ChunkIndex] != NewChunk) { - if (EnabledChunks[LoraxIndex, ChunkIndex] != null) { - EnabledChunks[LoraxIndex, ChunkIndex].SetActive(false); - } - NewChunk.SetActive(true); - EnabledChunks[LoraxIndex, ChunkIndex] = NewChunk; - } + NewChunk.SetActive(true); + EnabledChunks[LoraxIndex][ChunkIndex] = NewChunk; } } }