GUIHelper.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace FAE
  5. {
  6. /// <summary>
  7. /// Helper class to centralize commonly used fields and styles used in inspectors
  8. /// </summary>
  9. public class GUIHelper : Editor
  10. {
  11. /// <summary>Draws the Staggart Creations footer</summary>
  12. public static void DrawFooter()
  13. {
  14. GUILayout.Label("- Staggart Creations -", new GUIStyle(EditorStyles.centeredGreyMiniLabel)
  15. {
  16. alignment = TextAnchor.MiddleCenter,
  17. wordWrap = true,
  18. fontSize = 12
  19. });
  20. }
  21. /// <summary>Displays a box with the wind values from the current WindController</summary>
  22. public static void DrawWindInfo()
  23. {
  24. EditorGUILayout.Space();
  25. EditorGUILayout.LabelField("Global wind settings", EditorStyles.boldLabel);
  26. GUIHelper.ProgressBar(WindController._windStrength, 1f, "Strength");
  27. GUIHelper.ProgressBar(WindController._windAmplitude, 32f, "Amplitude");
  28. EditorGUILayout.Space();
  29. }
  30. private static void ProgressBar(float value, float maxValue, string label)
  31. {
  32. Rect rect = GUILayoutUtility.GetRect(6, 18, "TextField");
  33. EditorGUI.ProgressBar(rect, value / maxValue, label + " (" + value + " / " + maxValue + ")");
  34. }
  35. /// <summary>If the supported Unity version is used, a field for setting the Render Queue and GPU Instancing options is drawn</summary>
  36. public static void DrawExtraFields(MaterialEditor m_MaterialEditor)
  37. {
  38. #if UNITY_5_5_OR_NEWER
  39. m_MaterialEditor.RenderQueueField();
  40. #endif
  41. #if UNITY_5_6_OR_NEWER
  42. m_MaterialEditor.EnableInstancingField();
  43. #endif
  44. }
  45. //Styles
  46. private static GUIStyle _Header;
  47. public static GUIStyle Header
  48. {
  49. get
  50. {
  51. if (_Header == null)
  52. {
  53. _Header = new GUIStyle(EditorStyles.centeredGreyMiniLabel)
  54. {
  55. alignment = TextAnchor.MiddleCenter,
  56. wordWrap = true,
  57. fontSize = 12
  58. };
  59. }
  60. return _Header;
  61. }
  62. }
  63. }
  64. }