campfire/Assets/Scripts/LoraxCuller.cs

46 lines
1.8 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>();
2020-04-20 11:31:15 +02:00
private List<GameObject>[] EnabledChunks;
2020-04-20 03:14:45 +02:00
private void Awake() {
2020-04-20 11:31:15 +02:00
EnabledChunks = new List<GameObject>[Loraces.Length];
2020-04-20 03:14:45 +02:00
foreach (Transform Child in ChunkKeepAliveTransformsParent) {
ChunkKeepAliveTransforms.Add(Child);
}
2020-04-20 11:31:15 +02:00
for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) {
EnabledChunks[LoraxIndex] = new List<GameObject>();
for (int ChunkIndex = 0; ChunkIndex < ChunkKeepAliveTransforms.Count; ChunkIndex++) {
EnabledChunks[LoraxIndex].Add(null);
}
}
2020-04-20 03:14:45 +02:00
}
private void Update() {
2020-04-20 11:31:15 +02:00
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);
}
}
}
2020-04-20 03:14:45 +02:00
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;
GameObject NewChunk = Lorax.GetChunkAt(KeepAlivePosition.x, KeepAlivePosition.z);
2020-04-20 11:31:15 +02:00
NewChunk.SetActive(true);
EnabledChunks[LoraxIndex][ChunkIndex] = NewChunk;
2020-04-20 03:14:45 +02:00
}
}
}
}