FlareEditorHelper.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /// ProFlares - v1.08 - Copyright 2014-2015 All rights reserved - ProFlares.com
  2. /// <summary>
  3. /// FlareEditorHelper.cs
  4. /// Helper class that contains a number of functions that other Editor Scripts use.
  5. /// </summary>
  6. using UnityEngine;
  7. using UnityEditor;
  8. using System.Collections;
  9. public class FlareEditorHelper : MonoBehaviour {
  10. const int menuPos = 10000;
  11. //public static bool ProFlaresDebugMessages = false;
  12. [MenuItem ("Window/ProFlares/Create Setup",false,menuPos+0)]
  13. static void CreateSetup () {
  14. GameObject rootGO = new GameObject("ProFlareSetup");
  15. rootGO.layer = 8;
  16. GameObject cameraGO = new GameObject("ProFlareCamera");
  17. cameraGO.layer = 8;
  18. Camera camera = cameraGO.AddComponent<Camera>();
  19. cameraGO.transform.parent = rootGO.transform;
  20. camera.clearFlags = CameraClearFlags.Depth;
  21. camera.orthographic = true;
  22. camera.orthographicSize = 1;
  23. camera.farClipPlane = 2;
  24. camera.nearClipPlane = -2;
  25. camera.depth++;
  26. camera.cullingMask = 1 << 8;
  27. GameObject batchGO = new GameObject("ProFlareBatch");
  28. batchGO.layer = 8;
  29. batchGO.transform.parent = cameraGO.transform;
  30. ProFlareBatch batch = batchGO.AddComponent<ProFlareBatch>();
  31. batch.FlareCamera = camera;
  32. if(PlayerSettings.colorSpace == ColorSpace.Linear){
  33. batch.linearColorSpace = true;
  34. }
  35. GameObject MainCameraGo = GameObject.FindWithTag("MainCamera");
  36. if(MainCameraGo){
  37. batch.GameCamera = MainCameraGo.GetComponent<Camera>();
  38. batch.GameCameraTrans = MainCameraGo.transform;
  39. }
  40. Selection.activeGameObject = batchGO;
  41. }
  42. [MenuItem ("Window/ProFlares/Create Setup On Selected Camera",false,menuPos+0)]
  43. static void CreateSetupOnExisting () {
  44. GameObject cameraGO = null;
  45. Camera camera = null;
  46. if(Selection.activeGameObject){
  47. camera = Selection.activeGameObject.GetComponent<Camera>();
  48. if(camera == null){
  49. Debug.LogError("ProFlares - No Camera Selected");
  50. return;
  51. }else{
  52. cameraGO = Selection.activeGameObject;
  53. }
  54. }else{
  55. Debug.LogError("ProFlares - Nothing Selected");
  56. return;
  57. }
  58. Vector3 worldScale = cameraGO.transform.localScale;
  59. Transform parent = cameraGO.transform.parent;
  60. while (parent != null)
  61. {
  62. worldScale = Vector3.Scale(worldScale,parent.localScale);
  63. parent = parent.parent;
  64. }
  65. // Debug.LogError(worldScale.x + " " + worldScale.y + " " + worldScale.z);
  66. // Debug.LogError(1f/worldScale.x + " " + 1f/worldScale.y + " " + 1f/worldScale.z);
  67. int layerNumber = cameraGO.layer;
  68. GameObject batchGO = new GameObject("ProFlareBatch");
  69. batchGO.layer = layerNumber;
  70. batchGO.transform.parent = cameraGO.transform;
  71. batchGO.transform.localPosition = Vector3.zero;
  72. batchGO.transform.localScale = new Vector3(1f/worldScale.x,1f/worldScale.y,1f/worldScale.z);
  73. ProFlareBatch batch = batchGO.AddComponent<ProFlareBatch>();
  74. batch.FlareCamera = camera;
  75. batch.FlareCameraTrans = camera.transform;
  76. GameObject MainCameraGo = GameObject.FindWithTag("MainCamera");
  77. if(MainCameraGo){
  78. batch.GameCamera = MainCameraGo.GetComponent<Camera>();
  79. batch.GameCameraTrans = MainCameraGo.transform;
  80. }
  81. if(PlayerSettings.colorSpace == ColorSpace.Linear){
  82. batch.linearColorSpace = true;
  83. }
  84. Selection.activeGameObject = batchGO;
  85. }
  86. [MenuItem ("Window/ProFlares/Create Single Camera Setup On Selected Main Camera",false,menuPos+1)]
  87. static void CreateSetupOnExistingGameCamera () {
  88. GameObject cameraGO = null;
  89. Camera camera = null;
  90. if(Selection.activeGameObject){
  91. camera = Selection.activeGameObject.GetComponent<Camera>();
  92. if(camera == null){
  93. Debug.LogError("ProFlares - No Camera Selected");
  94. return;
  95. }else{
  96. cameraGO = Selection.activeGameObject;
  97. }
  98. }else{
  99. Debug.LogError("ProFlares - Nothing Selected");
  100. return;
  101. }
  102. // Vector3 worldScale = cameraGO.transform.localScale;
  103. // Transform parent = cameraGO.transform.parent;
  104. int layerNumber = cameraGO.layer;
  105. GameObject batchGO = new GameObject("ProFlareBatch");
  106. batchGO.layer = layerNumber;
  107. batchGO.transform.parent = cameraGO.transform;
  108. batchGO.transform.localPosition = Vector3.zero;
  109. batchGO.transform.localRotation = Quaternion.identity;
  110. batchGO.transform.localScale = Vector3.one;
  111. ProFlareBatch batch = batchGO.AddComponent<ProFlareBatch>();
  112. batch.FlareCamera = camera;
  113. batch.GameCamera = camera;
  114. batch.FlareCameraTrans = camera.transform;
  115. batch.mode = ProFlareBatch.Mode.SingleCamera;
  116. batch.SingleCamera_Mode = true;
  117. batch.zPos = 10;
  118. if(PlayerSettings.colorSpace == ColorSpace.Linear){
  119. batch.linearColorSpace = true;
  120. }
  121. /*
  122. GameObject MainCameraGo = GameObject.FindWithTag("MainCamera");
  123. if(MainCameraGo){
  124. batch.GameCamera = MainCameraGo.camera;
  125. batch.GameCameraTrans = MainCameraGo.transform;
  126. }*/
  127. Selection.activeGameObject = batchGO;
  128. }
  129. [MenuItem ("Window/ProFlares/Create Flare",false,menuPos+12)]
  130. static void CreateFlare () {
  131. GameObject flareGO = new GameObject("Flare");
  132. flareGO.layer = 8;
  133. flareGO.AddComponent<ProFlare>();
  134. Selection.activeGameObject = flareGO;
  135. }
  136. [MenuItem ("Window/ProFlares/Help",false,menuPos+71)]
  137. static void ProFlareHelp () {
  138. Application.OpenURL("http://www.proflares.com/help");
  139. }
  140. public static void DrawGuiInBoxDivider(){
  141. GUILayout.Space(8f);
  142. if (Event.current.type == EventType.Repaint)
  143. {
  144. int extra = 0;
  145. extra = 10;
  146. Texture2D tex = EditorGUIUtility.whiteTexture;
  147. Rect rect = GUILayoutUtility.GetLastRect();
  148. GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.25f);
  149. GUI.DrawTexture(new Rect(5f+extra, rect.yMin + 5f, Screen.width-11, 1f), tex);
  150. GUI.color = Color.white;
  151. }
  152. }
  153. public static void DrawGuiDivider(){
  154. GUILayout.Space(12f);
  155. if (Event.current.type == EventType.Repaint)
  156. {
  157. Texture2D tex = EditorGUIUtility.whiteTexture;
  158. Rect rect = GUILayoutUtility.GetLastRect();
  159. GUI.color = new Color(0f, 0f, 0f, 0.25f);
  160. GUI.DrawTexture(new Rect(0f, rect.yMin + 6f, Screen.width, 4f), tex);
  161. GUI.DrawTexture(new Rect(0f, rect.yMin + 6f, Screen.width, 1f), tex);
  162. GUI.DrawTexture(new Rect(0f, rect.yMin + 9f, Screen.width, 1f), tex);
  163. GUI.color = Color.white;
  164. }
  165. }
  166. public static GUIStyle TitleStyle(){
  167. GUIStyle title = new GUIStyle(EditorStyles.largeLabel);
  168. title.fontSize = 16;
  169. title.clipping = TextClipping.Overflow;
  170. return title;
  171. }
  172. public static GUIStyle ThinButtonStyle(){
  173. GUIStyle thinButton = new GUIStyle(EditorStyles.toolbarButton);
  174. thinButton.fontStyle = FontStyle.Bold;
  175. thinButton.fixedHeight = 24f;
  176. return thinButton;
  177. }
  178. public static GUIStyle ThinButtonRedStyle(){
  179. GUIStyle thinButtonRed = new GUIStyle(EditorStyles.toolbarButton);
  180. thinButtonRed.fontStyle = FontStyle.Bold;
  181. thinButtonRed.fixedHeight = 24f;
  182. thinButtonRed.normal.textColor = Color.red;
  183. return thinButtonRed;
  184. }
  185. public static GUIStyle ThinButtonPressedStyle(){
  186. GUIStyle thinButtonPressed = new GUIStyle(EditorStyles.toolbarButton);
  187. thinButtonPressed.fontStyle = FontStyle.Bold;
  188. thinButtonPressed.fixedHeight = 24f;
  189. return thinButtonPressed;
  190. }
  191. public static GUIStyle DropDownButtonStyle(){
  192. GUIStyle dropDownButton = new GUIStyle(EditorStyles.toolbarDropDown);
  193. dropDownButton.fontStyle = FontStyle.Bold;
  194. dropDownButton.fixedHeight = 20f;
  195. return dropDownButton;
  196. }
  197. public static GUIStyle EnumStyleButton(){
  198. GUIStyle enumStyleButton = new GUIStyle(EditorStyles.toolbarDropDown);
  199. enumStyleButton.onActive.background = ThinButtonStyle().onActive.background;
  200. enumStyleButton.fixedHeight = 24f;
  201. return enumStyleButton;
  202. }
  203. public static GUIStyle FoldOutButtonStyle(){
  204. GUIStyle foldOutButton = new GUIStyle(EditorStyles.foldout);
  205. foldOutButton.fontStyle = FontStyle.Bold;
  206. return foldOutButton;
  207. }
  208. }