diff --git a/Assets/Scripts/Editor/PrivateAssetBuildGuard.cs b/Assets/Scripts/Editor/PrivateAssetBuildGuard.cs new file mode 100644 index 00000000..e2c5c5cd --- /dev/null +++ b/Assets/Scripts/Editor/PrivateAssetBuildGuard.cs @@ -0,0 +1,61 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2025, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Editor +{ + using System; + using System.Linq; + using UnityEditor; + using UnityEditor.Build; + using UnityEditor.Build.Reporting; + + internal sealed class PrivateAssetBuildGuard : IPreprocessBuildWithReport + { + private const string PrivateBuildVariable = "PAL3_ALLOW_PRIVATE_ASSETS"; + private const string StoryVfxPath = "/Resources/Prefabs/VFX/"; + private const string HovlStudioPath = "/Hovl Studio/"; + private const string RealToonPath = "/RealToon/"; + private const string LegacyToonMaterialsPath = "Assets/Resources/Materials/"; + private const string Pal3VfxReadme = "Assets/Resources/Prefabs/VFX/PAL3/README.txt"; + private const string Pal3AVfxReadme = "Assets/Resources/Prefabs/VFX/PAL3A/README.txt"; + + internal static bool PrivateBuildEnabled => + Environment.GetEnvironmentVariable(PrivateBuildVariable) == "1" && + string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")) && + string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS")); + + public int callbackOrder => int.MaxValue; + + public void OnPreprocessBuild(BuildReport report) => Validate(); + + internal static void Validate() + { + if (PrivateBuildEnabled) return; + + string privateAsset = AssetDatabase.GetAllAssetPaths().FirstOrDefault(IsPrivateAsset); + if (privateAsset == null) return; + + throw new BuildFailedException( + $"Local optional VFX or legacy Toon assets are installed ({privateAsset}). " + + "Use a clean checkout for public builds. " + + $"For a private local build, launch Unity with {PrivateBuildVariable}=1."); + } + + private static bool IsPrivateAsset(string assetPath) + { + if (assetPath.IndexOf(HovlStudioPath, StringComparison.OrdinalIgnoreCase) < 0 && + assetPath.IndexOf(RealToonPath, StringComparison.OrdinalIgnoreCase) < 0 && + !assetPath.StartsWith(LegacyToonMaterialsPath, StringComparison.OrdinalIgnoreCase) && + assetPath.IndexOf(StoryVfxPath, StringComparison.OrdinalIgnoreCase) < 0) + { + return false; + } + + return !assetPath.Equals(Pal3VfxReadme, StringComparison.OrdinalIgnoreCase) && + !assetPath.Equals(Pal3AVfxReadme, StringComparison.OrdinalIgnoreCase) && + !AssetDatabase.IsValidFolder(assetPath); + } + } +} diff --git a/Assets/Scripts/Editor/PrivateAssetBuildGuard.cs.meta b/Assets/Scripts/Editor/PrivateAssetBuildGuard.cs.meta new file mode 100644 index 00000000..d47c922a --- /dev/null +++ b/Assets/Scripts/Editor/PrivateAssetBuildGuard.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: ac41b9b3ac5641d98126273f7efb452f diff --git a/Assets/Scripts/Editor/ReleaseBuildPipeline.cs b/Assets/Scripts/Editor/ReleaseBuildPipeline.cs index 4dbb29ce..9f048948 100644 --- a/Assets/Scripts/Editor/ReleaseBuildPipeline.cs +++ b/Assets/Scripts/Editor/ReleaseBuildPipeline.cs @@ -131,13 +131,16 @@ namespace Editor private static void BuildGame(Pal3BuildTarget buildTarget) { + PrivateAssetBuildGuard.Validate(); + BuildTargetGroup targetGroupBeforeBuild = EditorUserBuildSettings.selectedBuildTargetGroup; BuildTarget targetBeforeBuild = EditorUserBuildSettings.activeBuildTarget; string buildOutputPath = EditorUtility.SaveFolderPanel("Choose Location of Built Game", "", ""); if (string.IsNullOrWhiteSpace(buildOutputPath)) return; - buildOutputPath += $"{DirSeparator}{PlayerSettings.bundleVersion}{DirSeparator}"; + string versionFolder = GetVersionFolderName(PrivateAssetBuildGuard.PrivateBuildEnabled); + buildOutputPath += $"{DirSeparator}{versionFolder}{DirSeparator}"; var buildConfigurations = new[] { @@ -268,16 +271,30 @@ namespace Editor } } + private static string GetVersionFolderName(bool privateBuild) + { + return PlayerSettings.bundleVersion + (privateBuild ? "-Private" : ""); + } + private static void ZipReleaseFiles() { + string versionFolder = GetVersionFolderName(PrivateAssetBuildGuard.PrivateBuildEnabled); string buildOutputPath = EditorUtility.SaveFolderPanel("Choose Location of Built Game", - $"{PlayerSettings.bundleVersion}", $"{PlayerSettings.bundleVersion}"); + versionFolder, versionFolder); if (string.IsNullOrWhiteSpace(buildOutputPath)) return; + ZipReleaseFiles(buildOutputPath); + } - if (!buildOutputPath.EndsWith($"{PlayerSettings.bundleVersion}")) + private static void ZipReleaseFiles(string buildOutputPath) + { + string selectedFolder = Path.GetFileName(buildOutputPath.TrimEnd( + Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); + bool privateBuild = selectedFolder == GetVersionFolderName(true); + if (!privateBuild && selectedFolder != GetVersionFolderName(false)) { Debug.LogError($"Invalid build output path: {buildOutputPath}. " + - $"Please choose the current release build folder \"{PlayerSettings.bundleVersion}\""); + $"Please choose the current release build folder \"{GetVersionFolderName(false)}\" " + + $"or \"{GetVersionFolderName(true)}\"."); return; } @@ -296,7 +313,7 @@ namespace Editor foreach ((string folderPath, Pal3BuildTarget target) in buildTargets) { string fullPath = $"{buildOutputPath}{DirSeparator}{folderPath}"; - string zipFileName = $"{GameConstants.AppName}_v{PlayerSettings.bundleVersion}_{target.ToString()}.zip"; + string zipFileName = $"{GameConstants.AppName}_v{GetVersionFolderName(privateBuild)}_{target.ToString()}.zip"; string zipFilePath = $"{releaseDirPath}{DirSeparator}{zipFileName}"; if (File.Exists(fullPath) || Directory.Exists(fullPath)) diff --git a/Assets/Scripts/Pal3.Game/Data/GameResourceProvider.cs b/Assets/Scripts/Pal3.Game/Data/GameResourceProvider.cs index cc6b0a89..9dc243cf 100644 --- a/Assets/Scripts/Pal3.Game/Data/GameResourceProvider.cs +++ b/Assets/Scripts/Pal3.Game/Data/GameResourceProvider.cs @@ -25,6 +25,7 @@ namespace Pal3.Game.Data using Core.DataReader.Mv3; using Core.FileSystem; using Core.Utilities; + using Effect; using Engine.Core.Abstraction; using Engine.Core.Implementation; using Engine.DataLoader; @@ -61,12 +62,13 @@ namespace Pal3.Game.Data private readonly Dictionary _spriteCache = new (); private readonly Dictionary _audioClipCache = new (); - private readonly Dictionary _vfxEffectPrefabCache = new (); private readonly Dictionary> _gameResourceFileCache = new (); private readonly int _codepage; + internal OptionalVfxPlayer OptionalVfx { get; } + public GameResourceProvider(ICpkFileSystem fileSystem, ITextureLoaderFactory textureLoaderFactory, ITextureFactory textureFactory, @@ -81,6 +83,7 @@ namespace Pal3.Game.Data _codepage = _gameSettings.Language == Language.SimplifiedChinese ? 936 : 950; _gameDatabase = GetGameDatabaseFile(); // Initialize game database file + OptionalVfx = new OptionalVfxPlayer(_gameSettings); CommandExecutorRegistry.Instance.Register(this); } @@ -109,7 +112,7 @@ namespace Pal3.Game.Data } _audioClipCache.Clear(); - _vfxEffectPrefabCache.Clear(); + OptionalVfx.Dispose(); _materialManager.Dispose(); @@ -515,59 +518,6 @@ namespace Pal3.Game.Data return Array.Empty<(ITexture2D, bool)>(); } - private string GetVfxPrefabPath(int effectGroupId) - { - return $"Prefabs/VFX/{GameConstants.AppName}/{effectGroupId}"; - } - - public object GetVfxEffectPrefab(int effectGroupId) - { - if (!_gameSettings.OptionalVfxEnabled) return null; - - if (_vfxEffectPrefabCache.TryGetValue(effectGroupId, out UnityEngine.Object vfxEffectPrefab)) - { - return vfxEffectPrefab; - } - - UnityEngine.Object vfxPrefab = Resources.Load(GetVfxPrefabPath(effectGroupId)); - - if (vfxPrefab == null) - { - EngineLogger.LogWarning($"VFX prefab not found: {effectGroupId}"); - } - - _vfxEffectPrefabCache[effectGroupId] = vfxPrefab; - return vfxPrefab; - } - - public IEnumerator PreLoadVfxEffectAsync(int effectGroupId) - { - if (!_gameSettings.OptionalVfxEnabled) yield break; - - if (_vfxEffectPrefabCache.ContainsKey(effectGroupId)) - { - yield break; - } - - ResourceRequest request = Resources.LoadAsync(GetVfxPrefabPath(effectGroupId)); - - while (!request.isDone) - { - yield return request; - } - - if (request.asset == null) - { - EngineLogger.LogWarning($"VFX prefab not found: {effectGroupId}"); - } - else - { - EngineLogger.Log($"VFX prefab preloaded: {effectGroupId}"); - } - - _vfxEffectPrefabCache[effectGroupId] = request.asset; - } - public ITexture2D GetCursorTexture() { string cursorSpriteRelativePath = FileConstants.CursorSpriteFolderVirtualPath; @@ -640,8 +590,7 @@ namespace Pal3.Game.Data } } - // clear all vfx prefabs in cache - _vfxEffectPrefabCache.Clear(); + OptionalVfx.ClearPrefabCache(); } } diff --git a/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs b/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs index da8a9432..2ec48fca 100644 --- a/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs +++ b/Assets/Scripts/Pal3.Game/Effect/CombatEffect.cs @@ -5,8 +5,8 @@ namespace Pal3.Game.Effect { + using System; using Data; - using Engine.Core.Abstraction; using Engine.Core.Implementation; using Engine.Extensions; @@ -32,7 +32,7 @@ namespace Pal3.Game.Effect private RotatingSpriteEffect _bridgeBaseEffect; private RotatingSpriteEffect _bridgeEffect; - private IGameEntity _effect; + private IDisposable _effect; protected override void OnDisableGameEntity() { @@ -41,14 +41,6 @@ namespace Pal3.Game.Effect public void Init(GameResourceProvider resourceProvider, uint effectParameter) { - // object vfxPrefab = resourceProvider.GetVfxEffectPrefab((int)effectParameter); - // - // if (vfxPrefab != null) - // { - // _effect = PrefabFactory.Instantiate(vfxPrefab, Transform, worldPositionStays: false); - // _effect.Name = "VFX_" + effectParameter; - // } - #if PAL3 if (effectParameter == 465) // 蜀山太极桥特效 #elif PAL3A @@ -78,15 +70,12 @@ namespace Pal3.Game.Effect if (effectParameter == 344) // 重盘古元灵特效 #endif { - object vfxPrefab = resourceProvider.GetVfxEffectPrefab((int)effectParameter); - if (vfxPrefab != null) - { - _effect = GameEntityFactory.Create(name: $"VFX_{effectParameter}", - vfxPrefab, GameEntity, worldPositionStays: false); - } + _effect = resourceProvider.OptionalVfx.Attach((int)effectParameter, GameEntity); } } + private void OnDestroy() => Dispose(); + public void Dispose() { if (_bridgeBaseEffect != null) @@ -103,11 +92,8 @@ namespace Pal3.Game.Effect _bridgeEffect = null; } - if (_effect != null) - { - _effect.Destroy(); - _effect = null; - } + _effect?.Dispose(); + _effect = null; } } } \ No newline at end of file diff --git a/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs b/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs index 597f51f1..a1439b96 100644 --- a/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs +++ b/Assets/Scripts/Pal3.Game/Effect/EffectManager.cs @@ -17,8 +17,6 @@ namespace Pal3.Game.Effect using Core.Primitives; using Core.Utilities; using Data; - using Engine.Core.Abstraction; - using Engine.Core.Implementation; using Engine.Extensions; using Scene; @@ -32,7 +30,7 @@ namespace Pal3.Game.Effect ICommandExecutor, ICommandExecutor { - private readonly GameResourceProvider _resourceProvider; + private readonly OptionalVfxPlayer _optionalVfx; private readonly SceneManager _sceneManager; private ICommand _effectPositionCommand; @@ -42,10 +40,10 @@ namespace Pal3.Game.Effect public EffectManager(GameResourceProvider resourceProvider, SceneManager sceneManager) { - _resourceProvider = Requires.IsNotNull(resourceProvider, nameof(resourceProvider)); + _optionalVfx = Requires.IsNotNull(resourceProvider, nameof(resourceProvider)).OptionalVfx; _sceneManager = Requires.IsNotNull(sceneManager, nameof(sceneManager)); - _effectLinkerFile = _resourceProvider.GetGameResourceFile( + _effectLinkerFile = resourceProvider.GetGameResourceFile( FileConstants.CombatDataFolderVirtualPath + EFFECT_LINKER_FILE_NAME); CommandExecutorRegistry.Instance.Register(this); @@ -54,7 +52,7 @@ namespace Pal3.Game.Effect public void Dispose() { CommandExecutorRegistry.Instance.UnRegister(this); - _effectPositionCommand = null; + ClearSceneEffects(); } public void Execute(EffectPreLoadCommand command) @@ -64,7 +62,7 @@ namespace Pal3.Game.Effect // Even with a waiter, we need to make sure waiter's current execution mode is set // to synchronous otherwise the effect will be played before the pre-load is finished. #if PAL3 - Pal3.Instance.StartCoroutine(_resourceProvider.PreLoadVfxEffectAsync(command.EffectGroupId)); + Pal3.Instance.StartCoroutine(_optionalVfx.PreloadAsync(command.EffectGroupId)); #endif } @@ -80,33 +78,20 @@ namespace Pal3.Game.Effect } #endif - // Play VFX - object vfxPrefab = _resourceProvider.GetVfxEffectPrefab(command.EffectGroupId); - if (vfxPrefab != null) + if (_effectPositionCommand is EffectSetPositionCommand positionCommand) { - IGameEntity parent = null; - Vector3 localPosition = Vector3.zero; + Vector3 localPosition = new GameBoxVector3( + positionCommand.GameBoxXPosition, + positionCommand.GameBoxYPosition, + positionCommand.GameBoxZPosition).ToUnityPosition(); - if (_effectPositionCommand is EffectSetPositionCommand positionCommand && - _sceneManager.GetSceneRootGameEntity() is {} sceneRootGameEntity) - { - parent = sceneRootGameEntity; - localPosition = new GameBoxVector3( - positionCommand.GameBoxXPosition, - positionCommand.GameBoxYPosition, - positionCommand.GameBoxZPosition).ToUnityPosition(); - } - else if (_effectPositionCommand is EffectAttachToActorCommand actorCommand) - { - parent = currentScene.GetActorGameEntity(actorCommand.ActorId); - } - - if (!parent.IsNullOrDisposed()) - { - IGameEntity effectEntity = GameEntityFactory.Create(name: $"VFX_{command.EffectGroupId}", - vfxPrefab, parent, worldPositionStays: false); - effectEntity.Transform.LocalPosition += localPosition; - } + _optionalVfx.Play(command.EffectGroupId, + _sceneManager.GetSceneRootGameEntity(), localPosition); + } + else if (_effectPositionCommand is EffectAttachToActorCommand actorCommand) + { + _optionalVfx.Play(command.EffectGroupId, + currentScene.GetActorGameEntity(actorCommand.ActorId), Vector3.zero); } // Play SFX if any @@ -159,8 +144,14 @@ namespace Pal3.Game.Effect public void Execute(EffectAttachToActorCommand command) => _effectPositionCommand = command; - public void Execute(SceneLeavingCurrentSceneNotification command) => _effectPositionCommand = null; + public void Execute(SceneLeavingCurrentSceneNotification command) => ClearSceneEffects(); - public void Execute(ResetGameStateCommand command) => _effectPositionCommand = null; + public void Execute(ResetGameStateCommand command) => ClearSceneEffects(); + + private void ClearSceneEffects() + { + _effectPositionCommand = null; + _optionalVfx.ClearPlayedEffects(); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Pal3.Game/Effect/OptionalVfxPlayer.cs b/Assets/Scripts/Pal3.Game/Effect/OptionalVfxPlayer.cs new file mode 100644 index 00000000..0ffe4a5e --- /dev/null +++ b/Assets/Scripts/Pal3.Game/Effect/OptionalVfxPlayer.cs @@ -0,0 +1,198 @@ +// --------------------------------------------------------------------------------------------- +// Copyright (c) 2021-2025, Jiaqi (0x7c13) Liu. All rights reserved. +// See LICENSE file in the project root for license information. +// --------------------------------------------------------------------------------------------- + +namespace Pal3.Game.Effect +{ + using System; + using System.Collections; + using System.Collections.Generic; + using Constants; + using Engine.Core.Abstraction; + using Engine.Core.Implementation; + using Engine.Extensions; + using Engine.Logging; + using Settings; + using UnityEngine; + + internal sealed class OptionalVfxPlayer : IDisposable + { + private readonly GameSettings _settings; + private readonly Dictionary _prefabs = new(); + private readonly List _playedEffects = new(); + private readonly List _persistentEffects = new(); + + private int _prefabCacheGeneration; + private bool _disposed; + private bool IsEnabled => !_disposed && _settings.OptionalVfxEnabled; + + internal OptionalVfxPlayer(GameSettings settings) + { + _settings = settings; + _settings.OnGameSettingsChanged += OnGameSettingsChanged; + } + + private static string GetPrefabPath(int effectGroupId) => $"Prefabs/VFX/{GameConstants.AppName}/{effectGroupId}"; + + internal IEnumerator PreloadAsync(int effectGroupId) + { + if (!IsEnabled || _prefabs.ContainsKey(effectGroupId)) yield break; + + int generation = _prefabCacheGeneration; + ResourceRequest request = Resources.LoadAsync(GetPrefabPath(effectGroupId)); + yield return request; + + if (IsEnabled && generation == _prefabCacheGeneration && !_prefabs.ContainsKey(effectGroupId)) + { + CachePrefab(effectGroupId, request.asset as GameObject); + } + } + + private void CachePrefab(int effectGroupId, GameObject prefab) + { + _prefabs[effectGroupId] = prefab; + if (prefab == null) + { + EngineLogger.LogWarning($"VFX prefab not found: {effectGroupId}"); + } + } + + private IGameEntity Create(int effectGroupId, IGameEntity parent) + { + if (!IsEnabled || parent.IsNullOrDisposed()) return null; + + if (!_prefabs.TryGetValue(effectGroupId, out GameObject prefab)) + { + prefab = Resources.Load(GetPrefabPath(effectGroupId)); + CachePrefab(effectGroupId, prefab); + } + + return prefab == null ? null : + GameEntityFactory.Create($"VFX_{effectGroupId}", prefab, parent, worldPositionStays: false); + } + + internal void Play(int effectGroupId, IGameEntity parent, Vector3 localPosition) + { + if (Create(effectGroupId, parent) is not {} instance) return; + + instance.Transform.LocalPosition += localPosition; + _playedEffects.RemoveAll(effect => effect.IsNativeObjectDisposed); + _playedEffects.Add(instance); + } + + internal IDisposable Attach(int effectGroupId, IGameEntity parent) + { + if (_disposed || parent.IsNullOrDisposed()) return null; + PruneDeadAttachments(); + var effect = new PersistentEffect(this, effectGroupId, parent); + _persistentEffects.Add(effect); + effect.Refresh(); + return effect; + } + + private void OnGameSettingsChanged(string propertyName) + { + if (propertyName != nameof(GameSettings.OptionalVfxEnabled)) return; + + if (!IsEnabled) ClearPlayedEffects(); + + foreach (PersistentEffect effect in _persistentEffects.ToArray()) + { + effect.Refresh(); + } + } + + internal void ClearPlayedEffects() + { + foreach (IGameEntity effect in _playedEffects) + { + Stop(effect); + } + _playedEffects.Clear(); + } + + private static void Stop(IGameEntity effect) + { + if (effect.IsNullOrDisposed()) return; + + // Destroy is deferred to the end of the frame. + ((GameObject)effect.NativeObject).SetActive(false); + effect.Destroy(); + } + + private void PruneDeadAttachments() + { + for (int i = _persistentEffects.Count - 1; i >= 0; i--) + { + if (_persistentEffects[i].ParentIsDisposed) _persistentEffects[i].Dispose(); + } + } + + internal void ClearPrefabCache() + { + PruneDeadAttachments(); + _prefabCacheGeneration++; + _prefabs.Clear(); + } + + public void Dispose() + { + _disposed = true; + _settings.OnGameSettingsChanged -= OnGameSettingsChanged; + ClearPlayedEffects(); + + foreach (PersistentEffect effect in _persistentEffects.ToArray()) + { + effect.Dispose(); + } + ClearPrefabCache(); + } + + private sealed class PersistentEffect : IDisposable + { + private readonly OptionalVfxPlayer _player; + private readonly int _effectGroupId; + private readonly IGameEntity _parent; + private IGameEntity _instance; + private bool _disposed; + + internal PersistentEffect(OptionalVfxPlayer player, int effectGroupId, IGameEntity parent) + { + _player = player; + _effectGroupId = effectGroupId; + _parent = parent; + } + + internal bool ParentIsDisposed => _parent.IsNullOrDisposed(); + + internal void Refresh() + { + if (_disposed) return; + if (ParentIsDisposed) + { + Dispose(); + return; + } + + if (_player.IsEnabled) + { + if (_instance.IsNullOrDisposed()) _instance = _player.Create(_effectGroupId, _parent); + } + else + { + Stop(_instance); + _instance = null; + } + } + + public void Dispose() + { + _disposed = true; + _player._persistentEffects.Remove(this); + Stop(_instance); + _instance = null; + } + } + } +} diff --git a/Assets/Scripts/Pal3.Game/Effect/OptionalVfxPlayer.cs.meta b/Assets/Scripts/Pal3.Game/Effect/OptionalVfxPlayer.cs.meta new file mode 100644 index 00000000..30b395ad --- /dev/null +++ b/Assets/Scripts/Pal3.Game/Effect/OptionalVfxPlayer.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 476922aa1f964e19b6cc16895511908c diff --git a/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs b/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs index 11099958..66960217 100644 --- a/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs +++ b/Assets/Scripts/Pal3.Game/Effect/PortalEffect.cs @@ -5,8 +5,8 @@ namespace Pal3.Game.Effect { + using System; using Data; - using Engine.Core.Abstraction; using Engine.Core.Implementation; using Engine.Extensions; @@ -25,7 +25,7 @@ namespace Pal3.Game.Effect private const int PORTAL_RAY_EFFECT_ID = 0; private RotatingSpriteEffect _baseEffect; - private IGameEntity _rayEffect; + private IDisposable _rayEffect; protected override void OnDisableGameEntity() { @@ -40,14 +40,11 @@ namespace Pal3.Game.Effect new Vector3(PORTAL_DEFAULT_SIZE, PORTAL_DEFAULT_SIZE, PORTAL_DEFAULT_SIZE), PORTAL_ANIMATION_ROTATION_SPEED); - object rayEffectPrefab = resourceProvider.GetVfxEffectPrefab(PORTAL_RAY_EFFECT_ID); - if (rayEffectPrefab != null) - { - _rayEffect = GameEntityFactory.Create($"VFX_{PORTAL_RAY_EFFECT_ID}", - rayEffectPrefab, GameEntity, worldPositionStays: false); - } + _rayEffect = resourceProvider.OptionalVfx.Attach(PORTAL_RAY_EFFECT_ID, GameEntity); } + private void OnDestroy() => Dispose(); + public void Dispose() { if (_baseEffect != null) @@ -57,11 +54,8 @@ namespace Pal3.Game.Effect _baseEffect = null; } - if (_rayEffect != null) - { - _rayEffect.Destroy(); - _rayEffect = null; - } + _rayEffect?.Dispose(); + _rayEffect = null; } } } \ No newline at end of file diff --git a/README.en-US.md b/README.en-US.md index a4e01102..1c2058d3 100644 --- a/README.en-US.md +++ b/README.en-US.md @@ -71,7 +71,9 @@ Both games default to the original visual style in URP, preserving the original The visual effects settings provide independent switches for contact shadows, character lighting, enhanced night fire lighting, and night fire shadows. Contact shadows and fire shadows default to enabled on desktop devices. Enhanced fire lighting combines warm lights with a cool ambient tone. At most one fire casts real-time shadows. Bloom has a separate switch and defaults to enabled only for the original style on desktop. -The screenshots above show the previous toon renderer. Optional story VFX load numbered prefabs from `Assets/Resources/Prefabs/VFX/PAL3/` or `PAL3A/`. Install URP-compatible versions locally, then enable optional story VFX in the visual effects settings. Use a fresh checkout without optional assets for public builds. +The screenshots above show the previous toon renderer. Optional story VFX are off by default. Install URP-compatible numbered prefabs locally in `Assets/Resources/Prefabs/VFX/PAL3/` or `Assets/Resources/Prefabs/VFX/PAL3A/`, then enable optional story VFX in the visual effects settings. Turning the setting off hides active optional effects immediately. Turning it back on restores persistent effects in the current scene and shows newly triggered story effects. + +Use a fresh checkout for public builds. Unity blocks player builds when it finds local optional VFX prefabs, Hovl Studio assets, RealToon assets, or legacy toon materials. To build for private use, launch your local Unity editor with `PAL3_ALLOW_PRIVATE_ASSETS=1`. The project build menu places these builds in a version folder with the `-Private` suffix. ## Controls - Mouse and keyboard: Left mouse button to click and control character movement (arrow keys can also be used), A/D to control camera rotation, Spacebar to interact with nearby items or NPCs (also used as the jump button when available), M key to toggle the big map, U key or ESC key to open the story selection menu, Tab key to switch characters (in the maze). diff --git a/README.md b/README.md index a821b435..61f54228 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,9 @@ 「游戏设置 → 画面与特效设置」提供接触阴影、角色光照、增强夜景火光和夜景火光投影四个独立开关,在卡通画风中即时生效。接触阴影和火光投影在桌面设备默认开启,手持设备可按需开启。夜景火光使用暖色灯光与冷色环境底色,最多一盏火光投射实时阴影。泛光可以独立开关,默认仅桌面原版画风开启。 -上方截图来自旧版卡通渲染。可选剧情特效支持从 `Assets/Resources/Prefabs/VFX/PAL3/` 或 `PAL3A/` 加载编号预制体。请在本地安装与 URP 兼容的版本,再启用「可选剧情特效」。公开构建请使用未导入可选素材的全新检出。 +上方截图来自旧版卡通渲染。可选剧情特效默认关闭。请在本地安装与 URP 兼容的编号预制体到 `Assets/Resources/Prefabs/VFX/PAL3/` 或 `Assets/Resources/Prefabs/VFX/PAL3A/`,再启用「可选剧情特效」。关闭时会立即隐藏当前可选特效。重新启用后,仍在场景中的持续特效会恢复,后续触发的剧情特效会照常显示。 + +公开构建请使用未导入本地付费素材的全新检出。若工程中有可选特效预制体、Hovl Studio、RealToon 或旧版卡通材质,Unity 会阻止构建。仅供个人使用的构建可通过环境变量 `PAL3_ALLOW_PRIVATE_ASSETS=1` 启动本地 Unity 来显式启用。工程打包菜单会将这类构建输出到带 `-Private` 后缀的版本目录。 ## 按键以及操作 - 鼠标键盘:鼠标左键点击操作人物行走方向(键盘方向键也可以),AD控制镜头旋转,空格与周边附近的物品或者NPC交互(也是跳跃键),M键打开大地图,U键或ESC键打开剧情选择菜单,Tab键切换角色(迷宫中)。