HBAOGaiaExtension.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #if GAIA_PRESENT && UNITY_EDITOR
  2. using HorizonBasedAmbientOcclusion;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace Gaia.GX.MichaelJimenez
  6. {
  7. public class HBAOGaiaExtension : MonoBehaviour
  8. {
  9. #region Generic informational methods
  10. /// <summary>
  11. /// Returns the publisher name if provided.
  12. /// This will override the publisher name in the namespace ie Gaia.GX.PublisherName
  13. /// </summary>
  14. /// <returns>Publisher name</returns>
  15. public static string GetPublisherName()
  16. {
  17. return "Michael Jimenez";
  18. }
  19. /// <summary>
  20. /// Returns the package name if provided
  21. /// This will override the package name in the class name ie public class PackageName.
  22. /// </summary>
  23. /// <returns>Package name</returns>
  24. public static string GetPackageName()
  25. {
  26. return "Horizon Based Ambient Occlusion";
  27. }
  28. #endregion
  29. #region Methods exposed by Gaia as buttons must be prefixed with GX_
  30. public static void GX_About()
  31. {
  32. EditorUtility.DisplayDialog("About Horizon Based Ambient Occlusion ", "HBAO is a post processing image effect to use in order to add realism to your scenes. It helps accentuating small surface details and reproduce light attenuation due to occlusion.\n\nNote: This Post FX should be the first in your effect stack.", "OK");
  33. }
  34. public static void GX_Presets_FastestPerformance()
  35. {
  36. HBAO hbao = StackPostFXOnTop();
  37. if (hbao != null)
  38. {
  39. hbao.ApplyPreset(HBAO.Preset.FastestPerformance);
  40. MarkDirty(hbao);
  41. }
  42. }
  43. public static void GX_Presets_FastPerformance()
  44. {
  45. HBAO hbao = StackPostFXOnTop();
  46. if (hbao != null)
  47. {
  48. hbao.ApplyPreset(HBAO.Preset.FastPerformance);
  49. MarkDirty(hbao);
  50. }
  51. }
  52. public static void GX_Presets_Normal()
  53. {
  54. HBAO hbao = StackPostFXOnTop();
  55. if (hbao != null)
  56. {
  57. hbao.ApplyPreset(HBAO.Preset.Normal);
  58. MarkDirty(hbao);
  59. }
  60. }
  61. public static void GX_Presets_HighQuality()
  62. {
  63. HBAO hbao = StackPostFXOnTop();
  64. if (hbao != null)
  65. {
  66. hbao.ApplyPreset(HBAO.Preset.HighQuality);
  67. MarkDirty(hbao);
  68. }
  69. }
  70. public static void GX_Presets_HighestQuality()
  71. {
  72. HBAO hbao = StackPostFXOnTop();
  73. if (hbao != null)
  74. {
  75. hbao.ApplyPreset(HBAO.Preset.HighestQuality);
  76. MarkDirty(hbao);
  77. }
  78. }
  79. #endregion
  80. #region Helper methods
  81. private static HBAO StackPostFXOnTop()
  82. {
  83. Camera camera = Camera.main;
  84. if (camera == null)
  85. {
  86. camera = FindObjectOfType<Camera>();
  87. }
  88. if (camera == null)
  89. {
  90. EditorUtility.DisplayDialog("OOPS!", "Could not find camera to add camera effects to. Please add a camera to your scene.", "OK");
  91. return null;
  92. }
  93. // add HBAO to camera
  94. HBAO hbao = camera.GetComponent<HBAO>();
  95. if (hbao != null)
  96. {
  97. DestroyImmediate(hbao);
  98. }
  99. hbao = camera.gameObject.AddComponent<HBAO>();
  100. // stack it on top
  101. while (camera.GetComponents<MonoBehaviour>()[0] != hbao)
  102. {
  103. UnityEditorInternal.ComponentUtility.MoveComponentUp(hbao);
  104. }
  105. return hbao;
  106. }
  107. private static void MarkDirty(HBAO hbao)
  108. {
  109. EditorUtility.SetDirty(hbao);
  110. if (!EditorApplication.isPlaying)
  111. {
  112. UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
  113. }
  114. }
  115. #endregion
  116. }
  117. }
  118. #endif