Update lorax culler, fixing it finally maybe
This commit is contained in:
parent
4ab5cb6dbf
commit
5eb88c72a1
@ -24761,6 +24761,16 @@ PrefabInstance:
|
|||||||
propertyPath: Loraces.Array.size
|
propertyPath: Loraces.Array.size
|
||||||
value: 3
|
value: 3
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: Radius.Array.size
|
||||||
|
value: 3
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: Omnidirectional.Array.size
|
||||||
|
value: 3
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: Loraces.Array.data[0]
|
propertyPath: Loraces.Array.data[0]
|
||||||
@ -24776,6 +24786,31 @@ PrefabInstance:
|
|||||||
propertyPath: Loraces.Array.data[2]
|
propertyPath: Loraces.Array.data[2]
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 675824348}
|
objectReference: {fileID: 675824348}
|
||||||
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: Radius.Array.data[0]
|
||||||
|
value: 40
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: Radius.Array.data[1]
|
||||||
|
value: 20
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: Radius.Array.data[2]
|
||||||
|
value: 50
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: Omnidirectional.Array.data[1]
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 8702400494665140028, guid: 558201eae20fa5540a826edb23937665,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: Omnidirectional.Array.data[2]
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 558201eae20fa5540a826edb23937665, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 558201eae20fa5540a826edb23937665, type: 3}
|
||||||
--- !u!1001 &6166170816655763453
|
--- !u!1001 &6166170816655763453
|
||||||
@ -24793,7 +24828,7 @@ PrefabInstance:
|
|||||||
- target: {fileID: 5133887194504435357, guid: 8cf3939d3cb6e684c8ac9618e68c8259,
|
- target: {fileID: 5133887194504435357, guid: 8cf3939d3cb6e684c8ac9618e68c8259,
|
||||||
type: 3}
|
type: 3}
|
||||||
propertyPath: Regen
|
propertyPath: Regen
|
||||||
value: 1
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5133887194504435357, guid: 8cf3939d3cb6e684c8ac9618e68c8259,
|
- target: {fileID: 5133887194504435357, guid: 8cf3939d3cb6e684c8ac9618e68c8259,
|
||||||
type: 3}
|
type: 3}
|
||||||
|
@ -4,56 +4,53 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class LoraxCuller : MonoBehaviour {
|
public class LoraxCuller : MonoBehaviour {
|
||||||
public Lorax[] Loraces;
|
public Lorax[] Loraces;
|
||||||
public Transform ChunkKeepAliveTransformsParent;
|
public int[] Radius;
|
||||||
|
public bool[] Omnidirectional;
|
||||||
|
|
||||||
private List<Transform> ChunkKeepAliveTransforms = new List<Transform>();
|
private HashSet<GameObject> OldChunks = new HashSet<GameObject>();
|
||||||
private List<GameObject>[] EnabledChunks;
|
private int LastX = int.MaxValue;
|
||||||
|
private int LastY = int.MaxValue;
|
||||||
private void Awake() {
|
private int LastAngle = int.MaxValue;
|
||||||
EnabledChunks = new List<GameObject>[Loraces.Length];
|
|
||||||
foreach (Transform Child in ChunkKeepAliveTransformsParent) {
|
|
||||||
ChunkKeepAliveTransforms.Add(Child);
|
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Update() {
|
private void Update() {
|
||||||
Hashtable Refs = new Hashtable();
|
int BaseX = Mathf.FloorToInt(transform.position.x / 20) * 20 + 10;
|
||||||
|
int BaseY = Mathf.FloorToInt(transform.position.z / 20) * 20 + 10;
|
||||||
|
int Angle = Mathf.FloorToInt(transform.localEulerAngles.y / 5) * 5;
|
||||||
|
if (BaseX == LastX && BaseY == LastY && Angle == LastAngle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LastX = BaseX;
|
||||||
|
LastY = BaseY;
|
||||||
|
LastAngle = Angle;
|
||||||
|
|
||||||
|
HashSet<GameObject> EnabledChunks = new HashSet<GameObject>();
|
||||||
for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) {
|
for (int LoraxIndex = 0; LoraxIndex < Loraces.Length; LoraxIndex++) {
|
||||||
Lorax Lorax = Loraces[LoraxIndex];
|
Lorax Lorax = Loraces[LoraxIndex];
|
||||||
for (int ChunkIndex = 0; ChunkIndex < ChunkKeepAliveTransforms.Count; ChunkIndex++) {
|
for (float X = BaseX - Radius[LoraxIndex]; X <= BaseX + Radius[LoraxIndex]; X += 10) {
|
||||||
Vector3 KeepAlivePosition = ChunkKeepAliveTransforms[ChunkIndex].position;
|
for (float Y = BaseY - Radius[LoraxIndex]; Y <= BaseY + Radius[LoraxIndex]; Y += 10) {
|
||||||
GameObject NewChunk = Lorax.GetChunkAt(KeepAlivePosition.x, KeepAlivePosition.z);
|
if (!Omnidirectional[LoraxIndex]) {
|
||||||
GameObject OldChunk = EnabledChunks[LoraxIndex][ChunkIndex];
|
Vector3 Delta = new Vector3(X - BaseX, 0, Y - BaseY);
|
||||||
NewChunk.SetActive(true);
|
if (Delta.magnitude > Mathf.Sqrt(Mathf.Pow(20, 2) * 2)) {
|
||||||
|
if (Vector3.Dot(Delta.normalized, transform.forward) < -0.2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Refs.ContainsKey(NewChunk)) {
|
GameObject Chunk = Lorax.GetChunkAt(X, Y);
|
||||||
Refs[NewChunk] = (int)Refs[NewChunk] + 1;
|
if (Chunk != null) {
|
||||||
} else {
|
Chunk.SetActive(true);
|
||||||
Refs[NewChunk] = 1;
|
EnabledChunks.Add(Chunk);
|
||||||
}
|
|
||||||
if (NewChunk != OldChunk && OldChunk != null) {
|
|
||||||
// No longer pointing to OldChunk, remove ref
|
|
||||||
if (Refs.ContainsKey(OldChunk)) {
|
|
||||||
Refs[OldChunk] = (int)Refs[OldChunk] - 1;
|
|
||||||
} else {
|
|
||||||
Refs[OldChunk] = -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnabledChunks[LoraxIndex][ChunkIndex] = NewChunk;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (GameObject Key in Refs.Keys) {
|
foreach (GameObject OldChunk in OldChunks) {
|
||||||
if ((int)Refs[Key] < 0) {
|
if (!EnabledChunks.Contains(OldChunk)) {
|
||||||
Key.SetActive(false);
|
OldChunk.SetActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
OldChunks = EnabledChunks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user