升级水插件

This commit is contained in:
2026-01-31 00:32:49 +08:00
parent a739d2fe3b
commit 4123e83573
293 changed files with 13449 additions and 2853 deletions

View File

@@ -10,14 +10,134 @@ using UnityEngine.UIElements;
namespace WaveHarmonic.Crest.Editor.Settings
{
[FilePath(k_Path, FilePathAttribute.Location.ProjectFolder)]
sealed class ProjectSettings : ScriptableSingleton<ProjectSettings>
[System.Serializable]
class PlatformSettings
{
[SerializeField, HideInInspector]
#pragma warning disable 414
int _Version = 0;
#pragma warning restore 414
const string k_OverrideTooltip = "Override the feature for this platform";
[HideInInspector]
[SerializeField]
internal bool _Default;
[@Heading("Simulations", alwaysVisible: true)]
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideAlbedoSimulation;
[@Label("Albedo")]
[@DecoratedField]
[SerializeField]
internal bool _AlbedoSimulation = true;
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideAbsorptionSimulation;
[@Label("Absorption")]
[@DecoratedField]
[SerializeField]
internal bool _AbsorptionSimulation = true;
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideScatteringSimulation;
[@Label("Scattering")]
[@DecoratedField]
[SerializeField]
internal bool _ScatteringSimulation = true;
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideShadowSimulation;
[@Label("Shadow")]
[@DecoratedField]
[SerializeField]
internal bool _ShadowSimulation = true;
[@Heading("Surface Material", alwaysVisible: true)]
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideNormalMaps;
[@DecoratedField]
[SerializeField]
internal bool _NormalMaps = true;
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverridePlanarReflections;
[@DecoratedField]
[SerializeField]
internal bool _PlanarReflections = true;
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideFoamBioluminescence;
[@DecoratedField]
[SerializeField]
internal bool _FoamBioluminescence = true;
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideCausticsForceDistortion;
[@DecoratedField]
[SerializeField]
internal bool _CausticsForceDistortion = true;
[@Heading("Rendering", alwaysVisible: true)]
[Tooltip(k_OverrideTooltip)]
[@Predicated(nameof(_Default), inverted: true, hide: true)]
[@InlineToggle]
[SerializeField]
internal bool _OverrideSimpleTransparency;
[@DecoratedField]
[SerializeField]
internal bool _SimpleTransparency;
PlatformSettings Default => ProjectSettings.Instance._PlatformSettings;
public bool AlbedoSimulation => _Default || _OverrideAlbedoSimulation ? _AlbedoSimulation : Default.AlbedoSimulation;
public bool AbsorptionSimulation => _Default || _OverrideAbsorptionSimulation ? _AbsorptionSimulation : Default.AbsorptionSimulation;
public bool ScatteringSimulation => _Default || _OverrideScatteringSimulation ? _ScatteringSimulation : Default.ScatteringSimulation;
public bool ShadowSimulation => _Default || _OverrideShadowSimulation ? _ShadowSimulation : Default.ShadowSimulation;
public bool NormalMaps => _Default || _OverrideNormalMaps ? _NormalMaps : Default.NormalMaps;
public bool PlanarReflections => _Default || _OverridePlanarReflections ? _PlanarReflections : Default.PlanarReflections;
public bool FoamBioluminescence => _Default || _OverrideFoamBioluminescence ? _FoamBioluminescence : Default.FoamBioluminescence;
public bool CausticsForceDistortion => _Default || _OverrideCausticsForceDistortion ? _CausticsForceDistortion : Default.CausticsForceDistortion;
public bool SimpleTransparency => _Default || _OverrideSimpleTransparency ? _SimpleTransparency : Default.SimpleTransparency;
}
[FilePath(k_Path, FilePathAttribute.Location.ProjectFolder)]
sealed partial class ProjectSettings : ScriptableSingleton<ProjectSettings>
{
#pragma warning disable IDE0032 // Use auto property
[@Heading("Variant Stripping", Heading.Style.Settings)]
@@ -51,6 +171,86 @@ namespace WaveHarmonic.Crest.Editor.Settings
[@DecoratedField, SerializeField]
bool _LegacyUnderwater;
[@Space(10)]
[@PlatformTabs]
[SerializeField]
internal int _Platforms;
[@Label("Overriden Settings for Windows, Mac and Linux")]
[@Predicated(nameof(_Platforms), inverted: true, (int)BuildTargetGroup.Standalone, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettingsDesktop = new();
[@Label("Overriden Settings for Dedicated Server")]
[@Predicated(nameof(_Platforms), inverted: true, -2, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettingsServer = new();
[@Label("Overriden Settings for Android")]
[@Predicated(nameof(_Platforms), inverted: true, (int)BuildTargetGroup.Android, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettingsAndroid = new();
[@Label("Overriden Settings for iOS")]
[@Predicated(nameof(_Platforms), inverted: true, (int)BuildTargetGroup.iOS, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettingsIOS = new();
[@Label("Overriden Settings for tvOS")]
[@Predicated(nameof(_Platforms), inverted: true, (int)BuildTargetGroup.tvOS, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettingsTVOS = new();
[@Label("Overriden Settings for visionOS")]
[@Predicated(nameof(_Platforms), inverted: true, (int)BuildTargetGroup.VisionOS, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettingsVisionOS = new();
// Web has hard limitations on number of sampled textures. Set defaults with that
// in mind so the surface renders.
[@Label("Overriden Settings for Web")]
[@Predicated(nameof(_Platforms), inverted: true, (int)BuildTargetGroup.WebGL, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettingsWeb = new()
{
_OverrideAbsorptionSimulation = true,
_AbsorptionSimulation = false,
_OverrideAlbedoSimulation = true,
_AlbedoSimulation = false,
_OverrideScatteringSimulation = true,
_ScatteringSimulation = false,
_OverrideShadowSimulation = true,
_ShadowSimulation = false,
_OverrideCausticsForceDistortion = true,
_CausticsForceDistortion = false,
_OverridePlanarReflections = true,
_PlanarReflections = false,
_OverrideFoamBioluminescence = true,
_FoamBioluminescence = false,
};
// This will show if nothing else shows.
[@Label("Default Settings")]
[@Predicated(nameof(_Platforms), inverted: false, (int)BuildTargetGroup.Standalone, hide: true)]
[@Predicated(nameof(_Platforms), inverted: false, Reflected.BuildTargetGroup.k_Server, hide: true)]
[@Predicated(nameof(_Platforms), inverted: false, (int)BuildTargetGroup.Android, hide: true)]
[@Predicated(nameof(_Platforms), inverted: false, (int)BuildTargetGroup.iOS, hide: true)]
[@Predicated(nameof(_Platforms), inverted: false, (int)BuildTargetGroup.WebGL, hide: true)]
[@Predicated(nameof(_Platforms), inverted: false, (int)BuildTargetGroup.tvOS, hide: true)]
[@Predicated(nameof(_Platforms), inverted: false, (int)BuildTargetGroup.VisionOS, hide: true)]
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
[SerializeField]
internal PlatformSettings _PlatformSettings = new() { _Default = true };
#pragma warning restore IDE0032 // Use auto property
internal const string k_Path = "ProjectSettings/Packages/com.waveharmonic.crest/Settings.asset";
@@ -72,6 +272,24 @@ namespace WaveHarmonic.Crest.Editor.Settings
internal bool RenderAtmosphericScatteringWhenUnderWater => _RenderAtmosphericScatteringWhenUnderWater;
internal bool LegacyUnderwater => _LegacyUnderwater;
internal PlatformSettings CurrentPlatformSettings =>
#if PLATFORM_STANDALONE
_PlatformSettingsDesktop;
#elif PLATFORM_SERVER
_PlatformSettingsServer;
#elif PLATFORM_ANDROID
_PlatformSettingsAndroid;
#elif PLATFORM_IOS
_PlatformSettingsIOS;
#elif PLATFORM_TVOS
_PlatformSettingsTVOS;
#elif PLATFORM_VISIONOS
_PlatformSettingsVisionOS;
#else
_PlatformSettings;
#endif
internal bool _IsPlatformTabChange;
void OnEnable()
{
@@ -88,6 +306,14 @@ namespace WaveHarmonic.Crest.Editor.Settings
[@OnChange(skipIfInactive: false)]
void OnChange(string path, object previous)
{
_IsPlatformTabChange = path == nameof(_Platforms);
if (path.StartsWithNoAlloc("_PlatformSettings"))
{
UpdateSymbols();
return;
}
switch (path)
{
case nameof(_FullPrecisionDisplacementOnHalfPrecisionPlatforms):
@@ -101,6 +327,7 @@ namespace WaveHarmonic.Crest.Editor.Settings
void UpdateScriptingSymbols()
{
ScriptingSymbols.Set(ProjectSymbols.k_LegacyUnderwaterScriptingSymbol, _LegacyUnderwater);
ScriptingSymbols.Set(ProjectSymbols.k_SimpleTransparencyScriptingSymbol, CurrentPlatformSettings.SimpleTransparency);
}
void UpdateSymbols()
@@ -112,6 +339,7 @@ namespace WaveHarmonic.Crest.Editor.Settings
sealed class ProjectSymbols : AssetModificationProcessor
{
public const string k_LegacyUnderwaterScriptingSymbol = "d_Crest_LegacyUnderwater";
public const string k_SimpleTransparencyScriptingSymbol = "d_Crest_SimpleTransparency";
static FileSystemWatcher s_Watcher;
@@ -142,6 +370,11 @@ namespace WaveHarmonic.Crest.Editor.Settings
{
EditorApplication.delayCall += () =>
{
if (ProjectSettings.Instance != null && ProjectSettings.Instance._IsPlatformTabChange)
{
return;
}
// Destroy instance to reflect changes.
Helpers.Destroy(Instance);
typeof(ScriptableSingleton<ProjectSettings>)
@@ -220,31 +453,17 @@ namespace WaveHarmonic.Crest.Editor.Settings
return;
}
// Reset foldout values.
DecoratedDrawer.s_IsFoldout = false;
DecoratedDrawer.s_IsFoldoutOpen = false;
EditorGUI.BeginChangeCheck();
// Pad similar to settings header.
var style = new GUIStyle();
style.padding.left = 8;
EditorGUILayout.BeginVertical(style);
// Same label with as other settings.
EditorGUIUtility.labelWidth = 251;
EditorGUILayout.BeginVertical(style);
_Editor.OnInspectorGUI();
EditorGUILayout.EndVertical();
EditorGUI.BeginChangeCheck();
// Commit all changes. Normally settings are written when user hits save or exits
// without any undo/redo entry and dirty state. No idea how to do the same.
// SaveChanges and hasUnsavedChanges on custom editor did not work.
// Not sure if hooking into EditorSceneManager.sceneSaving is correct.
if (EditorGUI.EndChangeCheck())
{
ProjectSettings.Save();
}
_Editor.OnInspectorGUI();
GUILayout.Space(10 * 2);
@@ -256,6 +475,8 @@ namespace WaveHarmonic.Crest.Editor.Settings
AssetDatabase.ImportAsset(path);
}
}
EditorGUILayout.EndVertical();
}
[SettingsProvider]
@@ -272,4 +493,43 @@ namespace WaveHarmonic.Crest.Editor.Settings
return null;
}
}
[CustomEditor(typeof(ProjectSettings))]
class ProjectSettingsEditor : Inspector
{
protected override void OnChange()
{
base.OnChange();
// Commit all changes. Normally settings are written when user hits save or exits
// without any undo/redo entry and dirty state. No idea how to do the same.
// SaveChanges and hasUnsavedChanges on custom editor did not work.
// Not sure if hooking into EditorSceneManager.sceneSaving is correct.
ProjectSettings.Save();
}
}
partial class ProjectSettings : ISerializationCallbackReceiver
{
[SerializeField, HideInInspector]
int _Version = 0;
[SerializeField, HideInInspector]
internal int _MaterialVersion = MaterialUpgrader.k_MaterialVersion;
public void OnAfterDeserialize()
{
if (_Version == 0)
{
_MaterialVersion = 0;
}
_Version = 1;
}
public void OnBeforeSerialize()
{
}
}
}