多轮审查和修复

This commit is contained in:
2026-05-12 15:34:08 +08:00
parent f55d2a57c3
commit ebbbb7332e
805 changed files with 838724 additions and 1905 deletions

View File

@@ -0,0 +1,79 @@
using UnityEngine;
using BaseGames.Core.Events;
using BaseGames.Core.Save;
namespace BaseGames.Core
{
/// <summary>
/// 难度管理器(单例 MonoBehaviour
/// 统一管理当前难度档位,并通过事件频道广播变化。
/// 订阅者通过 <see cref="CurrentScaler"/> 获取具体缩放数值。
/// </summary>
[DefaultExecutionOrder(-900)]
public class DifficultyManager : MonoBehaviour, ISaveable, IDifficultyService
{
[SerializeField] private DifficultyScalerSO[] _allScalers;
[SerializeField] private DifficultyChangedEventChannel _onDifficultyChanged;
public DifficultyLevel CurrentLevel { get; private set; } = DifficultyLevel.Normal;
public DifficultyScalerSO CurrentScaler { get; private set; }
private void Awake()
{
if (ServiceLocator.GetOrDefault<IDifficultyService>() != null) { Destroy(gameObject); return; }
ServiceLocator.Register<IDifficultyService>(this);
Apply(DifficultyLevel.Normal);
ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Register(this);
}
private void OnDestroy()
{
ServiceLocator.Unregister<IDifficultyService>(this);
ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Unregister(this);
}
/// <summary>
/// 在游戏流程中切换难度。
/// SteelSoul 模式一旦选定,中途无法降级。
/// </summary>
public void ChangeDifficulty(DifficultyLevel level)
{
if (CurrentLevel == DifficultyLevel.SteelSoul && level != DifficultyLevel.SteelSoul)
{
Debug.LogWarning("[DifficultyManager] SteelSoul 模式无法在游戏中途降级。");
return;
}
Apply(level);
}
/// <summary>按档位查找对应的缩放器,未配置时返回 null。</summary>
public DifficultyScalerSO GetScaler(DifficultyLevel level)
{
if (_allScalers == null) return null;
foreach (var s in _allScalers)
if (s != null && s.Level == level) return s;
return null;
}
private void Apply(DifficultyLevel level)
{
CurrentLevel = level;
CurrentScaler = GetScaler(level);
_onDifficultyChanged?.Raise(CurrentLevel);
}
// ── ISaveable ────────────────────────────────────────────────────────
public void OnSave(SaveData saveData)
{
if (saveData?.Meta != null)
saveData.Meta.IsSteelSoul = CurrentLevel == DifficultyLevel.SteelSoul;
}
public void OnLoad(SaveData saveData)
{
if (saveData?.Meta != null && saveData.Meta.IsSteelSoul)
Apply(DifficultyLevel.SteelSoul);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a810da0a9739024d90a4f7415aeb2a6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
using UnityEngine;
using BaseGames.Core.Events;
namespace BaseGames.Core
{
/// <summary>
/// 难度缩放配置 ScriptableObject。每个难度档位对应一个实例。
/// </summary>
[CreateAssetMenu(menuName = "Core/DifficultyScaler")]
public class DifficultyScalerSO : ScriptableObject
{
[Header("标识")]
public DifficultyLevel Level;
[Header("玩家")]
public float PlayerMaxHPMultiplier = 1.0f;
public float PlayerDamageMultiplier = 1.0f;
public float InvincibilityFrameScale = 1.0f;
[Header("敌人")]
public float EnemyDamageMultiplier = 1.0f;
public float EnemyHPMultiplier = 1.0f;
public float BossDamageMultiplier = 1.0f;
public float BossHPMultiplier = 1.0f;
[Header("经济")]
public float ShopPriceMultiplier = 1.0f;
public float GeoDropMultiplier = 1.0f;
[Header("机制")]
public bool CanReviveWithGeoLoss = true;
public bool InstantDeathOnZeroHP = false;
public bool GeoPenaltyOnDeath = true;
[Header("AI")]
public float EnemyAttackIntervalScale = 1.0f;
public float EnemyAggroRangeScale = 1.0f;
public float EnemyReactionTimeScale = 1.0f;
public int EnemyAggressionLevel = 2;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d7e8ad48b35397348a800079849ee535
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
namespace BaseGames.Core
{
/// <summary>
/// 难度服务接口(架构 §DifficultyModule
/// 提供当前难度档位及缩放参数,供跨程序集的游戏系统(战斗、商店、掉落等)查询,
/// 无需直接依赖 <see cref="DifficultyManager"/> 具体类型。
/// </summary>
public interface IDifficultyService
{
/// <summary>当前难度档位。</summary>
DifficultyLevel CurrentLevel { get; }
/// <summary>当前档位对应的缩放配置。未配置时返回 null。</summary>
DifficultyScalerSO CurrentScaler { get; }
/// <summary>切换到指定难度。SteelSoul 模式一旦选定不可降级。</summary>
void ChangeDifficulty(DifficultyLevel level);
/// <summary>按档位查找缩放器,未配置时返回 null。</summary>
DifficultyScalerSO GetScaler(DifficultyLevel level);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 20984324b3111c5489d9c4c3e55ec4f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: