Make some changes to the lorax

This commit is contained in:
Sofia 2020-04-20 05:24:01 +03:00
parent 617c48d4ff
commit 6c232fd391
2 changed files with 20 additions and 18 deletions

View File

@ -18,8 +18,10 @@ public class FGAssetModificationProcessor : UnityEditor.AssetModificationProcess
foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Generator")) {
Lorax Lorax = obj.GetComponent<Lorax>();
if (Lorax.ShowInEditor) {
Lorax.DestroyGenerated();
Lorax.Generate();
}
}
}
}

View File

@ -10,7 +10,7 @@ public class Lorax : MonoBehaviour {
[Header("Generic Gen")]
public int Seed;
public bool Regen = false;
public bool Destroy = false;
public bool ShowInEditor = true;
public List<GameObject> SpawnableTrees;
public List<int> Chances;
@ -26,22 +26,24 @@ public class Lorax : MonoBehaviour {
private int LastSeed = -1;
private Vector3[][] TreePositions;
private bool Generated = false;
private int ChunkSize = 20;
private GameObject[] Chunks;
void Start() {
Debug.Log((int)((Mathf.Floor((228.55f) / ChunkSize) * 25) + Mathf.Floor(245.27f / ChunkSize)));
Generate();
}
void Update() {
if (Application.isEditor) {
if (Destroy) {
Destroy = false;
if (!Application.isPlaying) {
if (!ShowInEditor) {
if (Generated) {
DestroyGenerated();
}
if (LastSeed == Seed && !Regen) {
return;
}
if (Generated && LastSeed == Seed && !Regen) {
return;
}
Regen = false;
@ -52,13 +54,6 @@ public class Lorax : MonoBehaviour {
}
public GameObject GetChunkAt(float x, float y) {
/*Debug.Log("----------------");
Debug.Log("y: " + (y + 250f));
Debug.Log("x: " + (x + 250f));
Debug.Log("y divided: " + (y + 250f) / ChunkSize);
Debug.Log("x divided: " + (x + 250f) / ChunkSize);
Debug.Log("y floored: " + (Mathf.Floor((y + 250f) / ChunkSize)));
Debug.Log("x floored: " + (Mathf.Floor((x + 250f) / ChunkSize)));*/
int CurrentChunk = (int)((Mathf.Floor((y + 250f) / ChunkSize) * 25f) + Mathf.Floor((x + 250f) / ChunkSize));
return Chunks[CurrentChunk];
}
@ -68,10 +63,13 @@ public class Lorax : MonoBehaviour {
DestroyImmediate(transform.GetChild(0).gameObject);
}
Chunks = new GameObject[(500 / ChunkSize) * (500 / ChunkSize)];
Generated = false;
}
public void Generate() {
Random.InitState(Seed);
Generated = true;
Chunks = new GameObject[(500 / ChunkSize) * (500 / ChunkSize)];
int[] TotalChances = new int[SpawnableTrees.Count + 1];
int Counter = 0;
for (int x = 0; x < TotalChances.Length - 1; x++) {
@ -87,8 +85,10 @@ public class Lorax : MonoBehaviour {
if (Chunks[CurrentChunk] == null) {
Chunks[CurrentChunk] = new GameObject("Chunk " + CurrentChunk);
Chunks[CurrentChunk].transform.parent = transform;
if (Application.isPlaying) {
Chunks[CurrentChunk].SetActive(false);
}
}
if (Random.value > TreeChance) {
continue;
}