升级水插件

This commit is contained in:
2026-01-08 22:30:55 +08:00
parent febff82d24
commit ca68084264
415 changed files with 18138 additions and 7134 deletions

View File

@@ -2,6 +2,8 @@
// Copyright © 2024 Wave Harmonic. All rights reserved.
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
@@ -41,9 +43,13 @@ namespace WaveHarmonic.Crest.Editor.Settings
[@DecoratedField, SerializeField]
bool _FullPrecisionDisplacementOnHalfPrecisionPlatforms = true;
[Tooltip("Whether to sample shadow maps for built-in renderer.")]
[Tooltip("Whether to render atmospheric scattering (ie fog) for pixels receiving aquatic scattering (underwater only).\n\nWhen disabled, if a pixel is receiving aquatic scattering, then it will not receive atmospheric scattering.")]
[@DecoratedField, SerializeField]
bool _BuiltInRendererSampleShadowMaps = true;
bool _RenderAtmosphericScatteringWhenUnderWater;
[Tooltip("Renders the underwater effect after transparency and uses the more expensive mask.\n\nYou may need this if rendering the underwater to multiple cameras. The other benefit is that transparent objects will be fogged (albeit incorrectly).\n\nThe downsides are that there can be artifacts if waves are very choppy, has a less impressive meniscus, and generally more expensive to execute.")]
[@DecoratedField, SerializeField]
bool _LegacyUnderwater;
#pragma warning restore IDE0032 // Use auto property
@@ -63,7 +69,8 @@ namespace WaveHarmonic.Crest.Editor.Settings
internal bool LogStrippedVariants => _DebugEnableStrippingLogging && !_DebugOnlyLogRemainingVariants;
internal bool LogKeptVariants => _DebugEnableStrippingLogging && _DebugOnlyLogRemainingVariants;
internal bool FullPrecisionDisplacementOnHalfPrecisionPlatforms => _FullPrecisionDisplacementOnHalfPrecisionPlatforms;
internal bool BuiltInRendererSampleShadowMaps => _BuiltInRendererSampleShadowMaps;
internal bool RenderAtmosphericScatteringWhenUnderWater => _RenderAtmosphericScatteringWhenUnderWater;
internal bool LegacyUnderwater => _LegacyUnderwater;
void OnEnable()
@@ -83,12 +90,83 @@ namespace WaveHarmonic.Crest.Editor.Settings
{
switch (path)
{
case nameof(_BuiltInRendererSampleShadowMaps):
case nameof(_FullPrecisionDisplacementOnHalfPrecisionPlatforms):
ShaderSettingsGenerator.Generate();
case nameof(_RenderAtmosphericScatteringWhenUnderWater):
case nameof(_LegacyUnderwater):
UpdateSymbols();
break;
}
}
void UpdateScriptingSymbols()
{
ScriptingSymbols.Set(ProjectSymbols.k_LegacyUnderwaterScriptingSymbol, _LegacyUnderwater);
}
void UpdateSymbols()
{
UpdateScriptingSymbols();
ShaderSettingsGenerator.Generate();
}
sealed class ProjectSymbols : AssetModificationProcessor
{
public const string k_LegacyUnderwaterScriptingSymbol = "d_Crest_LegacyUnderwater";
static FileSystemWatcher s_Watcher;
// Will run on load and recompile preventing symbol removal in player settings.
[InitializeOnLoadMethod]
static void OnLoad()
{
if (Instance != null)
{
Instance.UpdateScriptingSymbols();
}
Directory.CreateDirectory(Path.GetDirectoryName(k_Path));
s_Watcher = new(Path.GetDirectoryName(k_Path))
{
Filter = Path.GetFileName(k_Path),
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size,
EnableRaisingEvents = true
};
s_Watcher.Changed -= OnChanged;
s_Watcher.Changed += OnChanged;
}
// Handle external edits. Possibly unreliable, but not important if fails.
static void OnChanged(object sender, FileSystemEventArgs e)
{
EditorApplication.delayCall += () =>
{
// Destroy instance to reflect changes.
Helpers.Destroy(Instance);
typeof(ScriptableSingleton<ProjectSettings>)
.GetField("s_Instance", BindingFlags.Static | BindingFlags.NonPublic)
.SetValue(null, null);
Instance.UpdateSymbols();
};
}
static AssetDeleteResult OnWillDeleteAsset(string path, RemoveAssetOptions options)
{
// Only remove symbols if this file is deleted.
if (Path.GetFullPath(path) == GetCurrentFileName())
{
ScriptingSymbols.Remove(ScriptingSymbols.Symbols.Where(x => x.StartsWith("d_Crest_")).ToArray());
}
return AssetDeleteResult.DidNotDelete;
}
static string GetCurrentFileName([System.Runtime.CompilerServices.CallerFilePath] string fileName = null)
{
return fileName;
}
}
}
sealed class SettingsProvider : UnityEditor.SettingsProvider