fxvIntroWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using UnityEngine.Rendering;
  8. namespace FXV.VolumetricFogEditorUtils
  9. {
  10. internal class fxvAssetPostprocess : AssetPostprocessor
  11. {
  12. private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
  13. {
  14. foreach (string str in importedAssets)
  15. {
  16. #if FX_DEBUG_LOGS
  17. Debug.Log("Reimported Asset: " + str);
  18. #endif
  19. if (str.Contains("fxvIntroWindow"))
  20. {
  21. fxvIntroWindow.ShowPipelineIntro();
  22. return;
  23. }
  24. }
  25. }
  26. }
  27. public partial class fxvIntroWindow : EditorWindow
  28. {
  29. static string version = "version 1.0.11";
  30. static int windowWidth = 700;
  31. static int windowHeight = 400;
  32. static int buttonWidth = 100;
  33. [MenuItem("Window/FXV/VolumetricFog/Intro")]
  34. public static void ShowPipelineIntro()
  35. {
  36. var currentRP = GraphicsSettings.currentRenderPipeline;
  37. if (currentRP == null)
  38. {
  39. ShowIntroWindowBuiltIn();
  40. return;
  41. }
  42. var curPipeline = currentRP.GetType().ToString().ToLower();
  43. if (curPipeline.Contains("universal"))
  44. {
  45. ShowIntroWindowURP();
  46. }
  47. else if (curPipeline.Contains("high definition") || curPipeline.Contains("highdefinition"))
  48. {
  49. ShowIntroWindowHDRP();
  50. }
  51. }
  52. public static void ShowIntroWindowBuiltIn()
  53. {
  54. #if FX_DEBUG_LOGS
  55. Debug.Log("FXV.Shield ShowIntroWindow");
  56. #endif
  57. fxvIntroWindow wnd = GetWindow<fxvIntroWindow>();
  58. wnd.titleContent = new GUIContent("Welcome Built In");
  59. wnd.pipelineType = 0;
  60. wnd.minSize = new Vector2(windowWidth, windowHeight);
  61. wnd.maxSize = new Vector2(windowWidth, windowHeight);
  62. wnd.Init();
  63. }
  64. public static void ShowIntroWindowURP()
  65. {
  66. #if FX_DEBUG_LOGS
  67. Debug.Log("FXV.Shield ShowIntroWindow");
  68. #endif
  69. fxvIntroWindow wnd = GetWindow<fxvIntroWindow>();
  70. wnd.titleContent = new GUIContent("Welcome URP");
  71. wnd.pipelineType = 1;
  72. wnd.minSize = new Vector2(windowWidth, windowHeight);
  73. wnd.maxSize = new Vector2(windowWidth, windowHeight);
  74. wnd.Init();
  75. }
  76. public static void ShowIntroWindowHDRP()
  77. {
  78. #if FX_DEBUG_LOGS
  79. Debug.Log("FXV.Shield ShowIntroWindow");
  80. #endif
  81. fxvIntroWindow wnd = GetWindow<fxvIntroWindow>();
  82. wnd.titleContent = new GUIContent("Welcome HDRP");
  83. wnd.pipelineType = 2;
  84. wnd.minSize = new Vector2(windowWidth, windowHeight);
  85. wnd.maxSize = new Vector2(windowWidth, windowHeight);
  86. wnd.Init();
  87. }
  88. int pipelineType = -1;
  89. string assetPath;
  90. bool pipelineSetupDone = false;
  91. GUIStyle titleStyle;
  92. GUIStyle greenStyle;
  93. GUIStyle redStyle;
  94. Texture2D fxvLogo;
  95. public void Init()
  96. {
  97. var g = AssetDatabase.FindAssets($"t:Script {nameof(fxvIntroWindow)}");
  98. string scriptPath = null;
  99. for (int i = 0; i < g.Length; i++)
  100. {
  101. string p = AssetDatabase.GUIDToAssetPath(g[i]);
  102. if (p.Contains("fxvIntroWindow.cs"))
  103. {
  104. scriptPath = p;
  105. break;
  106. }
  107. }
  108. assetPath = Path.GetDirectoryName(scriptPath);
  109. assetPath = Path.GetDirectoryName(assetPath);
  110. titleStyle = new GUIStyle();
  111. titleStyle.normal.textColor = new Color(0.6f, 0.8f, 1.0f, 1.0f);
  112. titleStyle.fontSize = 20;
  113. titleStyle.fontStyle = FontStyle.Bold;
  114. redStyle = new GUIStyle();
  115. redStyle.normal.textColor = new Color(0.9f, 0.9f, 0.4f, 1.0f);
  116. greenStyle = new GUIStyle();
  117. greenStyle.normal.textColor = new Color(0.4f, 0.9f, 0.4f, 1.0f);
  118. fxvLogo = (Texture2D)Resources.Load("FXVFogCardImg", typeof(Texture2D));
  119. }
  120. public void OnGUI()
  121. {
  122. if (assetPath == null || assetPath.Length == 0)
  123. {
  124. Init();
  125. }
  126. GUILayout.BeginHorizontal();
  127. GUILayout.Box(fxvLogo);
  128. GUILayout.BeginVertical();
  129. GUILayout.Label(version);
  130. GUILayout.Space(4);
  131. GUILayout.Label(" Thank you for purchasing \n Fast Volumetric Area Fog asset !!!", titleStyle);
  132. #if UNITY_2021_3_OR_NEWER
  133. #else
  134. GUILayout.Label("WARRNING - Your unity version (" + Application.unityVersion + ") is older than supported (2021.3.31f1+).\nPlease update to LTS version for maximum compatibility.", redStyle);
  135. #endif
  136. if (GUILayout.Button("fx.valley.contact@gmail.com", GUILayout.Width(buttonWidth * 2.0f)))
  137. {
  138. Application.OpenURL("mailto:fx.valley.contact@gmail.com");
  139. }
  140. if (GUILayout.Button("Join Discord", GUILayout.Width(buttonWidth * 2.0f)))
  141. {
  142. Application.OpenURL("https://discord.gg/3ssjcBcgpu");
  143. }
  144. if (GUILayout.Button("Leave Review on Asset Page", GUILayout.Width(buttonWidth * 2.0f)))
  145. {
  146. Application.OpenURL("https://assetstore.unity.com/packages/slug/123912");
  147. }
  148. GUILayout.Label("Below you can find configuration tips based on pipeline your project uses.");
  149. GUILayout.EndVertical();
  150. GUILayout.EndHorizontal();
  151. if (pipelineType == 0)
  152. {
  153. GUIBuiltIn();
  154. }
  155. else if (pipelineType == 1)
  156. {
  157. GUIURP();
  158. }
  159. else if (pipelineType == 2)
  160. {
  161. GUIHDRP();
  162. }
  163. }
  164. public static void GUILine(Color color, int thickness = 2, int padding = 10)
  165. {
  166. Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
  167. r.height = thickness;
  168. r.y += padding / 2;
  169. r.x -= 2;
  170. r.width += 6;
  171. EditorGUI.DrawRect(r, color);
  172. }
  173. void GUIBuiltIn()
  174. {
  175. GUILayout.Space(5);
  176. GUILayout.Space(5);
  177. bool builtinUnpacked = false;
  178. if (File.Exists(assetPath + "/BuiltIn/Shaders/FXVVolumeFogLit.shader"))
  179. {
  180. builtinUnpacked = true;
  181. var type = this.GetType();
  182. var fieldInfo = type.GetField("builtInVersion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
  183. if (fieldInfo == null || (string)fieldInfo.GetValue(this) != version)
  184. {
  185. builtinUnpacked = false;
  186. }
  187. }
  188. if (!builtinUnpacked)
  189. {
  190. GUILine(Color.gray);
  191. GUILayout.BeginHorizontal();
  192. {
  193. GUILayout.Label(" Import BuiltIn Render Pipeline fog asset package.", redStyle);
  194. if (GUILayout.Button("Show package", GUILayout.Width(buttonWidth)))
  195. {
  196. Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(assetPath + "/InstallBuiltIn.unitypackage");
  197. }
  198. if (GUILayout.Button("Import", GUILayout.Width(buttonWidth)))
  199. {
  200. AssetDatabase.ImportPackage(assetPath + "/InstallBuiltIn.unitypackage", true);
  201. }
  202. }
  203. GUILayout.EndHorizontal();
  204. }
  205. else
  206. {
  207. var type = this.GetType();
  208. if (!pipelineSetupDone)
  209. {
  210. var initMethod = type.GetMethod("Setup_BuiltIn_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  211. if (initMethod != null)
  212. {
  213. initMethod.Invoke(this, null);
  214. }
  215. pipelineSetupDone = true;
  216. }
  217. var method = type.GetMethod("GUI_BuiltIn_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  218. if (method != null)
  219. {
  220. method.Invoke(this, null);
  221. }
  222. }
  223. }
  224. void GUIURP()
  225. {
  226. GUILayout.Space(5);
  227. bool urpUnpacked = false;
  228. if (File.Exists(assetPath + "/URP/Shaders/FXVVolumetricFogLitURP.shader"))
  229. {
  230. urpUnpacked = true;
  231. var type = this.GetType();
  232. var fieldInfo = type.GetField("urpVersion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
  233. if (fieldInfo == null || (string)fieldInfo.GetValue(this) != version)
  234. {
  235. urpUnpacked = false;
  236. }
  237. }
  238. if (!urpUnpacked)
  239. {
  240. GUILine(Color.gray);
  241. GUILayout.BeginHorizontal();
  242. {
  243. GUILayout.Label(" Import URP fog asset package.", redStyle);
  244. if (GUILayout.Button("Show package", GUILayout.Width(buttonWidth)))
  245. {
  246. Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(assetPath + "/InstallURP.unitypackage");
  247. }
  248. if (GUILayout.Button("Import", GUILayout.Width(buttonWidth)))
  249. {
  250. AssetDatabase.ImportPackage(assetPath + "/InstallURP.unitypackage", true);
  251. }
  252. }
  253. GUILayout.EndHorizontal();
  254. }
  255. else
  256. {
  257. var type = this.GetType();
  258. if (!pipelineSetupDone)
  259. {
  260. var initMethod = type.GetMethod("Setup_URP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  261. if (initMethod != null)
  262. {
  263. initMethod.Invoke(this, null);
  264. }
  265. pipelineSetupDone = true;
  266. }
  267. var method = type.GetMethod("GUI_URP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  268. if (method != null)
  269. {
  270. method.Invoke(this, null);
  271. }
  272. }
  273. }
  274. void GUIHDRP()
  275. {
  276. GUILayout.Space(5);
  277. bool hdrpUnpacked = false;
  278. if (File.Exists(assetPath + "/HDRP/Shaders/FXVVolumetricFogLitHDRP.shader"))
  279. {
  280. hdrpUnpacked = true;
  281. }
  282. if (!hdrpUnpacked)
  283. {
  284. GUILine(Color.gray);
  285. GUILayout.BeginHorizontal();
  286. {
  287. GUILayout.Label(" Sorry but HDRP is not supported at the moment.", redStyle);
  288. GUILayout.Label(" It's planned to be added in the future update.", redStyle);
  289. /* GUILayout.Label(" Import HDRP fog asset package.", redStyle);
  290. if (GUILayout.Button("Show package", GUILayout.Width(buttonWidth)))
  291. {
  292. Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(assetPath + "/InstallHDRP.unitypackage");
  293. }
  294. if (GUILayout.Button("Import", GUILayout.Width(buttonWidth)))
  295. {
  296. AssetDatabase.ImportPackage(assetPath + "/InstallHDRP.unitypackage", true);
  297. }*/
  298. }
  299. GUILayout.EndHorizontal();
  300. }
  301. else
  302. {
  303. var type = this.GetType();
  304. if (!pipelineSetupDone)
  305. {
  306. var initMethod = type.GetMethod("Setup_HDRP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  307. if (initMethod != null)
  308. {
  309. initMethod.Invoke(this, null);
  310. }
  311. pipelineSetupDone = true;
  312. }
  313. var method = type.GetMethod("GUI_HDRP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
  314. if (method != null)
  315. {
  316. method.Invoke(this, null);
  317. }
  318. }
  319. }
  320. }
  321. }