IntersectionEditor.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Traffic Simulation
  2. // https://github.com/mchrbn/unity-traffic-simulation
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace TrafficSimulation {
  6. [CustomEditor(typeof(Intersection))]
  7. public class IntersectionEditor : Editor
  8. {
  9. private Intersection intersection;
  10. void OnEnable(){
  11. intersection = target as Intersection;
  12. }
  13. public override void OnInspectorGUI(){
  14. intersection.intersectionType = (IntersectionType) EditorGUILayout.EnumPopup("Intersection type", intersection.intersectionType);
  15. EditorGUI.BeginDisabledGroup(intersection.intersectionType != IntersectionType.STOP);
  16. EditorGUILayout.LabelField("Stop", EditorStyles.boldLabel);
  17. SerializedProperty sPrioritySegments = serializedObject.FindProperty("prioritySegments");
  18. EditorGUILayout.PropertyField(sPrioritySegments, new GUIContent("Priority Segments"), true);
  19. serializedObject.ApplyModifiedProperties();
  20. EditorGUI.EndDisabledGroup();
  21. EditorGUI.BeginDisabledGroup(intersection.intersectionType != IntersectionType.TRAFFIC_LIGHT);
  22. EditorGUILayout.LabelField("Traffic Lights", EditorStyles.boldLabel);
  23. intersection.lightsDuration = EditorGUILayout.FloatField("Light Duration (in s.)", intersection.lightsDuration);
  24. intersection.orangeLightDuration = EditorGUILayout.FloatField("Orange Light Duration (in s.)", intersection.orangeLightDuration);
  25. SerializedProperty sLightsNbr1 = serializedObject.FindProperty("lightsNbr1");
  26. SerializedProperty sLightsNbr2 = serializedObject.FindProperty("lightsNbr2");
  27. EditorGUILayout.PropertyField(sLightsNbr1, new GUIContent("Lights #1 (first to be red)"), true);
  28. EditorGUILayout.PropertyField(sLightsNbr2, new GUIContent("Lights #2"), true);
  29. serializedObject.ApplyModifiedProperties();
  30. EditorGUI.EndDisabledGroup();
  31. }
  32. }
  33. }