campfire/Assets/Scripts/LoraxCuller.cs

39 lines
1.5 KiB
C#
Raw Normal View History

2020-04-20 03:14:45 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoraxCuller : MonoBehaviour {
public Lorax[] Loraces;
public Transform ChunkKeepAliveTransformsParent;
private List<Transform> ChunkKeepAliveTransforms = new List<Transform>();
private GameObject[,] EnabledChunks;
private void Awake() {
foreach (Transform Child in ChunkKeepAliveTransformsParent) {
ChunkKeepAliveTransforms.Add(Child);
}
EnabledChunks = new GameObject[Loraces.Length, ChunkKeepAliveTransforms.Count];
}
private void Update() {
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;
2020-04-20 04:05:26 +02:00
2020-04-20 03:14:45 +02:00
Debug.DrawLine(KeepAlivePosition, KeepAlivePosition + Vector3.up * 5, Color.red);
GameObject NewChunk = Lorax.GetChunkAt(KeepAlivePosition.x, KeepAlivePosition.z);
2020-04-20 04:05:26 +02:00
2020-04-20 03:14:45 +02:00
if (EnabledChunks[LoraxIndex, ChunkIndex] != NewChunk) {
if (EnabledChunks[LoraxIndex, ChunkIndex] != null) {
EnabledChunks[LoraxIndex, ChunkIndex].SetActive(false);
}
NewChunk.SetActive(true);
EnabledChunks[LoraxIndex, ChunkIndex] = NewChunk;
}
}
}
}
}