using System; using System.Collections; using System.Collections.Generic; using TrafficSimulation; using UnityEditor; using UnityEngine; public class CarSpawnManipulator : MonoBehaviour { private void Start() { } private void Update() { } } [CustomEditor(typeof(CarSpawnManipulator))] public class CarSpawnManipulatorEditor : Editor { private SpawnWatcher[] spawns; private int spawnRate = 2; private void OnEnable() { this.spawns = ((CarSpawnManipulator) target).GetComponentsInChildren(); } public override void OnInspectorGUI() { EditorGUILayout.LabelField("Sets All Car Spawns in the Conditions!"); //Debug.Log("Found Spawns: " + this.spawns.Length); if (GUILayout.Button("Position Y to 0", GUILayout.Width(256))) { SetPosY(0); } if (GUILayout.Button("BoxCollider Size (6,1,6)", GUILayout.Width(256))) { SetSize(10,10); } this.spawnRate = EditorGUILayout.IntSlider("Spawn Rate", this.spawnRate,0, 10); if (GUILayout.Button("Set Spawn Rate", GUILayout.Width(256))) { SetSpawnRate(spawnRate); } } private void SetSpawnRate(int rate) { CarSituationSpawner[] spawners = ((CarSpawnManipulator)target).GetComponentsInChildren(); foreach(CarSituationSpawner spawner in spawners) { spawner.spawnRate = rate; } } private void SetSize(float xVal, float yVal) { foreach (SpawnWatcher spawn in this.spawns) { spawn.gameObject.GetComponent().size = new Vector3(6, 1, 6); } } private void SetPosY(float value) { foreach(SpawnWatcher spawn in this.spawns) { spawn.gameObject.transform.position = new Vector3(spawn.gameObject.transform.position.x, value, spawn.gameObject.transform.position.z); } } }