WindControllerInspector.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEditor;
  4. namespace FAE
  5. {
  6. [CustomEditor(typeof(WindController))]
  7. public class WindControllerInspector : Editor
  8. {
  9. WindController wc;
  10. private bool showHelp = false;
  11. private bool visualizeVectors;
  12. new SerializedObject serializedObject;
  13. SerializedProperty listenToWindZone;
  14. SerializedProperty windZone;
  15. SerializedProperty windVectors;
  16. SerializedProperty windSpeed;
  17. SerializedProperty windStrength;
  18. SerializedProperty windAmplitude;
  19. SerializedProperty trunkWindSpeed;
  20. SerializedProperty trunkWindWeight;
  21. SerializedProperty trunkWindSwinging;
  22. #if UNITY_EDITOR
  23. void OnEnable()
  24. {
  25. wc = (WindController)target;
  26. serializedObject = new SerializedObject(target);
  27. listenToWindZone = serializedObject.FindProperty("listenToWindZone");
  28. windZone = serializedObject.FindProperty("windZone");
  29. windVectors = serializedObject.FindProperty("windVectors");
  30. windSpeed = serializedObject.FindProperty("windSpeed");
  31. windStrength = serializedObject.FindProperty("windStrength");
  32. windAmplitude = serializedObject.FindProperty("windAmplitude");
  33. trunkWindSpeed = serializedObject.FindProperty("trunkWindSpeed");
  34. trunkWindWeight = serializedObject.FindProperty("trunkWindWeight");
  35. trunkWindSwinging = serializedObject.FindProperty("trunkWindSwinging");
  36. }
  37. public override void OnInspectorGUI()
  38. {
  39. serializedObject.Update();
  40. EditorGUI.BeginChangeCheck();
  41. //Sync inspector var to static class var
  42. visualizeVectors = WindController._visualizeVectors;
  43. Undo.RecordObject(this, "Component");
  44. Undo.RecordObject(wc, "WindController");
  45. DrawFields();
  46. serializedObject.ApplyModifiedProperties();
  47. if (GUI.changed || EditorGUI.EndChangeCheck())
  48. {
  49. EditorUtility.SetDirty((WindController)target);
  50. wc.Apply();
  51. //Set the static var
  52. WindController.VisualizeVectors(visualizeVectors);
  53. }
  54. }
  55. private void DrawFields()
  56. {
  57. DoHeader();
  58. EditorGUILayout.Space();
  59. EditorGUILayout.PropertyField(windVectors);
  60. if (!windVectors.objectReferenceValue)
  61. {
  62. EditorGUILayout.HelpBox("Assign a wind vector map for wind to function", MessageType.Error);
  63. return;
  64. }
  65. EditorGUILayout.PropertyField(listenToWindZone, new GUIContent("Listen to Wind Zone"));
  66. if (showHelp) EditorGUILayout.HelpBox("When a Wind Zone is assigned, the wind strength and tree trunk weight values are divided by it's \"Main\" parameter value.\n\nThis allows you to use weather systems such as Enviro", MessageType.Info);
  67. if (listenToWindZone.boolValue)
  68. {
  69. EditorGUILayout.PropertyField(windZone, new GUIContent("Wind Zone"));
  70. }
  71. EditorGUILayout.Space();
  72. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  73. EditorGUILayout.LabelField("Wind settings", EditorStyles.toolbarButton);
  74. EditorGUILayout.Space();
  75. EditorGUILayout.PropertyField(windSpeed, new GUIContent("Speed"));
  76. if (showHelp) EditorGUILayout.HelpBox("The overall speed of the wind.", MessageType.Info);
  77. EditorGUILayout.PropertyField(windStrength, new GUIContent("Strength"));
  78. if (showHelp) EditorGUILayout.HelpBox("The overall strength of the wind.", MessageType.Info);
  79. EditorGUILayout.PropertyField(windAmplitude, new GUIContent("Amplitude"));
  80. if (showHelp) EditorGUILayout.HelpBox("The overall amplitude of the wind, essentially the size of wind waves.\n\nThe shader have a \"WindAmplitudeMultiplier\" parameter which multiplies this value in the material.", MessageType.Info);
  81. EditorGUILayout.Space();
  82. EditorGUILayout.EndVertical();
  83. EditorGUILayout.Space();
  84. EditorGUILayout.BeginVertical(EditorStyles.helpBox);
  85. EditorGUILayout.LabelField("Tree trunks", EditorStyles.toolbarButton);
  86. EditorGUILayout.Space();
  87. EditorGUILayout.PropertyField(trunkWindSpeed, new GUIContent("Speed"));
  88. if (showHelp) EditorGUILayout.HelpBox("The speed by which the tree moves.", MessageType.Info);
  89. EditorGUILayout.PropertyField(trunkWindWeight, new GUIContent("Weight"));
  90. if (showHelp) EditorGUILayout.HelpBox("The amount of influence the wind has on a tree.", MessageType.Info);
  91. EditorGUILayout.PropertyField(trunkWindSwinging, new GUIContent("Swinging"));
  92. if (showHelp) EditorGUILayout.HelpBox("A value higher than 0 means the trees will also move against the wind direction.", MessageType.Info);
  93. EditorGUILayout.Space();
  94. EditorGUILayout.EndVertical();
  95. visualizeVectors = EditorGUILayout.Toggle("Visualize wind", visualizeVectors);
  96. if (showHelp) EditorGUILayout.HelpBox("Toggle a visualisation of the wind vectors on all the objects that use FAE shaders featuring wind.\n\nThis allows you to more clearly see the effects of the settings.", MessageType.Info);
  97. GUIHelper.DrawFooter();
  98. }
  99. private void DoHeader()
  100. {
  101. EditorGUILayout.BeginHorizontal();
  102. showHelp = GUILayout.Toggle(showHelp, "Toggle help", "Button");
  103. GUILayout.Label("FAE Wind Controller", GUIHelper.Header);
  104. EditorGUILayout.EndHorizontal();
  105. if (showHelp) EditorGUILayout.HelpBox("This script drives the wind parameters of the Foliage, Grass, Tree Branch and Tree Trunk shaders.", MessageType.Info);
  106. }
  107. #endif
  108. }
  109. }