备份CatanBuilding瘦身独立工程
This commit is contained in:
431
LocalPackages/StylizedWater2/Editor/AssetInfo.cs
Normal file
431
LocalPackages/StylizedWater2/Editor/AssetInfo.cs
Normal file
@@ -0,0 +1,431 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
|
||||
using UnityEngine;
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
public class AssetInfo
|
||||
{
|
||||
private const string THIS_FILE_GUID = "d5972a1c9cddd9941aec37a3343647aa";
|
||||
|
||||
public const string ASSET_NAME = "Stylized Water 2";
|
||||
public const string ASSET_ID = "170386";
|
||||
public const string ASSET_ABRV = "SW2";
|
||||
|
||||
public const string INSTALLED_VERSION = "1.6.0";
|
||||
|
||||
public const int SHADER_GENERATOR_VERSION_MAJOR = 1;
|
||||
public const int SHADER_GENERATOR_MINOR = 2;
|
||||
public const int SHADER_GENERATOR_PATCH = 0;
|
||||
|
||||
public const string MIN_UNITY_VERSION = "2021.3.16f1";
|
||||
public const string MIN_URP_VERSION = "12.1.6";
|
||||
|
||||
private const string VERSION_FETCH_URL = "http://www.staggart.xyz/backend/versions/stylizedwater2.php";
|
||||
public const string DOC_URL = "http://staggart.xyz/unity/stylized-water-2/sws-2-docs/";
|
||||
public const string FORUM_URL = "https://forum.unity.com/threads/999132/";
|
||||
public const string EMAIL_URL = "mailto:contact@staggart.xyz?subject=Stylized Water 2";
|
||||
|
||||
public static bool IS_UPDATED = true;
|
||||
public static bool supportedVersion = true;
|
||||
public static bool compatibleVersion = true;
|
||||
public static bool alphaVersion = false;
|
||||
|
||||
#if !URP //Enabled when com.unity.render-pipelines.universal is below MIN_URP_VERSION
|
||||
[InitializeOnLoad]
|
||||
sealed class PackageInstaller : Editor
|
||||
{
|
||||
[InitializeOnLoadMethod]
|
||||
public static void Initialize()
|
||||
{
|
||||
GetLatestCompatibleURPVersion();
|
||||
|
||||
if (EditorUtility.DisplayDialog(ASSET_NAME + " v" + INSTALLED_VERSION, "This package requires the Universal Render Pipeline " + MIN_URP_VERSION + " or newer, would you like to install or update it now?", "OK", "Later"))
|
||||
{
|
||||
Debug.Log("Universal Render Pipeline <b>v" + lastestURPVersion + "</b> will start installing in a moment. Please refer to the URP documentation for set up instructions");
|
||||
|
||||
InstallURP();
|
||||
}
|
||||
}
|
||||
|
||||
private static PackageInfo urpPackage;
|
||||
|
||||
private static string lastestURPVersion;
|
||||
|
||||
#if SWS_DEV
|
||||
[MenuItem("SWS/Get latest URP version")]
|
||||
#endif
|
||||
private static void GetLatestCompatibleURPVersion()
|
||||
{
|
||||
if(urpPackage == null) urpPackage = GetURPPackage();
|
||||
if(urpPackage == null) return;
|
||||
|
||||
lastestURPVersion = urpPackage.versions.latestCompatible;
|
||||
|
||||
#if SWS_DEV
|
||||
Debug.Log("Latest compatible URP version: " + lastestURPVersion);
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void InstallURP()
|
||||
{
|
||||
if(urpPackage == null) urpPackage = GetURPPackage();
|
||||
if(urpPackage == null) return;
|
||||
|
||||
lastestURPVersion = urpPackage.versions.latestCompatible;
|
||||
|
||||
AddRequest addRequest = Client.Add(URP_PACKAGE_ID + "@" + lastestURPVersion);
|
||||
|
||||
//Update Core and Shader Graph packages as well, doesn't always happen automatically
|
||||
for (int i = 0; i < urpPackage.dependencies.Length; i++)
|
||||
{
|
||||
#if SWS_DEV
|
||||
Debug.Log("Updating URP dependency <i>" + urpPackage.dependencies[i].name + "</i> to " + urpPackage.dependencies[i].version);
|
||||
#endif
|
||||
addRequest = Client.Add(urpPackage.dependencies[i].name + "@" + urpPackage.dependencies[i].version);
|
||||
}
|
||||
|
||||
//Wait until finished
|
||||
while(!addRequest.IsCompleted || addRequest.Status == StatusCode.InProgress) { }
|
||||
|
||||
WaterShaderImporter.ReimportAll();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public const string URP_PACKAGE_ID = "com.unity.render-pipelines.universal";
|
||||
|
||||
public static PackageInfo GetURPPackage()
|
||||
{
|
||||
SearchRequest request = Client.Search(URP_PACKAGE_ID);
|
||||
|
||||
while (request.Status == StatusCode.InProgress) { /* Waiting... */ }
|
||||
|
||||
if (request.Status == StatusCode.Failure)
|
||||
{
|
||||
Debug.LogError("Failed to retrieve URP package from Package Manager...");
|
||||
return null;
|
||||
}
|
||||
|
||||
return request.Result[0];
|
||||
}
|
||||
|
||||
//Sorry, as much as I hate to intrude on an entire project, this is the only way in Unity to track importing or updating an asset
|
||||
public class ImportOrUpdateAsset : AssetPostprocessor
|
||||
{
|
||||
private static bool OldShadersPresent()
|
||||
{
|
||||
return Shader.Find("Universal Render Pipeline/FX/Stylized Water 2") || Shader.Find("Hidden/StylizedWater2/Deleted");
|
||||
}
|
||||
|
||||
private void OnPreprocessAsset()
|
||||
{
|
||||
var oldShaders = false;
|
||||
//Importing/updating the Stylized Water 2 asset
|
||||
if (assetPath.EndsWith("StylizedWater2/Editor/AssetInfo.cs") || assetPath.EndsWith("sc.stylizedwater2/Editor/AssetInfo.cs"))
|
||||
{
|
||||
oldShaders = OldShadersPresent();
|
||||
}
|
||||
//These files change every version, so will trigger when updating or importing the first time
|
||||
if (
|
||||
//Importing the Underwater Rendering extension
|
||||
assetPath.EndsWith("UnderwaterRenderer.cs"))
|
||||
//Any further extensions...
|
||||
{
|
||||
OnImportExtension("Underwater Rendering");
|
||||
|
||||
oldShaders = OldShadersPresent();
|
||||
}
|
||||
|
||||
if (assetPath.EndsWith("WaterDynamicEffectsRenderFeature.cs"))
|
||||
{
|
||||
OnImportExtension("Dynamic Effects");
|
||||
}
|
||||
|
||||
if (oldShaders)
|
||||
{
|
||||
//Old non-templated shader(s) still present.
|
||||
if (EditorUtility.DisplayDialog(AssetInfo.ASSET_NAME, "Updating to v1.4.0+. Obsolete shader files were detected." +
|
||||
"\n\n" +
|
||||
"The water shader(s) are a now C# generated, thus has moved to a different file." +
|
||||
"\n\n" +
|
||||
"Materials in your project using the old shader must switch to it." +
|
||||
"\n\n" +
|
||||
"This process is automatic. The obsolete files will also be deleted." +
|
||||
"\n\n" +
|
||||
"Rest assured, no settings or functionality will be lost!", "OK", "Cancel"))
|
||||
{
|
||||
UpgradeMaterials();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnImportExtension(string name)
|
||||
{
|
||||
Debug.Log($"[Stylized Water 2] {name} extension installed/deleted or updated. Reimporting water shader(s) to toggle integration.");
|
||||
|
||||
//Re-import any .watershader files, since these depend on the installation state of extensions
|
||||
WaterShaderImporter.ReimportAll();
|
||||
}
|
||||
}
|
||||
|
||||
#if SWS_DEV
|
||||
[MenuItem("SWS/Upgrading/Upgrade materials to 1.4.0+")]
|
||||
#endif
|
||||
private static void UpgradeMaterials()
|
||||
{
|
||||
Shader oldShader = Shader.Find("Universal Render Pipeline/FX/Stylized Water 2");
|
||||
Shader oldShaderTess = Shader.Find("Universal Render Pipeline/FX/Stylized Water 2 (Tessellation)");
|
||||
|
||||
Shader newShader = Shader.Find("Stylized Water 2/Standard");
|
||||
Shader newShaderTess = Shader.Find("Stylized Water 2/Standard (Tessellation)");
|
||||
|
||||
int upgradedMaterialCount = 0;
|
||||
|
||||
//Possible the script imported before the water shader even did
|
||||
//Or the water shader was already deleted, yet this function is triggered by an old underwater-rendering shader.
|
||||
if (newShader != null || oldShader != null)
|
||||
{
|
||||
string[] materials = AssetDatabase.FindAssets("t: Material");
|
||||
|
||||
int totalMaterials = materials.Length;
|
||||
|
||||
for (int i = 0; i < totalMaterials; i++)
|
||||
{
|
||||
Material mat = AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath(materials[i]));
|
||||
|
||||
EditorUtility.DisplayProgressBar(ASSET_NAME, $"Checking \"{mat.name}\" ({i}/{totalMaterials})", (float)i / (float)totalMaterials);
|
||||
|
||||
if (mat.shader == oldShader)
|
||||
{
|
||||
int queue = mat.renderQueue;
|
||||
mat.shader = newShader;
|
||||
mat.renderQueue = queue;
|
||||
EditorUtility.SetDirty(mat);
|
||||
upgradedMaterialCount++;
|
||||
}
|
||||
|
||||
if (mat.shader == oldShaderTess)
|
||||
{
|
||||
int queue = mat.renderQueue;
|
||||
mat.shader = newShaderTess;
|
||||
mat.renderQueue = queue;
|
||||
|
||||
EditorUtility.SetDirty(mat);
|
||||
upgradedMaterialCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorUtility.ClearProgressBar();
|
||||
|
||||
List<string> deletedFiles = new List<string>();
|
||||
//Delete old files
|
||||
{
|
||||
void DeleteFile(string path)
|
||||
{
|
||||
if (path != string.Empty)
|
||||
{
|
||||
deletedFiles.Add(path);
|
||||
AssetDatabase.DeleteAsset(path);
|
||||
}
|
||||
}
|
||||
|
||||
DeleteFile(AssetDatabase.GetAssetPath(oldShader));
|
||||
DeleteFile(AssetDatabase.GetAssetPath(oldShaderTess));
|
||||
|
||||
//UnderwaterMask.shader
|
||||
DeleteFile(AssetDatabase.GUIDToAssetPath("85caab243c23a1e489cd0bdcaf742560"));
|
||||
|
||||
//UnderwaterShading.shader
|
||||
DeleteFile(AssetDatabase.GUIDToAssetPath("33652c9d694d8004bb649164aafc9ecc"));
|
||||
|
||||
//Waterline.shader
|
||||
DeleteFile(AssetDatabase.GUIDToAssetPath("aef8d53c098c94044b72ea6bda9bb6bc"));
|
||||
|
||||
//UnderwaterPost.shader
|
||||
DeleteFile(AssetDatabase.GUIDToAssetPath("7b53b35c69174ce092d2712e3db77f0e"));
|
||||
}
|
||||
|
||||
if (upgradedMaterialCount > 0 || deletedFiles.Count > 0)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog(AssetInfo.ASSET_NAME, $"Converted {upgradedMaterialCount} materials to use the new water shader." +
|
||||
$"\n\nObsolete shader files ({deletedFiles.Count}) deleted:\n\n" +
|
||||
String.Join(Environment.NewLine, deletedFiles),
|
||||
"OK")) { }
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
Debug.Log("<b>[Stylized Water 2]</b> Upgrade of materials and project complete!");
|
||||
}
|
||||
|
||||
public static bool MeetsMinimumVersion(string versionMinimum)
|
||||
{
|
||||
Version curVersion = new Version(INSTALLED_VERSION);
|
||||
Version minVersion = new Version(versionMinimum);
|
||||
|
||||
return curVersion >= minVersion;
|
||||
}
|
||||
|
||||
public static void OpenAssetStore(string url = null)
|
||||
{
|
||||
if (url == string.Empty) url = "https://assetstore.unity.com/packages/slug/" + ASSET_ID;
|
||||
|
||||
Application.OpenURL(url + "?aid=1011l7Uk8&pubref=sw2editor");
|
||||
}
|
||||
|
||||
public static void OpenReviewsPage()
|
||||
{
|
||||
Application.OpenURL($"https://assetstore.unity.com/packages/slug/{ASSET_ID}?aid=1011l7Uk8&pubref=sw2editor#reviews");
|
||||
}
|
||||
|
||||
public static void OpenInPackageManager()
|
||||
{
|
||||
Application.OpenURL("com.unity3d.kharma:content/" + ASSET_ID);
|
||||
}
|
||||
|
||||
public static void OpenForumPage()
|
||||
{
|
||||
Application.OpenURL(FORUM_URL + "/page-999");
|
||||
}
|
||||
|
||||
public static string GetRootFolder()
|
||||
{
|
||||
//Get script path
|
||||
string scriptFilePath = AssetDatabase.GUIDToAssetPath(THIS_FILE_GUID);
|
||||
|
||||
//Truncate to get relative path
|
||||
string rootFolder = scriptFilePath.Replace("Editor/AssetInfo.cs", string.Empty);
|
||||
|
||||
#if SWS_DEV
|
||||
//Debug.Log("<b>Package root</b> " + rootFolder);
|
||||
#endif
|
||||
|
||||
return rootFolder;
|
||||
}
|
||||
|
||||
public static class VersionChecking
|
||||
{
|
||||
public static string GetUnityVersion()
|
||||
{
|
||||
string version = UnityEditorInternal.InternalEditorUtility.GetFullUnityVersion();
|
||||
|
||||
//Remove GUID in parenthesis
|
||||
return version.Substring(0, version.LastIndexOf(" ("));
|
||||
}
|
||||
|
||||
public static void CheckUnityVersion()
|
||||
{
|
||||
#if !UNITY_2020_3_OR_NEWER
|
||||
compatibleVersion = false;
|
||||
#endif
|
||||
|
||||
#if !UNITY_2021_3_OR_NEWER
|
||||
supportedVersion = false;
|
||||
#endif
|
||||
|
||||
alphaVersion = GetUnityVersion().Contains("f") == false;
|
||||
}
|
||||
|
||||
public static string fetchedVersionString;
|
||||
public static System.Version fetchedVersion;
|
||||
private static bool showPopup;
|
||||
|
||||
public enum VersionStatus
|
||||
{
|
||||
UpToDate,
|
||||
Outdated
|
||||
}
|
||||
|
||||
public enum QueryStatus
|
||||
{
|
||||
Fetching,
|
||||
Completed,
|
||||
Failed
|
||||
}
|
||||
public static QueryStatus queryStatus = QueryStatus.Completed;
|
||||
|
||||
#if SWS_DEV
|
||||
[MenuItem("SWS/Check for update")]
|
||||
#endif
|
||||
public static void GetLatestVersionPopup()
|
||||
{
|
||||
CheckForUpdate(true);
|
||||
}
|
||||
|
||||
private static int VersionStringToInt(string input)
|
||||
{
|
||||
//Remove all non-alphanumeric characters from version
|
||||
input = input.Replace(".", string.Empty);
|
||||
input = input.Replace(" BETA", string.Empty);
|
||||
return int.Parse(input, System.Globalization.NumberStyles.Any);
|
||||
}
|
||||
|
||||
public static void CheckForUpdate(bool showPopup = false)
|
||||
{
|
||||
VersionChecking.showPopup = showPopup;
|
||||
|
||||
queryStatus = QueryStatus.Fetching;
|
||||
|
||||
using (WebClient webClient = new WebClient())
|
||||
{
|
||||
webClient.DownloadStringCompleted += new System.Net.DownloadStringCompletedEventHandler(OnRetrievedServerVersion);
|
||||
webClient.DownloadStringAsync(new System.Uri(VERSION_FETCH_URL), fetchedVersionString);
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnRetrievedServerVersion(object sender, DownloadStringCompletedEventArgs e)
|
||||
{
|
||||
if (e.Error == null && !e.Cancelled)
|
||||
{
|
||||
fetchedVersionString = e.Result;
|
||||
fetchedVersion = new System.Version(fetchedVersionString);
|
||||
System.Version installedVersion = new System.Version(INSTALLED_VERSION);
|
||||
|
||||
//Success
|
||||
IS_UPDATED = (installedVersion >= fetchedVersion) ? true : false;
|
||||
|
||||
#if SWS_DEV
|
||||
Debug.Log("<b>PackageVersionCheck</b> Up-to-date = " + IS_UPDATED + " (Installed:" + INSTALLED_VERSION + ") (Remote:" + fetchedVersionString + ")");
|
||||
#endif
|
||||
|
||||
queryStatus = QueryStatus.Completed;
|
||||
|
||||
if (VersionChecking.showPopup)
|
||||
{
|
||||
if (!IS_UPDATED)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog(ASSET_NAME + ", version " + INSTALLED_VERSION, "An updated version is available: " + fetchedVersionString, "Open Package Manager", "Close"))
|
||||
{
|
||||
OpenInPackageManager();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EditorUtility.DisplayDialog(ASSET_NAME + ", version " + INSTALLED_VERSION, "Installed version is up-to-date!", "Close")) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[" + ASSET_NAME + "] Contacting update server failed: " + e.Error.Message);
|
||||
queryStatus = QueryStatus.Failed;
|
||||
|
||||
//When failed, assume installation is up-to-date
|
||||
IS_UPDATED = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
LocalPackages/StylizedWater2/Editor/AssetInfo.cs.meta
Normal file
11
LocalPackages/StylizedWater2/Editor/AssetInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5972a1c9cddd9941aec37a3343647aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
686
LocalPackages/StylizedWater2/Editor/HelpWindow.cs
Normal file
686
LocalPackages/StylizedWater2/Editor/HelpWindow.cs
Normal file
File diff suppressed because one or more lines are too long
11
LocalPackages/StylizedWater2/Editor/HelpWindow.cs.meta
Normal file
11
LocalPackages/StylizedWater2/Editor/HelpWindow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9423877ce002b024984ae85461230da7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
LocalPackages/StylizedWater2/Editor/Inspectors.meta
Normal file
3
LocalPackages/StylizedWater2/Editor/Inspectors.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb0cf80ddc794103bd55d6c1d2b088a0
|
||||
timeCreated: 1701083972
|
||||
@@ -0,0 +1,262 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
using PrefabStageUtility = UnityEditor.SceneManagement.PrefabStageUtility;
|
||||
#else
|
||||
using PrefabStageUtility = UnityEditor.Experimental.SceneManagement.PrefabStageUtility;
|
||||
#endif
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(AlignToWaves))]
|
||||
public class AlignToWavesInspector : Editor
|
||||
{
|
||||
AlignToWaves script;
|
||||
|
||||
SerializedProperty waterObject;
|
||||
SerializedProperty autoFind;
|
||||
SerializedProperty dynamicMaterial;
|
||||
SerializedProperty waterLevelSource;
|
||||
SerializedProperty waterLevel;
|
||||
SerializedProperty childTransform;
|
||||
|
||||
SerializedProperty heightOffset;
|
||||
SerializedProperty rollAmount;
|
||||
|
||||
SerializedProperty samples;
|
||||
|
||||
private bool editSamples;
|
||||
private bool isRiver;
|
||||
private bool wavesEnabled;
|
||||
|
||||
private string proSkinPrefix => EditorGUIUtility.isProSkin ? "d_" : "";
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
script = (AlignToWaves)target;
|
||||
|
||||
waterObject = serializedObject.FindProperty("waterObject");
|
||||
autoFind = serializedObject.FindProperty("autoFind");
|
||||
dynamicMaterial = serializedObject.FindProperty("dynamicMaterial");
|
||||
waterLevelSource = serializedObject.FindProperty("waterLevelSource");
|
||||
waterLevel = serializedObject.FindProperty("waterLevel");
|
||||
childTransform = serializedObject.FindProperty("childTransform");
|
||||
heightOffset = serializedObject.FindProperty("heightOffset");
|
||||
rollAmount = serializedObject.FindProperty("rollAmount");
|
||||
samples = serializedObject.FindProperty("samples");
|
||||
|
||||
//Auto fetch if there is only one water body in the scene
|
||||
if (waterObject.objectReferenceValue == null && WaterObject.Instances.Count == 1)
|
||||
{
|
||||
serializedObject.Update();
|
||||
waterObject.objectReferenceValue = WaterObject.Instances[0];
|
||||
EditorUtility.SetDirty(target);
|
||||
serializedObject.ApplyModifiedPropertiesWithoutUndo();
|
||||
}
|
||||
|
||||
ValidateMaterial();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
AlignToWaves.Disable = false;
|
||||
Tools.hidden = false;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
UI.DrawHeader();
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
AlignToWaves.EnableInEditor =
|
||||
GUILayout.Toggle(AlignToWaves.EnableInEditor, new GUIContent(" Run in edit-mode (global)", EditorGUIUtility.IconContent(
|
||||
(AlignToWaves.EnableInEditor ? "animationvisibilitytoggleon" : "animationvisibilitytoggleoff")).image), "Button");
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(waterObject);
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(autoFind);
|
||||
EditorGUILayout.PropertyField(dynamicMaterial);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
UI.DrawNotification(isRiver, "Material has river mode enabled, buoyancy only works for flat water bodies", MessageType.Error);
|
||||
UI.DrawNotification(!wavesEnabled && !isRiver, "Material used on the water object does not have waves enabled.", MessageType.Error);
|
||||
|
||||
if (script.waterObject && script.waterObject.material)
|
||||
{
|
||||
UI.DrawNotification((script.waterObject.material.GetFloat("_WorldSpaceUV") == 0f), "Material must use world-projected UV", "Change", ()=> script.waterObject.material.SetFloat("_WorldSpaceUV", 1f), MessageType.Error);
|
||||
}
|
||||
|
||||
if(!autoFind.boolValue && waterObject.objectReferenceValue == null)
|
||||
{
|
||||
UI.DrawNotification("A water object must be assigned!", MessageType.Error);
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel("Water level source");
|
||||
waterLevelSource.intValue = GUILayout.Toolbar(waterLevelSource.intValue, new GUIContent[] { new GUIContent("Fixed Value"), new GUIContent("Water Object") });
|
||||
}
|
||||
if (waterLevelSource.intValue == (int)AlignToWaves.WaterLevelSource.FixedValue) EditorGUILayout.PropertyField(waterLevel);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(heightOffset);
|
||||
EditorGUILayout.PropertyField(rollAmount);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Sample positions", EditorStyles.boldLabel);
|
||||
|
||||
if (targets.Length > 1)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Cannot be modified for a multi-selection", MessageType.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (samples.arraySize > 0)
|
||||
{
|
||||
editSamples =
|
||||
GUILayout.Toggle(editSamples,
|
||||
new GUIContent(" Edit samples", EditorGUIUtility.IconContent("sv_icon_dot0_pix16_gizmo").image),
|
||||
"Button", GUILayout.MaxWidth(125f), GUILayout.MaxHeight(30f));
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.HelpBox("No sample positions added. The transform's pivot position is used", MessageType.None);
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples.arraySize; i++)
|
||||
{
|
||||
SerializedProperty param = samples.GetArrayElementAtIndex(i);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PropertyField(param, true);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("",
|
||||
EditorGUIUtility.IconContent(proSkinPrefix + "TreeEditor.Trash").image, "Delete item"), GUILayout.MaxWidth(30f)))
|
||||
{
|
||||
samples.DeleteArrayElementAtIndex(i);
|
||||
selectedSampleIndex = -1;
|
||||
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button(new GUIContent("Add", EditorGUIUtility.IconContent(proSkinPrefix + "Toolbar Plus").image, "Add new sample point")))
|
||||
{
|
||||
samples.InsertArrayElementAtIndex(samples.arraySize);
|
||||
selectedSampleIndex = samples.arraySize - 1;
|
||||
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(childTransform);
|
||||
if (childTransform.objectReferenceValue == null && samples.arraySize > 0)
|
||||
UI.DrawNotification("Assign a transform to rotate/scale the sample positions with");
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
ValidateMaterial();
|
||||
}
|
||||
|
||||
UI.DrawFooter();
|
||||
}
|
||||
|
||||
private void ValidateMaterial()
|
||||
{
|
||||
if (script.waterObject && script.waterObject.material)
|
||||
{
|
||||
if (script.waterObject.material != script.waterObject.meshRenderer.sharedMaterial) script.waterObject.material = script.waterObject.meshRenderer.sharedMaterial;
|
||||
|
||||
wavesEnabled = WaveParameters.WavesEnabled(script.waterObject.material);
|
||||
isRiver = script.waterObject.material.IsKeywordEnabled("_RIVER");
|
||||
}
|
||||
}
|
||||
|
||||
private int selectedSampleIndex;
|
||||
Vector3 sampleWorldPos;
|
||||
Vector3 prevSampleWorldPos;
|
||||
|
||||
private void OnSceneGUI()
|
||||
{
|
||||
if (!script) return;
|
||||
|
||||
AlignToWaves.Disable = PrefabStageUtility.GetCurrentPrefabStage() != null || editSamples;
|
||||
|
||||
if (editSamples)
|
||||
{
|
||||
//Mute default controls
|
||||
Tools.hidden = true;
|
||||
|
||||
Handles.color = new Color(0.66f, 0.66f, 0.66f, 1);
|
||||
|
||||
for (int i = 0; i < script.samples.Count; i++)
|
||||
{
|
||||
sampleWorldPos = script.ConvertToWorldSpace(script.samples[i]);
|
||||
|
||||
float size = HandleUtility.GetHandleSize(sampleWorldPos) * 0.25f;
|
||||
if (Handles.Button(sampleWorldPos, Quaternion.identity, size, size, Handles.SphereHandleCap))
|
||||
{
|
||||
selectedSampleIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedSampleIndex > -1)
|
||||
{
|
||||
sampleWorldPos = script.ConvertToWorldSpace(script.samples[selectedSampleIndex]);
|
||||
prevSampleWorldPos = sampleWorldPos;
|
||||
|
||||
sampleWorldPos = Handles.PositionHandle(sampleWorldPos, script.childTransform ? script.childTransform.rotation : script.transform.rotation );
|
||||
script.samples[selectedSampleIndex] = script.ConvertToLocalSpace(sampleWorldPos);
|
||||
|
||||
//If moved
|
||||
if (sampleWorldPos != prevSampleWorldPos)
|
||||
{
|
||||
prevSampleWorldPos = sampleWorldPos;
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedSampleIndex = -1;
|
||||
Tools.hidden = false;
|
||||
|
||||
if (script.samples == null) return;
|
||||
|
||||
Handles.color = new Color(1,1,1, 0.25f);
|
||||
for (int i = 0; i < script.samples.Count; i++)
|
||||
{
|
||||
sampleWorldPos = script.ConvertToWorldSpace(script.samples[i]);
|
||||
Handles.SphereHandleCap(0, sampleWorldPos, SceneView.lastActiveSceneView.camera.transform.rotation, HandleUtility.GetHandleSize(sampleWorldPos) * 0.25f, EventType.Repaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6551d287f84686b47a644eabc2efd2c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 148978298399363526, guid: 0000000000000000d000000000000000, type: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,350 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.XR;
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[CustomEditor(typeof(PlanarReflectionRenderer))]
|
||||
public class PlanarReflectionRendererInspector : Editor
|
||||
{
|
||||
private PlanarReflectionRenderer renderer;
|
||||
|
||||
//Rendering
|
||||
private SerializedProperty rotatable;
|
||||
private SerializedProperty cullingMask;
|
||||
private SerializedProperty rendererIndex;
|
||||
private SerializedProperty offset;
|
||||
private SerializedProperty includeSkybox;
|
||||
private SerializedProperty enableFog;
|
||||
|
||||
//Quality
|
||||
private SerializedProperty renderShadows;
|
||||
private SerializedProperty renderRange;
|
||||
private SerializedProperty renderScale;
|
||||
private SerializedProperty maximumLODLevel;
|
||||
|
||||
private SerializedProperty waterObjects;
|
||||
private SerializedProperty moveWithTransform;
|
||||
|
||||
private Bounds curBounds;
|
||||
private bool waterLayerError;
|
||||
|
||||
private bool previewReflection
|
||||
{
|
||||
get => EditorPrefs.GetBool("SWS2_PREVIEW_REFLECTION_ENABLED", true);
|
||||
set => EditorPrefs.SetBool("SWS2_PREVIEW_REFLECTION_ENABLED", value);
|
||||
}
|
||||
private RenderTexture previewTexture;
|
||||
|
||||
#if URP
|
||||
private void OnEnable()
|
||||
{
|
||||
PipelineUtilities.RefreshRendererList();
|
||||
|
||||
renderer = (PlanarReflectionRenderer)target;
|
||||
|
||||
rotatable = serializedObject.FindProperty("rotatable");
|
||||
cullingMask = serializedObject.FindProperty("cullingMask");
|
||||
rendererIndex = serializedObject.FindProperty("rendererIndex");
|
||||
offset = serializedObject.FindProperty("offset");
|
||||
includeSkybox = serializedObject.FindProperty("includeSkybox");
|
||||
enableFog = serializedObject.FindProperty("enableFog");
|
||||
renderShadows = serializedObject.FindProperty("renderShadows");
|
||||
renderRange = serializedObject.FindProperty("renderRange");
|
||||
renderScale = serializedObject.FindProperty("renderScale");
|
||||
maximumLODLevel = serializedObject.FindProperty("maximumLODLevel");
|
||||
waterObjects = serializedObject.FindProperty("waterObjects");
|
||||
moveWithTransform = serializedObject.FindProperty("moveWithTransform");
|
||||
|
||||
if (renderer.waterObjects.Count == 0 && WaterObject.Instances.Count == 1)
|
||||
{
|
||||
renderer.waterObjects.Add(WaterObject.Instances[0]);
|
||||
renderer.RecalculateBounds();
|
||||
renderer.EnableMaterialReflectionSampling();
|
||||
|
||||
EditorUtility.SetDirty(target);
|
||||
serializedObject.ApplyModifiedPropertiesWithoutUndo();
|
||||
}
|
||||
|
||||
ValidateWaterObjectLayer();
|
||||
|
||||
curBounds = renderer.CalculateBounds();
|
||||
|
||||
RenderPipelineManager.endCameraRendering += OnEndCameraRendering;
|
||||
}
|
||||
|
||||
private Camera currentCamera;
|
||||
private string currentCameraName;
|
||||
private bool waterObjectsVisible;
|
||||
|
||||
private void OnEndCameraRendering(ScriptableRenderContext context, Camera camera)
|
||||
{
|
||||
if (!previewReflection) return;
|
||||
|
||||
if (PlanarReflectionRenderer.InvalidContext(camera)) return;
|
||||
|
||||
currentCamera = camera;
|
||||
|
||||
waterObjectsVisible = renderer.WaterObjectsVisible(currentCamera);
|
||||
|
||||
previewTexture = renderer.TryGetReflectionTexture(currentCamera);
|
||||
currentCameraName = currentCamera.name;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
RenderPipelineManager.endCameraRendering -= OnEndCameraRendering;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
#if !URP
|
||||
UI.DrawNotification("The Universal Render Pipeline package v" + AssetInfo.MIN_URP_VERSION + " or newer is not installed", MessageType.Error);
|
||||
#else
|
||||
UI.DrawHeader();
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
previewReflection =
|
||||
GUILayout.Toggle(previewReflection, new GUIContent(" Preview reflection", EditorGUIUtility.IconContent(
|
||||
(previewReflection ? "animationvisibilitytoggleon" : "animationvisibilitytoggleoff")).image), "Button");
|
||||
}
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
EditorGUILayout.LabelField("Status: " + (waterObjectsVisible && currentCamera ? $"Rendering (camera: {currentCamera.name})" : "Not rendering (water not in view for any camera)"), EditorStyles.miniLabel);
|
||||
}
|
||||
|
||||
UI.DrawNotification(PipelineUtilities.VREnabled(), "Not supported with VR rendering", MessageType.Error);
|
||||
|
||||
UI.DrawNotification(PlanarReflectionRenderer.AllowReflections == false, "Reflections have been globally disabled by an external script", MessageType.Warning);
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.LabelField("Rendering", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
UI.DrawRendererProperty(rendererIndex);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
renderer.SetRendererIndex(rendererIndex.intValue);
|
||||
}
|
||||
|
||||
//Default renderer
|
||||
if (rendererIndex.intValue == 0)
|
||||
{
|
||||
UI.DrawNotification("\n" +
|
||||
"Using the default renderer for reflections is strongly discouraged." +
|
||||
"\n\nMost (if not all) render features, such as third-party post processing effects, will also render for the reflection." +
|
||||
"\n\nThis can lead to rendering artefacts and negatively impacts overall performance." +
|
||||
"\n", MessageType.Warning);
|
||||
|
||||
//If there are no other renderers to assign, suggest to auto-create one
|
||||
UI.DrawNotification(PipelineUtilities.rendererIndexList.Length <= 2, "It is highly recommend to create a separate empty renderer", "Create and assign", CreateRenderer, MessageType.None);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(cullingMask);
|
||||
|
||||
EditorGUILayout.PropertyField(includeSkybox);
|
||||
EditorGUILayout.PropertyField(enableFog);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(rotatable);
|
||||
EditorGUILayout.PropertyField(offset);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Quality", EditorStyles.boldLabel);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(renderShadows);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
renderer.ToggleShadows(renderShadows.boolValue);
|
||||
}
|
||||
EditorGUILayout.PropertyField(renderRange);
|
||||
EditorGUILayout.PropertyField(renderScale);
|
||||
EditorGUILayout.PropertyField(maximumLODLevel);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Target water objects", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(moveWithTransform, new GUIContent("Move bounds with transform", moveWithTransform.tooltip));
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(waterObjects);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
curBounds = renderer.CalculateBounds();
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
if(GUILayout.Button(new GUIContent("Auto-find", "Assigns all active water objects currently in the scene"), EditorStyles.miniButton))
|
||||
{
|
||||
renderer.waterObjects = new List<WaterObject>(WaterObject.Instances);
|
||||
|
||||
renderer.RecalculateBounds();
|
||||
curBounds = renderer.bounds;
|
||||
renderer.EnableMaterialReflectionSampling();
|
||||
|
||||
ValidateWaterObjectLayer();
|
||||
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
if(GUILayout.Button("Clear", EditorStyles.miniButton))
|
||||
{
|
||||
renderer.ToggleMaterialReflectionSampling(false);
|
||||
renderer.waterObjects.Clear();
|
||||
renderer.RecalculateBounds();
|
||||
|
||||
EditorUtility.SetDirty(target);
|
||||
}
|
||||
}
|
||||
|
||||
if (renderer.waterObjects != null)
|
||||
{
|
||||
UI.DrawNotification(renderer.waterObjects.Count == 0, "Assign at least one Water Object", MessageType.Info);
|
||||
|
||||
if (renderer.waterObjects.Count > 0)
|
||||
{
|
||||
UI.DrawNotification(curBounds.size != renderer.bounds.size || (moveWithTransform.boolValue == false && curBounds.center != renderer.bounds.center), "Water objects have changed or moved, bounds needs to be recalculated", "Recalculate",() => RecalculateBounds(), MessageType.Error);
|
||||
}
|
||||
|
||||
UI.DrawNotification(waterLayerError, "One or more Water Objects aren't on the \"Water\" layer.\n\nThis causes recursive reflections", "Fix", () => SetObjectsOnWaterLayer(), MessageType.Error);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
UI.DrawFooter();
|
||||
}
|
||||
|
||||
#if URP
|
||||
|
||||
private void CreateRenderer()
|
||||
{
|
||||
int index = -1;
|
||||
string path = "";
|
||||
|
||||
PipelineUtilities.CreateAndAssignNewRenderer(out index, out path);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
rendererIndex.intValue = index;
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
serializedObject.Update();
|
||||
|
||||
renderer.SetRendererIndex(rendererIndex.intValue);
|
||||
|
||||
if (path != string.Empty)
|
||||
{
|
||||
Debug.Log("New renderer created at path <i>" + path + "</i>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI()
|
||||
{
|
||||
return previewReflection && previewTexture;
|
||||
}
|
||||
|
||||
public override bool RequiresConstantRepaint()
|
||||
{
|
||||
return HasPreviewGUI();
|
||||
}
|
||||
|
||||
public override GUIContent GetPreviewTitle()
|
||||
{
|
||||
return currentCamera ? new GUIContent(currentCameraName + " reflection") : new GUIContent("Reflection");
|
||||
}
|
||||
|
||||
public override void OnPreviewSettings()
|
||||
{
|
||||
if (HasPreviewGUI() == false) return;
|
||||
|
||||
GUILayout.Label($"Resolution ({previewTexture.width}x{previewTexture.height})");
|
||||
}
|
||||
|
||||
private bool drawAlpha;
|
||||
|
||||
public override void OnPreviewGUI(Rect r, GUIStyle background)
|
||||
{
|
||||
if (drawAlpha)
|
||||
{
|
||||
EditorGUI.DrawTextureAlpha(r, previewTexture, ScaleMode.ScaleToFit);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.DrawTexture(r, previewTexture, ScaleMode.ScaleToFit, false);
|
||||
}
|
||||
|
||||
Rect btnRect = r;
|
||||
btnRect.x += 10f;
|
||||
btnRect.y += 10f;
|
||||
btnRect.width = 150f;
|
||||
btnRect.height = 20f;
|
||||
|
||||
drawAlpha = GUI.Toggle(btnRect, drawAlpha, new GUIContent(" Alpha channel"));
|
||||
}
|
||||
|
||||
private void ValidateWaterObjectLayer()
|
||||
{
|
||||
if (renderer.waterObjects == null) return;
|
||||
|
||||
waterLayerError = false;
|
||||
int layerID = LayerMask.NameToLayer("Water");
|
||||
|
||||
foreach (WaterObject obj in renderer.waterObjects)
|
||||
{
|
||||
//Is not on "Water" layer?
|
||||
if (obj.gameObject.layer != layerID)
|
||||
{
|
||||
waterLayerError = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetObjectsOnWaterLayer()
|
||||
{
|
||||
int layerID = LayerMask.NameToLayer("Water");
|
||||
|
||||
foreach (WaterObject obj in renderer.waterObjects)
|
||||
{
|
||||
//Is not on "Water" layer?
|
||||
if (obj.gameObject.layer != layerID)
|
||||
{
|
||||
obj.gameObject.layer = layerID;
|
||||
EditorUtility.SetDirty(obj);
|
||||
}
|
||||
}
|
||||
|
||||
waterLayerError = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
private void RecalculateBounds()
|
||||
{
|
||||
#if URP
|
||||
renderer.RecalculateBounds();
|
||||
curBounds = renderer.bounds;
|
||||
EditorUtility.SetDirty(target);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e169bca08efce694eab8006b53ed91c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,68 @@
|
||||
#if URP
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[CustomEditor(typeof(StylizedWaterRenderFeature))]
|
||||
public class RenderFeatureEditor : Editor
|
||||
{
|
||||
private SerializedProperty screenSpaceReflectionSettings;
|
||||
|
||||
private SerializedProperty directionalCaustics;
|
||||
|
||||
private SerializedProperty displacementPrePassSettings;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
screenSpaceReflectionSettings = serializedObject.FindProperty("screenSpaceReflectionSettings");
|
||||
|
||||
directionalCaustics = serializedObject.FindProperty("directionalCaustics");
|
||||
|
||||
displacementPrePassSettings = serializedObject.FindProperty("displacementPrePassSettings");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField($"Version {AssetInfo.INSTALLED_VERSION}", EditorStyles.miniLabel);
|
||||
|
||||
if (GUILayout.Button(new GUIContent(" Documentation", EditorGUIUtility.FindTexture("_Help"))))
|
||||
{
|
||||
Application.OpenURL(AssetInfo.DOC_URL);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(directionalCaustics);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(screenSpaceReflectionSettings);
|
||||
if(screenSpaceReflectionSettings.isExpanded) EditorGUILayout.HelpBox("This feature is available for preview, no configurable settings are available yet", MessageType.Info);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(displacementPrePassSettings);
|
||||
if (displacementPrePassSettings.isExpanded)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This will pre-render all the water geometry's height (including any displacement effects) into a buffer. Allowing other shaders to access this information." +
|
||||
"\n\nSee the Displacement.hlsl shader library for the API, or use the \"Sample Water Height\" Sub-graph in Shader Graph." +
|
||||
"\n\nThis is for advanced users, there is currently no functionality in Stylized Water 2 that makes use of this.", MessageType.Info);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
UI.DrawFooter();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1e12468f8ea4290a886e4706e800a98
|
||||
timeCreated: 1701084026
|
||||
@@ -0,0 +1,116 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[CustomEditor(typeof(WaterGrid))]
|
||||
public class CreateWaterGridInspector : Editor
|
||||
{
|
||||
private WaterGrid script;
|
||||
|
||||
private SerializedProperty material;
|
||||
private SerializedProperty followSceneCamera;
|
||||
private SerializedProperty autoAssignCamera;
|
||||
private SerializedProperty followTarget;
|
||||
|
||||
private SerializedProperty scale;
|
||||
private SerializedProperty vertexDistance;
|
||||
private SerializedProperty rowsColumns;
|
||||
|
||||
private int vertexCount;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
script = (WaterGrid) target;
|
||||
script.m_rowsColumns = script.rowsColumns;
|
||||
|
||||
material = serializedObject.FindProperty("material");
|
||||
followSceneCamera = serializedObject.FindProperty("followSceneCamera");
|
||||
autoAssignCamera = serializedObject.FindProperty("autoAssignCamera");
|
||||
followTarget = serializedObject.FindProperty("followTarget");
|
||||
|
||||
scale = serializedObject.FindProperty("scale");
|
||||
vertexDistance = serializedObject.FindProperty("vertexDistance");
|
||||
rowsColumns = serializedObject.FindProperty("rowsColumns");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
UI.DrawHeader();
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
WaterGrid.DisplayGrid = GUILayout.Toggle(WaterGrid.DisplayGrid , new GUIContent(" Display Grid", EditorGUIUtility.IconContent((WaterGrid.DisplayGrid ? "animationvisibilitytoggleon" : "animationvisibilitytoggleoff")).image), "Button");
|
||||
WaterGrid.DisplayWireframe = GUILayout.Toggle(WaterGrid.DisplayWireframe, new GUIContent(" Show Wireframe", EditorGUIUtility.IconContent((WaterGrid.DisplayWireframe ? "animationvisibilitytoggleon" : "animationvisibilitytoggleoff")).image), "Button");
|
||||
}
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.LabelField("Appearance", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(material);
|
||||
if(material.objectReferenceValue == null) EditorGUILayout.HelpBox("A material must be assigned", MessageType.Error);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Movement", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.PropertyField(followSceneCamera);
|
||||
using (new EditorGUI.DisabledScope(autoAssignCamera.boolValue))
|
||||
{
|
||||
EditorGUILayout.PropertyField(followTarget);
|
||||
}
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(autoAssignCamera);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Grid geometry", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.PropertyField(scale, GUILayout.MaxWidth(EditorGUIUtility.labelWidth + 95f));
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.PrefixLabel(rowsColumns.displayName);
|
||||
using (new EditorGUI.DisabledScope(rowsColumns.intValue <= 1))
|
||||
{
|
||||
if (GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.Width(25f)))
|
||||
{
|
||||
rowsColumns.intValue--;
|
||||
}
|
||||
}
|
||||
EditorGUILayout.PropertyField(rowsColumns, GUIContent.none, GUILayout.MaxWidth(40f));
|
||||
if (GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.Width(25f)))
|
||||
{
|
||||
rowsColumns.intValue++;
|
||||
}
|
||||
EditorGUILayout.LabelField($"= {rowsColumns.intValue * rowsColumns.intValue} tiles", EditorStyles.miniLabel);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(vertexDistance, new GUIContent("Min. vertex distance", vertexDistance.tooltip));
|
||||
vertexCount = Mathf.FloorToInt(((scale.floatValue / rowsColumns.intValue) / vertexDistance.floatValue) * ((scale.floatValue / rowsColumns.intValue) / vertexDistance.floatValue));
|
||||
if(vertexCount > 65535)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Vertex count of individual tiles is too high. Increase the vertex distance, decrease the grid scale, or add more rows/columns", MessageType.Error);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
//Executed here since objects can't be destroyed from OnValidate
|
||||
script.Recreate();
|
||||
}
|
||||
|
||||
UI.DrawFooter();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55b547e4881242f4af120838d3e9e6d6
|
||||
timeCreated: 1680100927
|
||||
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
#if URP
|
||||
using UnityEngine.Rendering.Universal;
|
||||
#endif
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[CustomEditor(typeof(WaterObject))]
|
||||
[CanEditMultipleObjects]
|
||||
public class WaterObjectInspector : Editor
|
||||
{
|
||||
private WaterObject component;
|
||||
|
||||
private SerializedProperty material;
|
||||
private SerializedProperty meshFilter;
|
||||
private SerializedProperty meshRenderer;
|
||||
|
||||
private bool depthTextureRequired;
|
||||
private bool opaqueTextureRequired;
|
||||
|
||||
private bool showInstances
|
||||
{
|
||||
get => SessionState.GetBool("WATEROBJECT_SHOW_INSTANCES", false);
|
||||
set => SessionState.SetBool("WATEROBJECT_SHOW_INSTANCES", value);
|
||||
}
|
||||
|
||||
private Texture icon;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
component = (WaterObject)target;
|
||||
|
||||
icon = Resources.Load<Texture>("water-object-icon");
|
||||
|
||||
material = serializedObject.FindProperty("material");
|
||||
meshFilter = serializedObject.FindProperty("meshFilter");
|
||||
meshRenderer = serializedObject.FindProperty("meshRenderer");
|
||||
|
||||
CheckMaterial();
|
||||
}
|
||||
|
||||
private void CheckMaterial()
|
||||
{
|
||||
#if URP
|
||||
if (UniversalRenderPipeline.asset == null || component.material == null) return;
|
||||
|
||||
depthTextureRequired = UniversalRenderPipeline.asset.supportsCameraDepthTexture == false && component.material.GetFloat("_DisableDepthTexture") == 0f;
|
||||
opaqueTextureRequired = UniversalRenderPipeline.asset.supportsCameraOpaqueTexture == false && component.material.GetFloat("_RefractionOn") == 1f;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
#if URP
|
||||
if (UniversalRenderPipeline.asset)
|
||||
{
|
||||
UI.DrawNotification(
|
||||
depthTextureRequired,
|
||||
"Depth texture is disabled, but is required for the water material",
|
||||
"Enable",
|
||||
() =>
|
||||
{
|
||||
StylizedWaterEditor.EnableDepthTexture();
|
||||
CheckMaterial();
|
||||
},
|
||||
MessageType.Error);
|
||||
|
||||
UI.DrawNotification(
|
||||
opaqueTextureRequired,
|
||||
"Opaque texture is disabled, but is required for the water material",
|
||||
"Enable",
|
||||
() =>
|
||||
{
|
||||
StylizedWaterEditor.EnableOpaqueTexture();
|
||||
CheckMaterial();
|
||||
},
|
||||
MessageType.Error);
|
||||
}
|
||||
#endif
|
||||
|
||||
EditorGUILayout.HelpBox("This component provides a means for other scripts to identify and find water bodies", MessageType.None);
|
||||
|
||||
EditorGUILayout.LabelField("References (Read only)", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUI.BeginDisabledGroup(true);
|
||||
{
|
||||
EditorGUILayout.PropertyField(material);
|
||||
EditorGUILayout.PropertyField(meshFilter);
|
||||
EditorGUILayout.PropertyField(meshRenderer);
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
//In case the material was changed on the attached Mesh Renderer, reflect the change
|
||||
foreach (Object currentTarget in targets)
|
||||
{
|
||||
WaterObject water = (WaterObject)currentTarget;
|
||||
water.FetchWaterMaterial();
|
||||
}
|
||||
|
||||
if (WaterObject.Instances.Count > 1)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
|
||||
showInstances = EditorGUILayout.BeginFoldoutHeaderGroup(showInstances, $"Instances ({WaterObject.Instances.Count})");
|
||||
|
||||
if (showInstances)
|
||||
{
|
||||
this.Repaint();
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(EditorStyles.textArea))
|
||||
{
|
||||
foreach (WaterObject obj in WaterObject.Instances)
|
||||
{
|
||||
var rect = EditorGUILayout.BeginHorizontal(EditorStyles.miniLabel);
|
||||
|
||||
if (rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 27, 27), MouseCursor.Link);
|
||||
EditorGUI.DrawRect(rect, Color.gray * (EditorGUIUtility.isProSkin ? 0.66f : 0.20f));
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent(" " + obj.name, icon), EditorStyles.miniLabel, GUILayout.Height(20f)))
|
||||
{
|
||||
EditorGUIUtility.PingObject(obj);
|
||||
Selection.activeGameObject = obj.gameObject;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24c4c7f693f04a3893891169c1f864d8
|
||||
timeCreated: 1685014300
|
||||
@@ -0,0 +1,341 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
using UnityEditor.AssetImporters;
|
||||
#else
|
||||
using UnityEditor.Experimental.AssetImporters;
|
||||
#endif
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[CustomEditor(typeof(WaterShaderImporter))]
|
||||
[CanEditMultipleObjects]
|
||||
public class WaterShaderImporterEditor : ScriptedImporterEditor
|
||||
{
|
||||
private WaterShaderImporter importer;
|
||||
|
||||
private SerializedProperty template;
|
||||
|
||||
private SerializedProperty settings;
|
||||
|
||||
private SerializedProperty shaderName;
|
||||
private SerializedProperty hidden;
|
||||
private SerializedProperty type;
|
||||
|
||||
private SerializedProperty autoIntegration;
|
||||
private SerializedProperty fogIntegration;
|
||||
|
||||
private SerializedProperty lightCookies;
|
||||
|
||||
private SerializedProperty customIncludeDirectives;
|
||||
|
||||
private bool underwaterRenderingInstalled;
|
||||
private bool dynamicEffectsInstalled;
|
||||
private ShaderConfigurator.Fog.Integration firstIntegration;
|
||||
private bool curvedWorldInstalled;
|
||||
|
||||
private bool showDependencies;
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
underwaterRenderingInstalled = StylizedWaterEditor.UnderwaterRenderingInstalled();
|
||||
dynamicEffectsInstalled = StylizedWaterEditor.DynamicEffectsInstalled();
|
||||
firstIntegration = ShaderConfigurator.Fog.GetFirstInstalled();
|
||||
curvedWorldInstalled = StylizedWaterEditor.CurvedWorldInstalled(out var _);
|
||||
|
||||
importer = (WaterShaderImporter)target;
|
||||
|
||||
template = serializedObject.FindProperty("template");
|
||||
|
||||
settings = serializedObject.FindProperty("settings");
|
||||
//settings.isExpanded = true;
|
||||
|
||||
shaderName = settings.FindPropertyRelative("shaderName");
|
||||
hidden = settings.FindPropertyRelative("hidden");
|
||||
type = settings.FindPropertyRelative("type");
|
||||
|
||||
lightCookies = settings.FindPropertyRelative("lightCookies");
|
||||
|
||||
autoIntegration = settings.FindPropertyRelative("autoIntegration");
|
||||
fogIntegration = settings.FindPropertyRelative("fogIntegration");
|
||||
|
||||
customIncludeDirectives = settings.FindPropertyRelative("customIncludeDirectives");
|
||||
}
|
||||
|
||||
public override bool HasPreviewGUI()
|
||||
{
|
||||
//Hide the useless sphere preview :)
|
||||
return false;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
//base.OnInspectorGUI();
|
||||
Color defaultColor = GUI.contentColor;
|
||||
|
||||
UI.DrawHeader();
|
||||
|
||||
Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(importer.assetPath);
|
||||
if (shader == null)
|
||||
{
|
||||
UI.DrawNotification("Shader failed to compile, try to manually recompile it now.", MessageType.Error);
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent(" Recompile", EditorGUIUtility.IconContent("RotateTool").image), GUILayout.MinHeight(30f)))
|
||||
{
|
||||
importer.SaveAndReimport();
|
||||
}
|
||||
|
||||
GUILayout.Space(-2f);
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
using (new EditorGUI.DisabledGroupScope(shader == null))
|
||||
{
|
||||
if (GUILayout.Button(new GUIContent(" Show Generated Code", EditorGUIUtility.IconContent("align_horizontally_left_active").image), EditorStyles.miniButtonLeft, GUILayout.Height(28f)))
|
||||
{
|
||||
GenericMenu menu = new GenericMenu();
|
||||
|
||||
menu.AddItem(new GUIContent("With tessellation"), false, () => OpenGeneratedCode(true));
|
||||
menu.AddItem(new GUIContent("Without tessellation"), false, () => OpenGeneratedCode(false));
|
||||
|
||||
menu.ShowAsContext();
|
||||
}
|
||||
if (GUILayout.Button(new GUIContent("Clear cache", "Unity's shader compiler will cache the compiled shader, and internally use that." +
|
||||
"\n\nThis may result in seemingly false-positive shader errors. Such as in the case of importing the shader, before the URP shader libraries are." +
|
||||
"\n\nClearing the cache gives the compiler a kick, and makes the shader properly represent the current state of the project/dependencies."), EditorStyles.miniButtonRight, GUILayout.Height(28f)))
|
||||
{
|
||||
importer.ClearCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(template);
|
||||
|
||||
if (template.objectReferenceValue == null) EditorGUILayout.HelpBox("• Template is assumed to be in the contents of the file itself", MessageType.None);
|
||||
//EditorGUILayout.LabelField(importer.GetTemplatePath(), EditorStyles.miniLabel);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
|
||||
EditorGUILayout.PropertyField(shaderName);
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(hidden);
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUILayout.PropertyField(type);
|
||||
|
||||
if (type.intValue == (int)WaterShaderImporter.WaterShaderSettings.ShaderType.WaterSurface)
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Integrations", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.PropertyField(autoIntegration, new GUIContent("Automatic detection", autoIntegration.tooltip));
|
||||
if (autoIntegration.boolValue)
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.LabelField("Fog post-processing", GUILayout.MaxWidth(EditorGUIUtility.labelWidth));
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope(EditorStyles.textField))
|
||||
{
|
||||
GUI.contentColor = Color.green;
|
||||
EditorGUILayout.LabelField(firstIntegration.name);
|
||||
|
||||
GUI.contentColor = defaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.LabelField("Curved World 2020", GUILayout.MaxWidth(EditorGUIUtility.labelWidth));
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope(EditorStyles.textField))
|
||||
{
|
||||
if (curvedWorldInstalled)
|
||||
{
|
||||
GUI.contentColor = Color.green;
|
||||
EditorGUILayout.LabelField("Installed");
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.contentColor = new Color(1f, 0.65f, 0f);
|
||||
EditorGUILayout.LabelField("(Not installed)");
|
||||
}
|
||||
|
||||
GUI.contentColor = defaultColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(fogIntegration);
|
||||
}
|
||||
if (curvedWorldInstalled) EditorGUILayout.HelpBox("Curved World integration must be activated through Window->Amazing Assets->Curved Word (Activator tab)", MessageType.Info);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Functionality support", EditorStyles.boldLabel);
|
||||
|
||||
EditorGUILayout.PropertyField(lightCookies);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.LabelField("Extensions", EditorStyles.boldLabel);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField("Underwater Rendering", GUILayout.MaxWidth(EditorGUIUtility.labelWidth));
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope(EditorStyles.textField))
|
||||
{
|
||||
if (underwaterRenderingInstalled)
|
||||
{
|
||||
GUI.contentColor = Color.green;
|
||||
EditorGUILayout.LabelField("Installed");
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.contentColor = new Color(1f, 0.65f, 0f);
|
||||
EditorGUILayout.LabelField("(Not installed)");
|
||||
}
|
||||
|
||||
GUI.contentColor = defaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
EditorGUILayout.LabelField("Dynamic Effects", GUILayout.MaxWidth(EditorGUIUtility.labelWidth));
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope(EditorStyles.textField))
|
||||
{
|
||||
if (dynamicEffectsInstalled)
|
||||
{
|
||||
GUI.contentColor = Color.green;
|
||||
EditorGUILayout.LabelField("Installed");
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI.contentColor = new Color(1f, 0.65f, 0f);
|
||||
EditorGUILayout.LabelField("(Not installed)");
|
||||
}
|
||||
|
||||
GUI.contentColor = defaultColor;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(customIncludeDirectives);
|
||||
if (customIncludeDirectives.isExpanded)
|
||||
{
|
||||
EditorGUILayout.HelpBox("These are defined in a HLSLINCLUDE block and apply to all passes" +
|
||||
"\nMay be used to insert custom code.", MessageType.Info);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
//Force the parameter to a matching value.
|
||||
//This way, if the "auto-integration" option is used, the .meta file will be changed when using the shader in a package, spanning different projects.
|
||||
//When switching a different project, the file will be seen as changed and will be re-imported, in turn applying the project-specific integration.
|
||||
if (autoIntegration.boolValue)
|
||||
{
|
||||
fogIntegration.intValue = (int)firstIntegration.asset;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
this.ApplyRevertGUI();
|
||||
|
||||
showDependencies = EditorGUILayout.BeginFoldoutHeaderGroup(showDependencies, $"Dependencies ({importer.dependencies.Count})");
|
||||
|
||||
if (showDependencies)
|
||||
{
|
||||
this.Repaint();
|
||||
|
||||
using (new EditorGUILayout.VerticalScope(EditorStyles.textArea))
|
||||
{
|
||||
foreach (string dependency in importer.dependencies)
|
||||
{
|
||||
var rect = EditorGUILayout.BeginHorizontal(EditorStyles.miniLabel);
|
||||
|
||||
if (rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
EditorGUIUtility.AddCursorRect(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 27, 27), MouseCursor.Link);
|
||||
EditorGUI.DrawRect(rect, Color.gray * (EditorGUIUtility.isProSkin ? 0.66f : 0.20f));
|
||||
}
|
||||
|
||||
if (GUILayout.Button(dependency == string.Empty ? new GUIContent(" (Missing)", EditorGUIUtility.IconContent("console.warnicon.sml").image) : new GUIContent(" " + dependency, EditorGUIUtility.IconContent("TextAsset Icon").image),
|
||||
EditorStyles.miniLabel, GUILayout.Height(20f)))
|
||||
{
|
||||
if (dependency != string.Empty)
|
||||
{
|
||||
TextAsset file = AssetDatabase.LoadAssetAtPath<TextAsset>(dependency);
|
||||
|
||||
EditorGUIUtility.PingObject(file);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.HelpBox("Should any of these files be modified/moved/deleted, this shader will also re-import", MessageType.Info);
|
||||
}
|
||||
EditorGUILayout.EndFoldoutHeaderGroup();
|
||||
|
||||
UI.DrawFooter();
|
||||
|
||||
if (shader)
|
||||
{
|
||||
UI.DrawNotification(ShaderUtil.ShaderHasError(shader), "Errors may be false-positives due to caching", "Clear cache", () => importer.ClearCache(true), MessageType.Warning);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGeneratedCode(bool tessellation)
|
||||
{
|
||||
importer = (WaterShaderImporter)target;
|
||||
|
||||
string filePath = $"{Application.dataPath.Replace("Assets", string.Empty)}Temp/{importer.settings.shaderName}(Generated Code).shader";
|
||||
|
||||
string code = ShaderConfigurator.TemplateParser.CreateShaderCode(importer.GetTemplatePath(), importer, tessellation);
|
||||
File.WriteAllText(filePath, code);
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Debug.LogError(string.Format("Path {0} doesn't exists", filePath));
|
||||
return;
|
||||
}
|
||||
|
||||
string externalScriptEditor = ScriptEditorUtility.GetExternalScriptEditor();
|
||||
if (externalScriptEditor != "internal")
|
||||
{
|
||||
InternalEditorUtility.OpenFileAtLineExternal(filePath, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.OpenURL("file://" + filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81c37dbe6c244dcca9bde0e9c0f64171
|
||||
timeCreated: 1691138447
|
||||
1703
LocalPackages/StylizedWater2/Editor/MaterialUI.cs
Normal file
1703
LocalPackages/StylizedWater2/Editor/MaterialUI.cs
Normal file
File diff suppressed because it is too large
Load Diff
11
LocalPackages/StylizedWater2/Editor/MaterialUI.cs.meta
Normal file
11
LocalPackages/StylizedWater2/Editor/MaterialUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab427f26bc4a58a4d982a32fcf593b66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
LocalPackages/StylizedWater2/Editor/Resources.meta
Normal file
8
LocalPackages/StylizedWater2/Editor/Resources.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a75fcefb8ac12334b9cb3ec88076b02e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,132 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83548767ebe1791409159648329da97d
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: -1
|
||||
wrapV: -1
|
||||
wrapW: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
@@ -0,0 +1,132 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8b93d3698aa42dd4382e180b61a3f224
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: -1
|
||||
wrapV: -1
|
||||
wrapW: -1
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 0
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
flipbookRows: 1
|
||||
flipbookColumns: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 0
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
873
LocalPackages/StylizedWater2/Editor/ShaderConfigurator.cs
Normal file
873
LocalPackages/StylizedWater2/Editor/ShaderConfigurator.cs
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 026e0b49a81c6b047b5b159b73908933
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
261
LocalPackages/StylizedWater2/Editor/StylizedWaterEditor.cs
Normal file
261
LocalPackages/StylizedWater2/Editor/StylizedWaterEditor.cs
Normal file
@@ -0,0 +1,261 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
#if URP
|
||||
using UnityEngine.Rendering.Universal;
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
using ForwardRendererData = UnityEngine.Rendering.Universal.UniversalRendererData;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
public class StylizedWaterEditor : Editor
|
||||
{
|
||||
#if URP
|
||||
[MenuItem("GameObject/3D Object/Water/Object", false, 0)]
|
||||
public static void CreateWaterObject()
|
||||
{
|
||||
Material mat = AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath("fbb04271505a76f40b984e38071e86f3"));
|
||||
Mesh mesh = AssetDatabase.LoadAssetAtPath<Mesh>(AssetDatabase.GUIDToAssetPath("1e01d80fdc2155d4692276500db33fc9"));
|
||||
|
||||
WaterObject obj = WaterObject.New(mat, mesh);
|
||||
|
||||
//Position in view
|
||||
if (SceneView.lastActiveSceneView)
|
||||
{
|
||||
obj.transform.position = SceneView.lastActiveSceneView.camera.transform.position + (SceneView.lastActiveSceneView.camera.transform.forward * (Mathf.Max(mesh.bounds.size.x, mesh.bounds.size.z)) * 0.5f);
|
||||
}
|
||||
|
||||
if (Selection.activeGameObject) obj.transform.parent = Selection.activeGameObject.transform;
|
||||
|
||||
Selection.activeObject = obj;
|
||||
|
||||
if(Application.isPlaying == false) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/3D Object/Water/Grid", false, 1)]
|
||||
[MenuItem("Window/Stylized Water 2/Create water grid", false, 2001)]
|
||||
public static void CreateWaterGrid()
|
||||
{
|
||||
GameObject obj = new GameObject("Water Grid", typeof(WaterGrid));
|
||||
Undo.RegisterCreatedObjectUndo(obj, "Created Water Grid");
|
||||
|
||||
obj.layer = LayerMask.NameToLayer("Water");
|
||||
|
||||
WaterGrid grid = obj.GetComponent<WaterGrid>();
|
||||
grid.Recreate();
|
||||
|
||||
if (Selection.activeGameObject) obj.transform.parent = Selection.activeGameObject.transform;
|
||||
|
||||
Selection.activeObject = obj;
|
||||
|
||||
//Position in view
|
||||
if (SceneView.lastActiveSceneView)
|
||||
{
|
||||
Vector3 position = SceneView.lastActiveSceneView.camera.transform.position + (SceneView.lastActiveSceneView.camera.transform.forward * grid.scale * 0.5f);
|
||||
position.y = 0f;
|
||||
|
||||
grid.transform.position = position;
|
||||
}
|
||||
|
||||
if(Application.isPlaying == false) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
|
||||
[MenuItem("Window/Stylized Water 2/Set up render feature", false, 2000)]
|
||||
public static void SetupRenderFeature()
|
||||
{
|
||||
PipelineUtilities.SetupRenderFeature<StylizedWaterRenderFeature>("Stylized Water 2");
|
||||
}
|
||||
|
||||
[MenuItem("GameObject/3D Object/Water/Planar Reflections Renderer", false, 2)]
|
||||
[MenuItem("Window/Stylized Water 2/Set up planar reflections", false, 2001)]
|
||||
public static void CreatePlanarReflectionRenderer()
|
||||
{
|
||||
GameObject obj = new GameObject("Planar Reflections Renderer", typeof(PlanarReflectionRenderer));
|
||||
Undo.RegisterCreatedObjectUndo(obj, "Created PlanarReflectionRenderer");
|
||||
PlanarReflectionRenderer r = obj.GetComponent<PlanarReflectionRenderer>();
|
||||
r.ApplyToAllWaterInstances();
|
||||
|
||||
Selection.activeObject = obj;
|
||||
|
||||
if(Application.isPlaying == false) EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
#endif
|
||||
|
||||
[MenuItem("Assets/Create/Water/Mesh")]
|
||||
private static void CreateWaterPlaneAsset()
|
||||
{
|
||||
ProjectWindowUtil.CreateAssetWithContent("New Watermesh.watermesh", "");
|
||||
}
|
||||
|
||||
[MenuItem("CONTEXT/Transform/Align To Waves")]
|
||||
private static void AddAlignToWaves(MenuCommand cmd)
|
||||
{
|
||||
Transform t = (Transform)cmd.context;
|
||||
|
||||
if (!t.gameObject.GetComponent<AlignToWaves>())
|
||||
{
|
||||
AlignToWaves component = t.gameObject.AddComponent<AlignToWaves>();
|
||||
EditorUtility.SetDirty(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool UnderwaterRenderingInstalled()
|
||||
{
|
||||
//Checking for UnderwaterRenderer.cs meta file
|
||||
string path = AssetDatabase.GUIDToAssetPath("6a52edc7a3652d84784e10be859d5807");
|
||||
return AssetDatabase.LoadMainAssetAtPath(path);
|
||||
}
|
||||
|
||||
public static bool DynamicEffectsInstalled()
|
||||
{
|
||||
//Checking for the WaterDynamicEffectsRenderFeature.cs meta file
|
||||
string path = AssetDatabase.GUIDToAssetPath("48bd76fbc46e46fe9bc606bd3c30bd9b");
|
||||
return AssetDatabase.LoadMainAssetAtPath(path);
|
||||
}
|
||||
|
||||
public static void OpenGraphicsSettings()
|
||||
{
|
||||
SettingsService.OpenProjectSettings("Project/Graphics");
|
||||
}
|
||||
|
||||
public static void SelectForwardRenderer()
|
||||
{
|
||||
#if URP
|
||||
if (!UniversalRenderPipeline.asset) return;
|
||||
|
||||
System.Reflection.BindingFlags bindings = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
|
||||
ScriptableRendererData[] m_rendererDataList = (ScriptableRendererData[])typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList", bindings).GetValue(UniversalRenderPipeline.asset);
|
||||
|
||||
ForwardRendererData main = m_rendererDataList[0] as ForwardRendererData;
|
||||
Selection.activeObject = main;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void EnableDepthTexture()
|
||||
{
|
||||
#if URP
|
||||
if (!UniversalRenderPipeline.asset) return;
|
||||
|
||||
UniversalRenderPipeline.asset.supportsCameraDepthTexture = true;
|
||||
EditorUtility.SetDirty(UniversalRenderPipeline.asset);
|
||||
|
||||
if (PipelineUtilities.IsDepthTextureOptionDisabledAnywhere())
|
||||
{
|
||||
if (EditorUtility.DisplayDialog(AssetInfo.ASSET_NAME, "The Depth Texture option is still disabled on other pipeline assets (likely for other quality levels).\n\nWould you like to enable it on those as well?", "OK", "Cancel"))
|
||||
{
|
||||
PipelineUtilities.SetDepthTextureOnAllAssets(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void EnableOpaqueTexture()
|
||||
{
|
||||
#if URP
|
||||
if (!UniversalRenderPipeline.asset) return;
|
||||
|
||||
UniversalRenderPipeline.asset.supportsCameraOpaqueTexture = true;
|
||||
EditorUtility.SetDirty(UniversalRenderPipeline.asset);
|
||||
|
||||
if (PipelineUtilities.IsOpaqueTextureOptionDisabledAnywhere())
|
||||
{
|
||||
if (EditorUtility.DisplayDialog(AssetInfo.ASSET_NAME, "The Opaque Texture option is still disabled on other pipeline assets (likely for other quality levels).\n\nWould you like to enable it on those as well?", "OK", "Cancel"))
|
||||
{
|
||||
PipelineUtilities.SetOpaqueTextureOnAllAssets(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the assigned water material to render as double-sided, which is required for underwater rendering
|
||||
/// </summary>
|
||||
public static void DisableCullingForMaterial(Material material)
|
||||
{
|
||||
if (!material) return;
|
||||
|
||||
material.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
|
||||
|
||||
EditorUtility.SetDirty(material);
|
||||
}
|
||||
|
||||
public static bool CurvedWorldInstalled(out string libraryPath)
|
||||
{
|
||||
//Checking for "CurvedWorldTransform.cginc"
|
||||
libraryPath = AssetDatabase.GUIDToAssetPath("208a98c9ab72b9f4bb8735c6a229e807");
|
||||
return libraryPath != string.Empty;
|
||||
}
|
||||
|
||||
#if NWH_DWP2
|
||||
public static bool DWP2Installed => true;
|
||||
#else
|
||||
public static bool DWP2Installed => false;
|
||||
#endif
|
||||
|
||||
public static T Find<T>() where T : Object
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
return (T)Object.FindFirstObjectByType(typeof(T));
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
return (T)Object.FindObjectOfType(typeof(T), false);
|
||||
#else
|
||||
return (T)Object.FindObjectOfType(typeof(T));
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void SetupForDWP2()
|
||||
{
|
||||
#if NWH_DWP2
|
||||
if (!EditorUtility.DisplayDialog("Dynamic Water Physics 2 -> Stylized Water 2",
|
||||
"This operation will look for a \"Flat Water Data Provider\" component and replace it with the \"Stylized Water Data Provider\" component",
|
||||
"OK", "Cancel"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NWH.DWP2.WaterData.StylizedWaterDataProvider dataProvider = Find<NWH.DWP2.WaterData.StylizedWaterDataProvider>();
|
||||
NWH.DWP2.WaterData.FlatWaterDataProvider oldProvider = Find<NWH.DWP2.WaterData.FlatWaterDataProvider>();
|
||||
|
||||
if (dataProvider)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Dynamic Water Physics 2 -> Stylized Water 2", "A \"Stylized Water Data Provider\" component was already found in the scene", "OK");
|
||||
|
||||
EditorGUIUtility.PingObject(dataProvider.gameObject);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(oldProvider == null)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Dynamic Water Physics 2 -> Stylized Water 2",
|
||||
"Could not find a \"Flat Water Data Provider\" component in the scene.\n\nIt's recommended to first set up DWP2 according to their manual.",
|
||||
"OK"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NWH.DWP2.DefaultWater.Water waterScript = Find<NWH.DWP2.DefaultWater.Water>();
|
||||
if(waterScript) DestroyImmediate(waterScript);
|
||||
|
||||
if (oldProvider)
|
||||
{
|
||||
dataProvider = oldProvider.gameObject.AddComponent<NWH.DWP2.WaterData.StylizedWaterDataProvider>();
|
||||
oldProvider.gameObject.AddComponent<StylizedWater2.WaterObject>();
|
||||
|
||||
Selection.activeGameObject = oldProvider.gameObject;
|
||||
|
||||
DestroyImmediate(oldProvider);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23fe47c78f2c84d4db3765a2a5466f68
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1026
LocalPackages/StylizedWater2/Editor/UI.cs
Normal file
1026
LocalPackages/StylizedWater2/Editor/UI.cs
Normal file
File diff suppressed because one or more lines are too long
11
LocalPackages/StylizedWater2/Editor/UI.cs.meta
Normal file
11
LocalPackages/StylizedWater2/Editor/UI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3ec5d4ce2810a8428fc54db383a4386
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
221
LocalPackages/StylizedWater2/Editor/WaterMeshImporter.cs
Normal file
221
LocalPackages/StylizedWater2/Editor/WaterMeshImporter.cs
Normal file
@@ -0,0 +1,221 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
using UnityEditor.AssetImporters;
|
||||
#else
|
||||
using UnityEditor.Experimental.AssetImporters;
|
||||
#endif
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[ScriptedImporter(3, FILE_EXTENSION)]
|
||||
public class WaterMeshImporter : ScriptedImporter
|
||||
{
|
||||
private const string FILE_EXTENSION = "watermesh";
|
||||
|
||||
[SerializeField] public WaterMesh waterMesh = new WaterMesh();
|
||||
|
||||
public override void OnImportAsset(AssetImportContext context)
|
||||
{
|
||||
waterMesh.Rebuild();
|
||||
|
||||
context.AddObjectToAsset("mesh", waterMesh.mesh);
|
||||
context.SetMainObject(waterMesh.mesh);
|
||||
}
|
||||
|
||||
//Handles correct behaviour when double-clicking a .watermesh asset assigned to a field
|
||||
//Otherwise the OS prompts to open it
|
||||
[UnityEditor.Callbacks.OnOpenAsset]
|
||||
public static bool OnOpenAsset(int instanceID, int line)
|
||||
{
|
||||
Object target = EditorUtility.InstanceIDToObject(instanceID);
|
||||
|
||||
if (target is Mesh)
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(instanceID);
|
||||
|
||||
if (Path.GetExtension(path) != "." + FILE_EXTENSION) return false;
|
||||
|
||||
Selection.activeObject = target;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(WaterMeshImporter))]
|
||||
public class WaterMeshImporterEditor: ScriptedImporterEditor
|
||||
{
|
||||
private SerializedProperty waterMesh;
|
||||
|
||||
private SerializedProperty shape;
|
||||
|
||||
private SerializedProperty scale;
|
||||
private SerializedProperty UVTiling;
|
||||
|
||||
private SerializedProperty vertexDistance;
|
||||
|
||||
private SerializedProperty noise;
|
||||
private SerializedProperty boundsPadding;
|
||||
|
||||
private WaterMeshImporter importer;
|
||||
|
||||
private bool autoApplyChanges;
|
||||
private bool previewInSceneView
|
||||
{
|
||||
get => EditorPrefs.GetBool("SWS2_PREVIEW_WATER_MESH_ENABLED", true);
|
||||
set => EditorPrefs.SetBool("SWS2_PREVIEW_WATER_MESH_ENABLED", value);
|
||||
}
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
importer = (WaterMeshImporter)target;
|
||||
|
||||
waterMesh = serializedObject.FindProperty("waterMesh");
|
||||
|
||||
shape = waterMesh.FindPropertyRelative("shape");
|
||||
scale = waterMesh.FindPropertyRelative("scale");
|
||||
UVTiling = waterMesh.FindPropertyRelative("UVTiling");
|
||||
vertexDistance = waterMesh.FindPropertyRelative("vertexDistance");
|
||||
noise = waterMesh.FindPropertyRelative("noise");
|
||||
boundsPadding = waterMesh.FindPropertyRelative("boundsPadding");
|
||||
|
||||
SceneView.duringSceneGui += OnSceneGUI;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
UI.DrawHeader();
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
previewInSceneView =
|
||||
GUILayout.Toggle(previewInSceneView, new GUIContent(" Preview in scene view", EditorGUIUtility.IconContent(
|
||||
(previewInSceneView ? "animationvisibilitytoggleon" : "animationvisibilitytoggleoff")).image), "Button");
|
||||
}
|
||||
if (previewInSceneView && WaterObject.Instances.Count > 0)
|
||||
{
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
EditorGUILayout.HelpBox($"Drawing on WaterObject instances in the scene ({WaterObject.Instances.Count})", MessageType.None);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(shape);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(scale);
|
||||
EditorGUILayout.PropertyField(vertexDistance);
|
||||
|
||||
int subdivisions = Mathf.FloorToInt(scale.floatValue / vertexDistance.floatValue);
|
||||
int vertexCount = Mathf.FloorToInt(subdivisions * subdivisions);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
|
||||
Rect rect = EditorGUILayout.GetControlRect();
|
||||
EditorGUI.ProgressBar(rect, (float)vertexCount/65535f, $"Vertex count: {vertexCount:N1}/{65535f:N1}");
|
||||
}
|
||||
if(vertexCount > 65535)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Vertex count (" + vertexCount + ") is too high. Decrease the scale, or increase the vertex distance.", MessageType.Error);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(UVTiling);
|
||||
EditorGUILayout.PropertyField(noise);
|
||||
EditorGUILayout.PropertyField(boundsPadding);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
autoApplyChanges = EditorGUILayout.Toggle("Auto-apply changes", autoApplyChanges);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (autoApplyChanges && HasModified())
|
||||
{
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
this.SaveChanges();
|
||||
#else
|
||||
this.ApplyAndImport();
|
||||
#endif
|
||||
|
||||
importer = (WaterMeshImporter)target;
|
||||
}
|
||||
}
|
||||
|
||||
this.ApplyRevertGUI();
|
||||
|
||||
UI.DrawFooter();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
SceneView.duringSceneGui -= OnSceneGUI;
|
||||
}
|
||||
|
||||
private Material mat;
|
||||
private void OnSceneGUI(SceneView obj)
|
||||
{
|
||||
if (!previewInSceneView)
|
||||
{
|
||||
GL.wireframe = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mat)
|
||||
{
|
||||
mat = new Material(Shader.Find("Unlit/Color"));
|
||||
mat.color = new Color(0,0,0, 0.25f);
|
||||
mat.mainTexture = Texture2D.whiteTexture;
|
||||
}
|
||||
mat.SetPass(0);
|
||||
|
||||
if (importer.waterMesh.mesh)
|
||||
{
|
||||
GL.wireframe = true;
|
||||
if (WaterObject.Instances.Count > 0)
|
||||
{
|
||||
foreach (WaterObject waterObject in WaterObject.Instances)
|
||||
{
|
||||
Graphics.DrawMeshNow(importer.waterMesh.mesh, waterObject.transform.localToWorldMatrix);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SceneView.lastActiveSceneView)
|
||||
{
|
||||
//Position in view
|
||||
Vector3 position = SceneView.lastActiveSceneView.camera.transform.position + (SceneView.lastActiveSceneView.camera.transform.forward * importer.waterMesh.scale * 0.5f);
|
||||
|
||||
Graphics.DrawMeshNow(importer.waterMesh.mesh, position, Quaternion.identity);
|
||||
}
|
||||
}
|
||||
GL.wireframe = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b8903faabaa4d64bbf306b8787d2d67
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
317
LocalPackages/StylizedWater2/Editor/WaterShaderImporter.cs
Normal file
317
LocalPackages/StylizedWater2/Editor/WaterShaderImporter.cs
Normal file
@@ -0,0 +1,317 @@
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#if UNITY_2020_2_OR_NEWER
|
||||
using UnityEditor.AssetImporters;
|
||||
#else
|
||||
using UnityEditor.Experimental.AssetImporters;
|
||||
#endif
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace StylizedWater2
|
||||
{
|
||||
[ScriptedImporterAttribute(AssetInfo.SHADER_GENERATOR_VERSION_MAJOR + AssetInfo.SHADER_GENERATOR_MINOR + AssetInfo.SHADER_GENERATOR_PATCH, TARGET_FILE_EXTENSION, 2)]
|
||||
public class WaterShaderImporter : ScriptedImporter
|
||||
{
|
||||
private const string TARGET_FILE_EXTENSION = "watershader";
|
||||
private const string ICON_NAME = "water-shader-icon";
|
||||
|
||||
[Tooltip("Rather than storing the template in this file, it can be sourced from an external text file" +
|
||||
"\nUse this if you intent to duplicate this asset, and need only minor modifications to its import settings")]
|
||||
[SerializeField] public LazyLoadReference<Object> template;
|
||||
|
||||
[Space]
|
||||
|
||||
public WaterShaderSettings settings;
|
||||
|
||||
/// <summary>
|
||||
/// File paths of any file this shader depends on. This list will be populated with any "#include" paths present in the template
|
||||
/// Registering these as dependencies is required to trigger the shader to recompile when these files are changed
|
||||
/// </summary>
|
||||
//[NonSerialized] //Want to keep these serialized. Will differ per-project, which also causes the file to appear as changed for every project when updating the asset (this triggers a re-import)
|
||||
public List<string> dependencies = new List<string>();
|
||||
|
||||
private bool HasExternalTemplate()
|
||||
{
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
return template.isSet;
|
||||
#else
|
||||
return template.asset;
|
||||
#endif
|
||||
}
|
||||
|
||||
public string GetTemplatePath()
|
||||
{
|
||||
return HasExternalTemplate() ? AssetDatabase.GetAssetPath(template.asset) : assetPath;
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
if(settings.shaderName == string.Empty) settings.shaderName = $"{Application.productName} ({DateTime.Now.Ticks})";
|
||||
}
|
||||
|
||||
public override void OnImportAsset(AssetImportContext context)
|
||||
{
|
||||
Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(context.assetPath);
|
||||
//if (shader != null) ShaderUtil.ClearShaderMessages(shader);
|
||||
|
||||
string templatePath = GetTemplatePath();
|
||||
|
||||
if (templatePath == string.Empty)
|
||||
{
|
||||
Debug.LogError("Failed to import water shader, template file path is null. It possibly hasn't been imported first?", shader);
|
||||
return;
|
||||
}
|
||||
|
||||
#if SWS_DEV
|
||||
Stopwatch sw = new Stopwatch();
|
||||
sw.Start();
|
||||
#endif
|
||||
|
||||
string[] lines = File.ReadAllLines(templatePath);
|
||||
|
||||
if (lines.Length == 0)
|
||||
{
|
||||
Debug.LogError("Failed to generated water shader. Template or file content is empty (or wasn't yet imported)...");
|
||||
return;
|
||||
}
|
||||
|
||||
dependencies.Clear();
|
||||
|
||||
string templateContents = ShaderConfigurator.TemplateParser.CreateShaderCode(context.assetPath, ref lines, this, false);
|
||||
|
||||
Shader shaderAsset = ShaderUtil.CreateShaderAsset(templateContents, true);
|
||||
ShaderUtil.RegisterShader(shaderAsset);
|
||||
|
||||
Texture2D thumbnail = Resources.Load<Texture2D>(ICON_NAME);
|
||||
if(!thumbnail) thumbnail = EditorGUIUtility.IconContent("ShaderImporter Icon").image as Texture2D;
|
||||
|
||||
context.AddObjectToAsset("MainAsset", shaderAsset, thumbnail);
|
||||
context.SetMainObject(shaderAsset);
|
||||
|
||||
//Do not attempt to create a tessellation variant for the underwater post-effect shaders
|
||||
if (settings.type == WaterShaderSettings.ShaderType.WaterSurface)
|
||||
{
|
||||
//Re-read the original template again
|
||||
lines = File.ReadAllLines(templatePath);
|
||||
templateContents = ShaderConfigurator.TemplateParser.CreateShaderCode(context.assetPath, ref lines, this, true);
|
||||
|
||||
Shader tessellation = ShaderUtil.CreateShaderAsset(templateContents, true);
|
||||
//ShaderUtil.RegisterShader(tessellation);
|
||||
|
||||
context.AddObjectToAsset("Tessellation", (Object)tessellation, thumbnail);
|
||||
}
|
||||
|
||||
//Set up dependency, so that changes to the template triggers shaders to regenerate
|
||||
if (HasExternalTemplate() && AssetDatabase.TryGetGUIDAndLocalFileIdentifier(template, out var guid, out long _))
|
||||
{
|
||||
//Note: this strictly only works when adding the file path!
|
||||
//context.DependsOnArtifact(guid);
|
||||
|
||||
dependencies.Insert(0, AssetDatabase.GUIDToAssetPath(guid));
|
||||
}
|
||||
|
||||
//Dependencies are populated during the template parsing phase.
|
||||
foreach (string dependency in dependencies)
|
||||
{
|
||||
context.DependsOnSourceAsset(dependency);
|
||||
}
|
||||
|
||||
#if SWS_DEV
|
||||
sw.Stop();
|
||||
//Debug.Log($"Imported \"{Path.GetFileNameWithoutExtension(assetPath)}\" water shader in {sw.Elapsed.Milliseconds}ms. With {dependencies.Count} dependencies.", shader);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ClearCache(bool recompile = false)
|
||||
{
|
||||
var objs = AssetDatabase.LoadAllAssetsAtPath(assetPath);
|
||||
|
||||
foreach (var obj in objs)
|
||||
{
|
||||
if (obj is Shader)
|
||||
{
|
||||
ShaderUtil.ClearShaderMessages((Shader)obj);
|
||||
ShaderUtil.ClearCachedData((Shader)obj);
|
||||
|
||||
if(recompile) AssetDatabase.ImportAsset(assetPath);
|
||||
|
||||
#if SWS_DEV
|
||||
Debug.Log($"Cleared cache for {obj.name}");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
public void RegisterDependency(string dependencyAssetPath)
|
||||
{
|
||||
if (dependencyAssetPath.StartsWith("Packages/") == false)
|
||||
{
|
||||
string guid = AssetDatabase.AssetPathToGUID(dependencyAssetPath);
|
||||
|
||||
if (guid == string.Empty)
|
||||
{
|
||||
//Also throws an error for things like '#include_library "SurfaceModifiers/SurfaceModifiers.hlsl"', which are wrapped in an #ifdef. That's a false positive
|
||||
//Debug.LogException(new Exception($"Tried to import \"{this.assetPath}\" with an missing dependency, supposedly at path: {dependencyAssetPath}."));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Tessellation variant pass may run, causing the same dependencies to be registered twice, hence check first
|
||||
if(dependencies.Contains(dependencyAssetPath) == false) dependencies.Add(dependencyAssetPath);
|
||||
}
|
||||
|
||||
//Handles correct behaviour when double-clicking a .watershader asset. Should open in the IDE
|
||||
[UnityEditor.Callbacks.OnOpenAsset]
|
||||
public static bool OnOpenAsset(int instanceID, int line)
|
||||
{
|
||||
Object target = EditorUtility.InstanceIDToObject(instanceID);
|
||||
|
||||
if (target is Shader)
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(instanceID);
|
||||
|
||||
if (Path.GetExtension(path) != "." + TARGET_FILE_EXTENSION) return false;
|
||||
|
||||
string externalScriptEditor = ScriptEditorUtility.GetExternalScriptEditor();
|
||||
if (externalScriptEditor != "internal")
|
||||
{
|
||||
InternalEditorUtility.OpenFileAtLineExternal(path, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.OpenURL("file://" + path);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Directive
|
||||
{
|
||||
public enum Type
|
||||
{
|
||||
[InspectorName("(no prefix)")]
|
||||
custom,
|
||||
[InspectorName("#include")]
|
||||
include,
|
||||
[InspectorName("#pragma")]
|
||||
pragma,
|
||||
[InspectorName("#define")]
|
||||
define
|
||||
}
|
||||
public bool enabled = true;
|
||||
public Type type;
|
||||
public string value;
|
||||
|
||||
public Directive(Type _type, string _value)
|
||||
{
|
||||
this.type = _type;
|
||||
this.value = _value;
|
||||
}
|
||||
}
|
||||
|
||||
class WaterShaderAssetPostProcessor : AssetPostprocessor
|
||||
{
|
||||
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
||||
{
|
||||
RegisterShaders(importedAssets);
|
||||
}
|
||||
|
||||
//Register imported water shaders, so they work with Shader.Find() and show up in the shader selection menu
|
||||
private static void RegisterShaders(string[] paths)
|
||||
{
|
||||
foreach (var path in paths)
|
||||
{
|
||||
if (!path.EndsWith(WaterShaderImporter.TARGET_FILE_EXTENSION, StringComparison.InvariantCultureIgnoreCase))
|
||||
continue;
|
||||
|
||||
var mainObj = AssetDatabase.LoadMainAssetAtPath(path);
|
||||
if (mainObj is Shader)
|
||||
{
|
||||
if (mainObj.name == string.Empty) return;
|
||||
|
||||
//ShaderUtil.RegisterShader((Shader)mainObj);
|
||||
|
||||
#if SWS_DEV
|
||||
//Debug.Log($"Registered water shader \"{mainObj.name}\" on import", mainObj);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] FindAllAssets()
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(Application.dataPath);
|
||||
|
||||
FileInfo[] fileInfos = directoryInfo.GetFiles("*." + TARGET_FILE_EXTENSION, SearchOption.AllDirectories);
|
||||
|
||||
#if SWS_DEV
|
||||
Debug.Log($"{fileInfos.Length} .{TARGET_FILE_EXTENSION} assets found");
|
||||
#endif
|
||||
|
||||
string[] filePaths = new string[fileInfos.Length];
|
||||
|
||||
for (int i = 0; i < filePaths.Length; i++)
|
||||
{
|
||||
filePaths[i] = fileInfos[i].FullName.Replace(@"\", "/").Replace(Application.dataPath, "Assets");
|
||||
}
|
||||
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
#if SWS_DEV
|
||||
[MenuItem("SWS/Reimport water shaders")]
|
||||
#endif
|
||||
public static void ReimportAll()
|
||||
{
|
||||
string[] filePaths = FindAllAssets();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
#if SWS_DEV
|
||||
Debug.Log($"Reimporting: {filePath}");
|
||||
#endif
|
||||
AssetDatabase.ImportAsset(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class WaterShaderSettings
|
||||
{
|
||||
[Tooltip("How it will appear in the selection menu")]
|
||||
public string shaderName;
|
||||
[Tooltip("Hide the shader in the selection menu. Yet still make it findable with Shader.Find()")]
|
||||
public bool hidden;
|
||||
public enum ShaderType
|
||||
{
|
||||
WaterSurface,
|
||||
PostProcessing
|
||||
}
|
||||
public ShaderType type;
|
||||
|
||||
[Tooltip("Before compiling the shader, check whichever asset is present in the project and activate its integration")]
|
||||
public bool autoIntegration = true;
|
||||
public ShaderConfigurator.Fog.Assets fogIntegration = ShaderConfigurator.Fog.Assets.UnityFog;
|
||||
|
||||
[Tooltip("Add support for native light cookies. Disabled by default to allow for cookies to act as caustics projectors that ignore the water surface")]
|
||||
public bool lightCookies = false;
|
||||
|
||||
public List<Directive> customIncludeDirectives = new List<Directive>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 531a3ff0802e4acbaef16e2b9d97fd66
|
||||
timeCreated: 1678979614
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "sc.stylizedwater2.editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:93226a8cd37f67d4a996a525146f6f09",
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9",
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
|
||||
"GUID:3eae0364be2026648bf74846acb8a731",
|
||||
"GUID:e40ba710768534012815d3193fa296cb",
|
||||
"GUID:f9fe0089ec81f4079af78eb2287a6163",
|
||||
"GUID:75ecb28acc33857438e533566abcb3be"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.xr.management",
|
||||
"expression": "3.2.10",
|
||||
"define": "XR"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.render-pipelines.universal",
|
||||
"expression": "10.3.2",
|
||||
"define": "URP"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.visualeffectgraph",
|
||||
"expression": "10.3.2",
|
||||
"define": "VFX_GRAPH"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.splines",
|
||||
"expression": "2.0.0",
|
||||
"define": "SPLINES"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0d7a190570d98a42893c25d592fe760
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user