EnviroZoneInspector.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace Enviro
  6. {
  7. [CustomEditor(typeof(EnviroZone))]
  8. public class EnviroZoneInspector : EnviroBaseInspector
  9. {
  10. private EnviroZone myTarget;
  11. private SerializedProperty autoWeatherChanges, weatherChangeIntervall, zoneScale, zoneGizmoColor;
  12. void OnEnable()
  13. {
  14. myTarget = (EnviroZone)target;
  15. serializedObj = new SerializedObject(myTarget);
  16. autoWeatherChanges = serializedObj.FindProperty("autoWeatherChanges");
  17. weatherChangeIntervall = serializedObj.FindProperty("weatherChangeIntervall");
  18. zoneScale = serializedObj.FindProperty("zoneScale");
  19. zoneGizmoColor = serializedObj.FindProperty("zoneGizmoColor");
  20. }
  21. public override void OnInspectorGUI()
  22. {
  23. SetupGUIStyles();
  24. GUILayout.BeginVertical("", boxStyle);
  25. GUILayout.Label("Enviro Weather Zone",headerStyleMid);
  26. //Help Box Button
  27. //RenderHelpBoxButton();
  28. // if(showHelpBox)
  29. // RenderHelpBox("This is a help text test!");
  30. GUILayout.EndVertical();
  31. serializedObj.UpdateIfRequiredOrScript ();
  32. EditorGUI.BeginChangeCheck();
  33. GUILayout.BeginVertical("", boxStyle);
  34. GUILayout.Label("Zone Setup",headerStyleMid);
  35. GUILayout.BeginVertical("",boxStyleModified);
  36. EditorGUILayout.PropertyField(zoneScale);
  37. EditorGUILayout.PropertyField(zoneGizmoColor);
  38. GUILayout.EndVertical ();
  39. GUILayout.EndVertical ();
  40. GUILayout.BeginVertical("", boxStyle);
  41. GUILayout.Label("Weather Setup",headerStyleMid);
  42. GUILayout.Space(5f);
  43. if(myTarget.currentWeatherType != null)
  44. GUILayout.Label("Current Weather: " + myTarget.currentWeatherType.name,wrapStyle);
  45. else
  46. GUILayout.Label("Current Weather: Not Set",wrapStyle);
  47. GUILayout.Space(5f);
  48. if(myTarget.nextWeatherType != null)
  49. {
  50. if(EnviroManager.instance != null && EnviroManager.instance.Time != null)
  51. {
  52. GUILayout.Label("Next Change in: " + (myTarget.nextWeatherUpdate - EnviroManager.instance.Time.GetDateInHours()).ToString("#.00") + " hours",wrapStyle);
  53. }
  54. }
  55. else
  56. {
  57. GUILayout.Label("Next Change in: Not Set");
  58. }
  59. GUILayout.Space(5f);
  60. if(myTarget.nextWeatherType != null)
  61. GUILayout.Label("Next Weather: " + myTarget.nextWeatherType.name,wrapStyle);
  62. else
  63. GUILayout.Label("Next Weather: Not Set",wrapStyle);
  64. GUILayout.Space(5f);
  65. GUILayout.BeginVertical("", boxStyleModified);
  66. EditorGUILayout.PropertyField(autoWeatherChanges);
  67. EditorGUILayout.PropertyField(weatherChangeIntervall);
  68. GUILayout.EndVertical();
  69. GUILayout.Space(5f);
  70. GUILayout.BeginVertical("",boxStyleModified);
  71. Object selectedObject = null;
  72. if(GUILayout.Button("Add"))
  73. {
  74. int controlID = EditorGUIUtility.GetControlID (FocusType.Passive);
  75. EditorGUIUtility.ShowObjectPicker<EnviroWeatherType>(null,false,"",controlID);
  76. }
  77. string commandName = Event.current.commandName;
  78. if (commandName == "ObjectSelectorClosed")
  79. {
  80. selectedObject = EditorGUIUtility.GetObjectPickerObject ();
  81. bool add = true;
  82. for (int i = 0; i < myTarget.weatherTypeList.Count; i++)
  83. {
  84. if((EnviroWeatherType)selectedObject == myTarget.weatherTypeList[i].weatherType)
  85. add = false;
  86. }
  87. if(selectedObject == null)
  88. add = false;
  89. if(add)
  90. myTarget.AddWeatherType((EnviroWeatherType)selectedObject);
  91. }
  92. GUILayout.Space(15);
  93. for (int i = 0; i < myTarget.weatherTypeList.Count; i++)
  94. {
  95. EnviroZoneWeather curZoneWeather = myTarget.weatherTypeList[i];
  96. GUILayout.BeginVertical ("", boxStyleModified);
  97. EditorGUILayout.BeginHorizontal();
  98. string name = "Empty";
  99. if(curZoneWeather.weatherType != null)
  100. name = curZoneWeather.weatherType.name;
  101. curZoneWeather.showEditor = GUILayout.Toggle(curZoneWeather.showEditor, name, headerFoldout);
  102. GUILayout.FlexibleSpace();
  103. if(curZoneWeather.weatherType != myTarget.currentWeatherType)
  104. {
  105. if(GUILayout.Button("Change Now", EditorStyles.miniButtonRight,GUILayout.Width(80), GUILayout.Height(18)))
  106. {
  107. myTarget.ChangeZoneWeatherInstant(curZoneWeather.weatherType);
  108. //EditorUtility.SetDirty(curWT);
  109. }
  110. }
  111. if(GUILayout.Button("x", EditorStyles.miniButtonRight,GUILayout.Width(18), GUILayout.Height(18)))
  112. {
  113. myTarget.RemoveWeatherZoneType(curZoneWeather);
  114. }
  115. EditorGUILayout.EndHorizontal();
  116. if(curZoneWeather.showEditor)
  117. {
  118. GUILayout.BeginVertical ("", boxStyleModified);
  119. curZoneWeather.probability = EditorGUILayout.Slider("Probabillity",curZoneWeather.probability,0f,100f);
  120. EditorGUILayout.EndVertical ();
  121. }
  122. GUILayout.EndVertical ();
  123. }
  124. GUILayout.EndVertical ();
  125. GUILayout.EndVertical ();
  126. ApplyChanges();
  127. }
  128. }
  129. }