diff --git a/Assets/Scripts/AssetModificationProcessor.cs b/Assets/Scripts/AssetModificationProcessor.cs index 526956a..2613e81 100644 --- a/Assets/Scripts/AssetModificationProcessor.cs +++ b/Assets/Scripts/AssetModificationProcessor.cs @@ -18,8 +18,10 @@ public class FGAssetModificationProcessor : UnityEditor.AssetModificationProcess foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Generator")) { Lorax Lorax = obj.GetComponent(); - Lorax.DestroyGenerated(); - Lorax.Generate(); + if (Lorax.ShowInEditor) { + Lorax.DestroyGenerated(); + Lorax.Generate(); + } } } } diff --git a/Assets/Scripts/Lorax.cs b/Assets/Scripts/Lorax.cs index 9ccba04..f79fcd9 100644 --- a/Assets/Scripts/Lorax.cs +++ b/Assets/Scripts/Lorax.cs @@ -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 SpawnableTrees; public List 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; - DestroyGenerated(); + if (!Application.isPlaying) { + if (!ShowInEditor) { + if (Generated) { + DestroyGenerated(); + } + return; } - if (LastSeed == Seed && !Regen) { + 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,7 +85,9 @@ public class Lorax : MonoBehaviour { if (Chunks[CurrentChunk] == null) { Chunks[CurrentChunk] = new GameObject("Chunk " + CurrentChunk); Chunks[CurrentChunk].transform.parent = transform; - Chunks[CurrentChunk].SetActive(false); + if (Application.isPlaying) { + Chunks[CurrentChunk].SetActive(false); + } } if (Random.value > TreeChance) { continue;