123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.Rendering;
- namespace FXV.VolumetricFogEditorUtils
- {
- internal class fxvAssetPostprocess : AssetPostprocessor
- {
- private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload)
- {
- foreach (string str in importedAssets)
- {
- #if FX_DEBUG_LOGS
- Debug.Log("Reimported Asset: " + str);
- #endif
- if (str.Contains("fxvIntroWindow"))
- {
- fxvIntroWindow.ShowPipelineIntro();
- return;
- }
- }
- }
- }
- public partial class fxvIntroWindow : EditorWindow
- {
- static string version = "version 1.0.11";
- static int windowWidth = 700;
- static int windowHeight = 400;
- static int buttonWidth = 100;
- [MenuItem("Window/FXV/VolumetricFog/Intro")]
- public static void ShowPipelineIntro()
- {
- var currentRP = GraphicsSettings.currentRenderPipeline;
- if (currentRP == null)
- {
- ShowIntroWindowBuiltIn();
- return;
- }
- var curPipeline = currentRP.GetType().ToString().ToLower();
- if (curPipeline.Contains("universal"))
- {
- ShowIntroWindowURP();
- }
- else if (curPipeline.Contains("high definition") || curPipeline.Contains("highdefinition"))
- {
- ShowIntroWindowHDRP();
- }
- }
- public static void ShowIntroWindowBuiltIn()
- {
- #if FX_DEBUG_LOGS
- Debug.Log("FXV.Shield ShowIntroWindow");
- #endif
- fxvIntroWindow wnd = GetWindow<fxvIntroWindow>();
- wnd.titleContent = new GUIContent("Welcome Built In");
- wnd.pipelineType = 0;
- wnd.minSize = new Vector2(windowWidth, windowHeight);
- wnd.maxSize = new Vector2(windowWidth, windowHeight);
- wnd.Init();
- }
- public static void ShowIntroWindowURP()
- {
- #if FX_DEBUG_LOGS
- Debug.Log("FXV.Shield ShowIntroWindow");
- #endif
- fxvIntroWindow wnd = GetWindow<fxvIntroWindow>();
- wnd.titleContent = new GUIContent("Welcome URP");
- wnd.pipelineType = 1;
- wnd.minSize = new Vector2(windowWidth, windowHeight);
- wnd.maxSize = new Vector2(windowWidth, windowHeight);
- wnd.Init();
- }
- public static void ShowIntroWindowHDRP()
- {
- #if FX_DEBUG_LOGS
- Debug.Log("FXV.Shield ShowIntroWindow");
- #endif
- fxvIntroWindow wnd = GetWindow<fxvIntroWindow>();
- wnd.titleContent = new GUIContent("Welcome HDRP");
- wnd.pipelineType = 2;
- wnd.minSize = new Vector2(windowWidth, windowHeight);
- wnd.maxSize = new Vector2(windowWidth, windowHeight);
- wnd.Init();
- }
- int pipelineType = -1;
- string assetPath;
- bool pipelineSetupDone = false;
- GUIStyle titleStyle;
- GUIStyle greenStyle;
- GUIStyle redStyle;
- Texture2D fxvLogo;
- public void Init()
- {
- var g = AssetDatabase.FindAssets($"t:Script {nameof(fxvIntroWindow)}");
- string scriptPath = null;
- for (int i = 0; i < g.Length; i++)
- {
- string p = AssetDatabase.GUIDToAssetPath(g[i]);
- if (p.Contains("fxvIntroWindow.cs"))
- {
- scriptPath = p;
- break;
- }
- }
- assetPath = Path.GetDirectoryName(scriptPath);
- assetPath = Path.GetDirectoryName(assetPath);
- titleStyle = new GUIStyle();
- titleStyle.normal.textColor = new Color(0.6f, 0.8f, 1.0f, 1.0f);
- titleStyle.fontSize = 20;
- titleStyle.fontStyle = FontStyle.Bold;
- redStyle = new GUIStyle();
- redStyle.normal.textColor = new Color(0.9f, 0.9f, 0.4f, 1.0f);
- greenStyle = new GUIStyle();
- greenStyle.normal.textColor = new Color(0.4f, 0.9f, 0.4f, 1.0f);
- fxvLogo = (Texture2D)Resources.Load("FXVFogCardImg", typeof(Texture2D));
- }
- public void OnGUI()
- {
- if (assetPath == null || assetPath.Length == 0)
- {
- Init();
- }
- GUILayout.BeginHorizontal();
- GUILayout.Box(fxvLogo);
- GUILayout.BeginVertical();
- GUILayout.Label(version);
- GUILayout.Space(4);
- GUILayout.Label(" Thank you for purchasing \n Fast Volumetric Area Fog asset !!!", titleStyle);
- #if UNITY_2021_3_OR_NEWER
- #else
- GUILayout.Label("WARRNING - Your unity version (" + Application.unityVersion + ") is older than supported (2021.3.31f1+).\nPlease update to LTS version for maximum compatibility.", redStyle);
- #endif
- if (GUILayout.Button("fx.valley.contact@gmail.com", GUILayout.Width(buttonWidth * 2.0f)))
- {
- Application.OpenURL("mailto:fx.valley.contact@gmail.com");
- }
- if (GUILayout.Button("Join Discord", GUILayout.Width(buttonWidth * 2.0f)))
- {
- Application.OpenURL("https://discord.gg/3ssjcBcgpu");
- }
- if (GUILayout.Button("Leave Review on Asset Page", GUILayout.Width(buttonWidth * 2.0f)))
- {
- Application.OpenURL("https://assetstore.unity.com/packages/slug/123912");
- }
- GUILayout.Label("Below you can find configuration tips based on pipeline your project uses.");
- GUILayout.EndVertical();
- GUILayout.EndHorizontal();
- if (pipelineType == 0)
- {
- GUIBuiltIn();
- }
- else if (pipelineType == 1)
- {
- GUIURP();
- }
- else if (pipelineType == 2)
- {
- GUIHDRP();
- }
- }
- public static void GUILine(Color color, int thickness = 2, int padding = 10)
- {
- Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
- r.height = thickness;
- r.y += padding / 2;
- r.x -= 2;
- r.width += 6;
- EditorGUI.DrawRect(r, color);
- }
- void GUIBuiltIn()
- {
- GUILayout.Space(5);
- GUILayout.Space(5);
- bool builtinUnpacked = false;
- if (File.Exists(assetPath + "/BuiltIn/Shaders/FXVVolumeFogLit.shader"))
- {
- builtinUnpacked = true;
- var type = this.GetType();
- var fieldInfo = type.GetField("builtInVersion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
- if (fieldInfo == null || (string)fieldInfo.GetValue(this) != version)
- {
- builtinUnpacked = false;
- }
- }
- if (!builtinUnpacked)
- {
- GUILine(Color.gray);
- GUILayout.BeginHorizontal();
- {
- GUILayout.Label(" Import BuiltIn Render Pipeline fog asset package.", redStyle);
- if (GUILayout.Button("Show package", GUILayout.Width(buttonWidth)))
- {
- Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(assetPath + "/InstallBuiltIn.unitypackage");
- }
- if (GUILayout.Button("Import", GUILayout.Width(buttonWidth)))
- {
- AssetDatabase.ImportPackage(assetPath + "/InstallBuiltIn.unitypackage", true);
- }
- }
- GUILayout.EndHorizontal();
- }
- else
- {
- var type = this.GetType();
- if (!pipelineSetupDone)
- {
- var initMethod = type.GetMethod("Setup_BuiltIn_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
- if (initMethod != null)
- {
- initMethod.Invoke(this, null);
- }
- pipelineSetupDone = true;
- }
- var method = type.GetMethod("GUI_BuiltIn_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
- if (method != null)
- {
- method.Invoke(this, null);
- }
- }
- }
- void GUIURP()
- {
- GUILayout.Space(5);
- bool urpUnpacked = false;
- if (File.Exists(assetPath + "/URP/Shaders/FXVVolumetricFogLitURP.shader"))
- {
- urpUnpacked = true;
- var type = this.GetType();
- var fieldInfo = type.GetField("urpVersion", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
- if (fieldInfo == null || (string)fieldInfo.GetValue(this) != version)
- {
- urpUnpacked = false;
- }
- }
- if (!urpUnpacked)
- {
- GUILine(Color.gray);
- GUILayout.BeginHorizontal();
- {
- GUILayout.Label(" Import URP fog asset package.", redStyle);
- if (GUILayout.Button("Show package", GUILayout.Width(buttonWidth)))
- {
- Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(assetPath + "/InstallURP.unitypackage");
- }
- if (GUILayout.Button("Import", GUILayout.Width(buttonWidth)))
- {
- AssetDatabase.ImportPackage(assetPath + "/InstallURP.unitypackage", true);
- }
- }
- GUILayout.EndHorizontal();
- }
- else
- {
- var type = this.GetType();
- if (!pipelineSetupDone)
- {
- var initMethod = type.GetMethod("Setup_URP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
- if (initMethod != null)
- {
- initMethod.Invoke(this, null);
- }
- pipelineSetupDone = true;
- }
- var method = type.GetMethod("GUI_URP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
- if (method != null)
- {
- method.Invoke(this, null);
- }
- }
- }
- void GUIHDRP()
- {
- GUILayout.Space(5);
- bool hdrpUnpacked = false;
- if (File.Exists(assetPath + "/HDRP/Shaders/FXVVolumetricFogLitHDRP.shader"))
- {
- hdrpUnpacked = true;
- }
- if (!hdrpUnpacked)
- {
- GUILine(Color.gray);
- GUILayout.BeginHorizontal();
- {
- GUILayout.Label(" Sorry but HDRP is not supported at the moment.", redStyle);
- GUILayout.Label(" It's planned to be added in the future update.", redStyle);
- /* GUILayout.Label(" Import HDRP fog asset package.", redStyle);
- if (GUILayout.Button("Show package", GUILayout.Width(buttonWidth)))
- {
- Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(assetPath + "/InstallHDRP.unitypackage");
- }
- if (GUILayout.Button("Import", GUILayout.Width(buttonWidth)))
- {
- AssetDatabase.ImportPackage(assetPath + "/InstallHDRP.unitypackage", true);
- }*/
- }
- GUILayout.EndHorizontal();
- }
- else
- {
- var type = this.GetType();
- if (!pipelineSetupDone)
- {
- var initMethod = type.GetMethod("Setup_HDRP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
- if (initMethod != null)
- {
- initMethod.Invoke(this, null);
- }
- pipelineSetupDone = true;
- }
- var method = type.GetMethod("GUI_HDRP_AfterImport", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
- if (method != null)
- {
- method.Invoke(this, null);
- }
- }
- }
- }
- }
|