后处理+FEEL完全改进

This commit is contained in:
SoulliesOfficial
2025-12-22 18:36:29 -05:00
parent c3914da4ac
commit a2052bfe16
1427 changed files with 193092 additions and 374110 deletions

View File

@@ -0,0 +1,219 @@
using UnityEngine;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine.Rendering;
// 引入你的 PostProcess 命名空间
using SLSFramework.Rendering.PostProcessing;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// 事件定义:携带所有必要的参数
/// </summary>
public struct MMAdvancedChromaticAberrationShakeEvent
{
public static void Register(Delegate callback) { OnEvent += callback; }
public static void Unregister(Delegate callback) { OnEvent -= callback; }
public delegate void Delegate(MMF_Feedback source, AnimationCurve intensityCurve, float duration, float remapMin, float remapMax, bool relativeIntensity = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
// Center
bool modifyCenter = false, Vector2 center = default,
// Extras
bool modifyExtra = false, Vector3 channelSplit = default, float dispersionStrength = 0f, float jitterIntensity = 0f, float maskRadius = 0.2f, float maskHardness = 0.2f);
public static event Delegate OnEvent;
public static void Trigger(MMF_Feedback source, AnimationCurve intensityCurve, float duration, float remapMin, float remapMax, bool relativeIntensity = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyCenter = false, Vector2 center = default,
bool modifyExtra = false, Vector3 channelSplit = default, float dispersionStrength = 0f, float jitterIntensity = 0f, float maskRadius = 0.2f, float maskHardness = 0.2f)
{
OnEvent?.Invoke(source, intensityCurve, duration, remapMin, remapMax, relativeIntensity, feedbacksIntensity, channelData, resetShakerValuesAfterShake, resetTargetValuesAfterShake, forwardDirection, timescaleMode, stop, restore,
modifyCenter, center, modifyExtra, channelSplit, dispersionStrength, jitterIntensity, maskRadius, maskHardness);
}
}
/// <summary>
/// Shaker: 控制 Advanced Chromatic Aberration
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/PostProcessing/MM Advanced Chromatic Aberration Shaker")]
[RequireComponent(typeof(Volume))]
public class MMAdvancedChromaticAberrationShaker : MMShaker
{
[MMInspectorGroup("Intensity", true, 53)]
[Tooltip("是否在现有 Intensity 基础上叠加")]
public bool RelativeIntensity = false;
[Tooltip("Intensity 的震动曲线")]
public AnimationCurve ShakeIntensity = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
[Tooltip("曲线 0 对应的值")]
public float RemapIntensityZero = 0f;
[Tooltip("曲线 1 对应的值")]
public float RemapIntensityOne = 1f;
protected Volume _volume;
protected AdvancedChromaticAberration _aca;
// 初始值存储
protected float _initialIntensity;
protected Vector2 _initialCenter;
protected Vector3 _initialSplit;
protected float _initialDispersion;
protected float _initialJitter;
protected float _initialMaskRadius;
protected float _initialMaskHardness;
// 运行时目标值存储
protected bool _modifyCenter;
protected Vector2 _targetCenter;
protected bool _modifyExtra;
protected Vector3 _targetSplit;
protected float _targetDispersion;
protected float _targetJitter;
protected float _targetMaskRadius;
protected float _targetMaskHardness;
// Shaker 复位备份
protected float _originalShakeDuration;
protected bool _originalRelativeIntensity;
protected AnimationCurve _originalShakeIntensity;
protected float _originalRemapIntensityZero;
protected float _originalRemapIntensityOne;
protected override void Initialization()
{
base.Initialization();
_volume = GetComponent<Volume>();
if (!_volume.profile.TryGet(out _aca))
{
Debug.LogWarning("MMAdvancedChromaticAberrationShaker : No AdvancedChromaticAberration found in Volume on " + name);
}
}
protected override void GrabInitialValues()
{
if (_aca != null)
{
_initialIntensity = _aca.intensity.value;
_initialCenter = _aca.center.value;
_initialSplit = _aca.channelSplit.value;
_initialDispersion = _aca.dispersionStrength.value;
_initialJitter = _aca.jitterIntensity.value;
_initialMaskRadius = _aca.maskRadius.value;
_initialMaskHardness = _aca.maskHardness.value;
}
}
protected override void Shake()
{
if (_aca == null) return;
// 1. 驱动 Intensity (带有 Curve 动画)
float newIntensity = ShakeFloat(ShakeIntensity, RemapIntensityZero, RemapIntensityOne, RelativeIntensity, _initialIntensity);
_aca.intensity.value = newIntensity;
// 2. 驱动 Center (如果启用,强制设为目标值)
if (_modifyCenter)
{
_aca.center.value = _targetCenter;
}
// 3. 驱动 Extras (如果启用,强制设为目标值)
if (_modifyExtra)
{
_aca.channelSplit.value = _targetSplit;
_aca.dispersionStrength.value = _targetDispersion;
_aca.jitterIntensity.value = _targetJitter;
_aca.maskRadius.value = _targetMaskRadius;
_aca.maskHardness.value = _targetMaskHardness;
}
}
protected override void ResetTargetValues()
{
base.ResetTargetValues();
if (_aca != null)
{
_aca.intensity.value = _initialIntensity;
_aca.center.value = _initialCenter;
_aca.channelSplit.value = _initialSplit;
_aca.dispersionStrength.value = _initialDispersion;
_aca.jitterIntensity.value = _initialJitter;
_aca.maskRadius.value = _initialMaskRadius;
_aca.maskHardness.value = _initialMaskHardness;
}
}
protected override void ResetShakerValues()
{
base.ResetShakerValues();
ShakeDuration = _originalShakeDuration;
ShakeIntensity = _originalShakeIntensity;
RemapIntensityZero = _originalRemapIntensityZero;
RemapIntensityOne = _originalRemapIntensityOne;
RelativeIntensity = _originalRelativeIntensity;
_modifyCenter = false;
_modifyExtra = false;
}
public virtual void OnEvent(MMF_Feedback source, AnimationCurve intensityCurve, float duration, float remapMin, float remapMax, bool relativeIntensity = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyCenter = false, Vector2 center = default,
bool modifyExtra = false, Vector3 channelSplit = default, float dispersionStrength = 0f, float jitterIntensity = 0f, float maskRadius = 0.2f, float maskHardness = 0.2f)
{
if (!CheckEventAllowed(channelData)) return;
if (stop) { Stop(); return; }
if (restore) { ResetTargetValues(); return; }
if (resetShakerValuesAfterShake)
{
_originalShakeDuration = ShakeDuration;
_originalShakeIntensity = ShakeIntensity;
_originalRemapIntensityZero = RemapIntensityZero;
_originalRemapIntensityOne = RemapIntensityOne;
_originalRelativeIntensity = RelativeIntensity;
}
if (!OnlyUseShakerValues)
{
TimescaleMode = timescaleMode;
ShakeDuration = duration;
ShakeIntensity = intensityCurve;
RemapIntensityZero = remapMin * feedbacksIntensity;
RemapIntensityOne = remapMax * feedbacksIntensity;
RelativeIntensity = relativeIntensity;
ForwardDirection = forwardDirection;
// 接收额外参数
_modifyCenter = modifyCenter;
_targetCenter = center;
_modifyExtra = modifyExtra;
_targetSplit = channelSplit;
_targetDispersion = dispersionStrength;
_targetJitter = jitterIntensity;
_targetMaskRadius = maskRadius;
_targetMaskHardness = maskHardness;
}
Play(source);
}
public override void StartListening()
{
base.StartListening();
MMAdvancedChromaticAberrationShakeEvent.Register(OnEvent);
}
public override void StopListening()
{
base.StopListening();
MMAdvancedChromaticAberrationShakeEvent.Unregister(OnEvent);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 83e1b594d698f9449ac7adafb9976fec

View File

@@ -0,0 +1,224 @@
using UnityEngine;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine.Rendering;
// 引入你的命名空间
using SLSFramework.Rendering.PostProcessing;
namespace MoreMountains.FeedbacksForThirdParty
{
/// <summary>
/// 事件定义:携带 Advanced Vignette 所需的所有参数
/// </summary>
public struct MMAdvancedVignetteShakeEvent
{
public static void Register(Delegate callback) { OnEvent += callback; }
public static void Unregister(Delegate callback) { OnEvent -= callback; }
public delegate void Delegate(MMF_Feedback source, AnimationCurve intensityCurve, float duration, float remapMin, float remapMax, bool relativeIntensity = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
// Custom Params
bool modifyCenter = false, Vector2 center = default,
bool modifyColors = false, Color colorOuter = default, Color colorInner = default,
bool modifyExtra = false, float smoothness = 0.5f, float roundness = 1f);
public static event Delegate OnEvent;
public static void Trigger(MMF_Feedback source, AnimationCurve intensityCurve, float duration, float remapMin, float remapMax, bool relativeIntensity = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyCenter = false, Vector2 center = default,
bool modifyColors = false, Color colorOuter = default, Color colorInner = default,
bool modifyExtra = false, float smoothness = 0.5f, float roundness = 1f)
{
OnEvent?.Invoke(source, intensityCurve, duration, remapMin, remapMax, relativeIntensity, feedbacksIntensity, channelData, resetShakerValuesAfterShake, resetTargetValuesAfterShake, forwardDirection, timescaleMode, stop, restore,
modifyCenter, center, modifyColors, colorOuter, colorInner, modifyExtra, smoothness, roundness);
}
}
/// <summary>
/// Shaker: 控制 Advanced Vignette 效果
/// </summary>
[AddComponentMenu("More Mountains/Feedbacks/Shakers/PostProcessing/MM Advanced Vignette Shaker")]
[RequireComponent(typeof(Volume))]
public class MMAdvancedVignetteShaker : MMShaker
{
[MMInspectorGroup("Intensity", true, 53)]
[Tooltip("是否在现有 Intensity 基础上叠加")]
public bool RelativeIntensity = false;
[Tooltip("Intensity 的震动曲线")]
public AnimationCurve ShakeIntensity = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
[Tooltip("曲线 0 对应的值")]
public float RemapIntensityZero = 0f;
[Tooltip("曲线 1 对应的值")]
public float RemapIntensityOne = 1f;
protected Volume _volume;
protected AdvancedVignette _vignette;
// 初始值存储
protected float _initialIntensity;
protected Vector2 _initialCenter;
protected Color _initialColorOuter;
protected Color _initialColorInner;
protected float _initialSmoothness;
protected float _initialRoundness;
// 运行时目标值
protected bool _modifyCenter;
protected Vector2 _targetCenter;
protected bool _modifyColors;
protected Color _targetColorOuter;
protected Color _targetColorInner;
protected bool _modifyExtra;
protected float _targetSmoothness;
protected float _targetRoundness;
// Shaker 状态备份
protected float _originalShakeDuration;
protected bool _originalRelativeIntensity;
protected AnimationCurve _originalShakeIntensity;
protected float _originalRemapIntensityZero;
protected float _originalRemapIntensityOne;
protected override void Initialization()
{
base.Initialization();
_volume = GetComponent<Volume>();
if (!_volume.profile.TryGet(out _vignette))
{
Debug.LogWarning("MMAdvancedVignetteShaker : No AdvancedVignette found in Volume on " + name);
}
}
protected override void GrabInitialValues()
{
if (_vignette != null)
{
_initialIntensity = _vignette.intensity.value;
_initialCenter = _vignette.center.value;
_initialColorOuter = _vignette.colorOuter.value;
_initialColorInner = _vignette.colorInner.value;
_initialSmoothness = _vignette.smoothness.value;
_initialRoundness = _vignette.roundness.value;
}
}
protected override void Shake()
{
if (_vignette == null) return;
// 1. 驱动 Intensity
float newIntensity = ShakeFloat(ShakeIntensity, RemapIntensityZero, RemapIntensityOne, RelativeIntensity, _initialIntensity);
_vignette.intensity.value = newIntensity;
// 2. 驱动 Center
if (_modifyCenter)
{
_vignette.center.value = _targetCenter;
}
// 3. 驱动 Colors
if (_modifyColors)
{
_vignette.colorOuter.value = _targetColorOuter;
_vignette.colorInner.value = _targetColorInner;
}
// 4. 驱动 Extra (Smoothness, Roundness)
if (_modifyExtra)
{
_vignette.smoothness.value = _targetSmoothness;
_vignette.roundness.value = _targetRoundness;
}
}
protected override void ResetTargetValues()
{
base.ResetTargetValues();
if (_vignette != null)
{
_vignette.intensity.value = _initialIntensity;
_vignette.center.value = _initialCenter;
_vignette.colorOuter.value = _initialColorOuter;
_vignette.colorInner.value = _initialColorInner;
_vignette.smoothness.value = _initialSmoothness;
_vignette.roundness.value = _initialRoundness;
}
}
protected override void ResetShakerValues()
{
base.ResetShakerValues();
ShakeDuration = _originalShakeDuration;
ShakeIntensity = _originalShakeIntensity;
RemapIntensityZero = _originalRemapIntensityZero;
RemapIntensityOne = _originalRemapIntensityOne;
RelativeIntensity = _originalRelativeIntensity;
_modifyCenter = false;
_modifyColors = false;
_modifyExtra = false;
}
public virtual void OnEvent(MMF_Feedback source, AnimationCurve intensityCurve, float duration, float remapMin, float remapMax, bool relativeIntensity = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyCenter = false, Vector2 center = default,
bool modifyColors = false, Color colorOuter = default, Color colorInner = default,
bool modifyExtra = false, float smoothness = 0.5f, float roundness = 1f)
{
if (!CheckEventAllowed(channelData)) return;
if (stop) { Stop(); return; }
if (restore) { ResetTargetValues(); return; }
if (resetShakerValuesAfterShake)
{
_originalShakeDuration = ShakeDuration;
_originalShakeIntensity = ShakeIntensity;
_originalRemapIntensityZero = RemapIntensityZero;
_originalRemapIntensityOne = RemapIntensityOne;
_originalRelativeIntensity = RelativeIntensity;
}
if (!OnlyUseShakerValues)
{
TimescaleMode = timescaleMode;
ShakeDuration = duration;
ShakeIntensity = intensityCurve;
RemapIntensityZero = remapMin * feedbacksIntensity;
RemapIntensityOne = remapMax * feedbacksIntensity;
RelativeIntensity = relativeIntensity;
ForwardDirection = forwardDirection;
_modifyCenter = modifyCenter;
_targetCenter = center;
_modifyColors = modifyColors;
_targetColorOuter = colorOuter;
_targetColorInner = colorInner;
_modifyExtra = modifyExtra;
_targetSmoothness = smoothness;
_targetRoundness = roundness;
}
Play(source);
}
public override void StartListening()
{
base.StartListening();
MMAdvancedVignetteShakeEvent.Register(OnEvent);
}
public override void StopListening()
{
base.StopListening();
MMAdvancedVignetteShakeEvent.Unregister(OnEvent);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 11b930e92331e8c48b320c5d04808814

View File

@@ -0,0 +1,187 @@
using UnityEngine;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine.Rendering;
using SLSFramework.Rendering.PostProcessing;
namespace MoreMountains.FeedbacksForThirdParty
{
public struct MMRadialBlurShakeEvent
{
public static void Register(Delegate callback) { OnEvent += callback; }
public static void Unregister(Delegate callback) { OnEvent -= callback; }
// 修改点:在参数列表中增加了 modifyCenter 和 center
public delegate void Delegate(MMF_Feedback source, AnimationCurve distortionCurve, float duration, float remapMin, float remapMax, bool relativeDistortion = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyCenter = false, Vector2 center = default); // 新增参数放在最后,带默认值以保持兼容性
public static event Delegate OnEvent;
public static void Trigger(MMF_Feedback source, AnimationCurve distortionCurve, float duration, float remapMin, float remapMax, bool relativeDistortion = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyCenter = false, Vector2 center = default)
{
OnEvent?.Invoke(source, distortionCurve, duration, remapMin, remapMax, relativeDistortion, feedbacksIntensity, channelData, resetShakerValuesAfterShake, resetTargetValuesAfterShake, forwardDirection, timescaleMode, stop, restore, modifyCenter, center);
}
}
[AddComponentMenu("More Mountains/Feedbacks/Shakers/PostProcessing/MM Radial Blur Shaker")]
[RequireComponent(typeof(Volume))]
public class MMRadialBlurShaker : MMShaker
{
[MMInspectorGroup("Radial Blur", true, 52)]
[Tooltip("是否在现有值的基础上叠加")]
public bool RelativeIntensity = false;
[Tooltip("模糊强度的震动曲线")]
public AnimationCurve ShakeIntensity = new AnimationCurve(new Keyframe(0, 0), new Keyframe(0.5f, 1), new Keyframe(1, 0));
[Tooltip("曲线 0 对应的 Blur Radius 值")]
public float RemapIntensityZero = 0f;
[Tooltip("曲线 1 对应的 Blur Radius 值")]
public float RemapIntensityOne = 1f;
protected Volume _volume;
protected RadialBlur _radialBlur;
// 初始值记录
protected float _initialIntensity;
protected float _initialCenterX;
protected float _initialCenterY;
// 震动时的临时变量
protected bool _modifyCenter;
protected Vector2 _targetCenter;
protected float _originalShakeDuration;
protected bool _originalRelativeIntensity;
protected AnimationCurve _originalShakeIntensity;
protected float _originalRemapIntensityZero;
protected float _originalRemapIntensityOne;
protected override void Initialization()
{
base.Initialization();
_volume = this.gameObject.GetComponent<Volume>();
if (_volume.profile.TryGet<RadialBlur>(out _radialBlur))
{
// 获取成功
}
else
{
Debug.LogWarning("MMRadialBlurShaker : No RadialBlur Override found in the Volume on " + this.name);
}
}
protected override void GrabInitialValues()
{
if (_radialBlur != null)
{
_initialIntensity = _radialBlur.blurRadius.value;
_initialCenterX = _radialBlur.radialCenterX.value;
_initialCenterY = _radialBlur.radialCenterY.value;
}
}
protected override void Shake()
{
if (_radialBlur == null) return;
// 1. 处理模糊强度 (Radius)
float newIntensity = ShakeFloat(ShakeIntensity, RemapIntensityZero, RemapIntensityOne, RelativeIntensity, _initialIntensity);
_radialBlur.blurRadius.value = newIntensity;
// 2. 处理模糊中心 (Center) - 新增逻辑
// 只有当 Feedback 要求修改中心时才覆盖,否则保持原样 (通常是 0.5)
if (_modifyCenter)
{
_radialBlur.radialCenterX.value = _targetCenter.x;
_radialBlur.radialCenterY.value = _targetCenter.y;
}
else
{
// 如果不修改,我们强制设为默认中心(0.5, 0.5)或者初始值?
// 根据你的描述:如果不开启,默认中心为(0.5,0.5)。
// 为了保险这里可以不做操作保留Volume当前值也可以强制复位。
// 建议不做操作让ResetTargetValues去负责恢复。
}
}
protected override void ResetTargetValues()
{
base.ResetTargetValues();
if (_radialBlur != null)
{
_radialBlur.blurRadius.value = _initialIntensity;
// 复位中心点
_radialBlur.radialCenterX.value = _initialCenterX;
_radialBlur.radialCenterY.value = _initialCenterY;
}
}
protected override void ResetShakerValues()
{
base.ResetShakerValues();
ShakeDuration = _originalShakeDuration;
ShakeIntensity = _originalShakeIntensity;
RemapIntensityZero = _originalRemapIntensityZero;
RemapIntensityOne = _originalRemapIntensityOne;
RelativeIntensity = _originalRelativeIntensity;
// 震动结束,重置 modifyCenter 标记,防止后续影响
_modifyCenter = false;
}
public virtual void OnMMRadialBlurShakeEvent(MMF_Feedback source, AnimationCurve distortionCurve, float duration, float remapMin, float remapMax, bool relativeDistortion = false,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyCenter = false, Vector2 center = default)
{
if (!CheckEventAllowed(channelData)) return;
if (stop) { Stop(); return; }
if (restore) { ResetTargetValues(); return; }
if (!Interruptible && Shaking) return;
_resetShakerValuesAfterShake = resetShakerValuesAfterShake;
_resetTargetValuesAfterShake = resetTargetValuesAfterShake;
if (resetShakerValuesAfterShake)
{
_originalShakeDuration = ShakeDuration;
_originalShakeIntensity = ShakeIntensity;
_originalRemapIntensityZero = RemapIntensityZero;
_originalRemapIntensityOne = RemapIntensityOne;
_originalRelativeIntensity = RelativeIntensity;
}
if (!OnlyUseShakerValues)
{
TimescaleMode = timescaleMode;
ShakeDuration = duration;
ShakeIntensity = distortionCurve;
RemapIntensityZero = remapMin * feedbacksIntensity;
RemapIntensityOne = remapMax * feedbacksIntensity;
RelativeIntensity = relativeDistortion;
ForwardDirection = forwardDirection;
// 接收并存储中心点参数
_modifyCenter = modifyCenter;
_targetCenter = center;
}
Play(source);
}
public override void StartListening()
{
base.StartListening();
MMRadialBlurShakeEvent.Register(OnMMRadialBlurShakeEvent);
}
public override void StopListening()
{
base.StopListening();
MMRadialBlurShakeEvent.Unregister(OnMMRadialBlurShakeEvent);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d41e65444be95a7469ed5fab9af1d3a2

View File

@@ -0,0 +1,188 @@
using UnityEngine;
using MoreMountains.Feedbacks;
using MoreMountains.Tools;
using UnityEngine.Rendering;
using SLSFramework.Rendering.PostProcessing;
namespace MoreMountains.FeedbacksForThirdParty
{
public struct MMStrobeFlashShakeEvent
{
public static void Register(Delegate callback) { OnEvent += callback; }
public static void Unregister(Delegate callback) { OnEvent -= callback; }
public delegate void Delegate(MMF_Feedback source, float duration,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyExtra = false, float frequency = 15f, Color colorHigh = default, Color colorLow = default);
public static event Delegate OnEvent;
public static void Trigger(MMF_Feedback source, float duration,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyExtra = false, float frequency = 15f, Color colorHigh = default, Color colorLow = default)
{
OnEvent?.Invoke(source, duration, feedbacksIntensity, channelData, resetShakerValuesAfterShake, resetTargetValuesAfterShake, forwardDirection, timescaleMode, stop, restore,
modifyExtra, frequency, colorHigh, colorLow);
}
}
[AddComponentMenu("More Mountains/Feedbacks/Shakers/PostProcessing/MM Strobe Flash Shaker")]
[RequireComponent(typeof(Volume))]
public class MMStrobeFlashShaker : MMShaker
{
[MMInspectorGroup("Strobe Settings", true, 53)]
[Tooltip("如果勾选,震动结束后会强制关闭 Effect无论初始状态是什么。建议勾选。")]
public bool ForceOffAfterShake = true;
[MMInspectorGroup("Debug Info", true, 54)]
[MMReadOnly]
public bool IsActive = false;
protected Volume _volume;
protected StrobeFlash _strobe;
protected bool _initialEnableEffect;
protected bool _initialAutoFlash;
protected float _initialFrequency;
protected Color _initialColorHigh;
protected Color _initialColorLow;
protected bool _modifyExtra;
protected float _targetFrequency;
protected Color _targetColorHigh;
protected Color _targetColorLow;
protected float _originalShakeDuration;
protected override void Initialization()
{
base.Initialization();
_volume = GetComponent<Volume>();
if (!_volume.profile.TryGet(out _strobe))
{
Debug.LogWarning("MMStrobeFlashShaker : No StrobeFlash found in Volume on " + name);
}
}
protected override void GrabInitialValues()
{
if (_strobe != null)
{
_initialEnableEffect = _strobe.enableEffect.value;
_initialAutoFlash = _strobe.autoFlash.value;
_initialFrequency = _strobe.frequency.value;
_initialColorHigh = _strobe.colorHigh.value;
_initialColorLow = _strobe.colorLow.value;
}
}
protected override void Shake()
{
if (_strobe == null) return;
// 强制开启
_strobe.enableEffect.value = true;
_strobe.autoFlash.value = true;
IsActive = true;
if (_modifyExtra)
{
_strobe.frequency.value = _targetFrequency;
_strobe.colorHigh.value = _targetColorHigh;
_strobe.colorLow.value = _targetColorLow;
}
}
// 确保 Stop 被调用时执行复位
public override void Stop()
{
base.Stop();
// base.Stop() 会调用 ResetTargetValues但为了保险再次确保状态
IsActive = false;
}
protected override void ResetTargetValues()
{
base.ResetTargetValues();
IsActive = false;
if (_strobe != null)
{
// [关键修改] 如果开启了强制关闭,直接设为 false否则恢复初始值
if (ForceOffAfterShake)
{
_strobe.enableEffect.value = false;
_strobe.autoFlash.value = false;
}
else
{
_strobe.enableEffect.value = _initialEnableEffect;
_strobe.autoFlash.value = _initialAutoFlash;
}
_strobe.frequency.value = _initialFrequency;
_strobe.colorHigh.value = _initialColorHigh;
_strobe.colorLow.value = _initialColorLow;
}
}
protected override void ResetShakerValues()
{
base.ResetShakerValues();
ShakeDuration = _originalShakeDuration;
_modifyExtra = false;
}
// 增加 OnDisable 处理,防止游戏物体被禁用时状态残留
protected virtual void OnDisable()
{
if (IsActive)
{
ResetTargetValues();
}
}
public virtual void OnEvent(MMF_Feedback source, float duration,
float feedbacksIntensity = 1.0f, MMChannelData channelData = null, bool resetShakerValuesAfterShake = true, bool resetTargetValuesAfterShake = true, bool forwardDirection = true,
TimescaleModes timescaleMode = TimescaleModes.Scaled, bool stop = false, bool restore = false,
bool modifyExtra = false, float frequency = 15f, Color colorHigh = default, Color colorLow = default)
{
if (!CheckEventAllowed(channelData)) return;
if (stop) { Stop(); return; }
if (restore) { ResetTargetValues(); return; }
if (resetShakerValuesAfterShake)
{
_originalShakeDuration = ShakeDuration;
}
if (!OnlyUseShakerValues)
{
TimescaleMode = timescaleMode;
ShakeDuration = duration;
_modifyExtra = modifyExtra;
_targetFrequency = frequency;
_targetColorHigh = colorHigh;
_targetColorLow = colorLow;
}
// 你的框架修改:传入 source
Play(source);
}
public override void StartListening()
{
base.StartListening();
MMStrobeFlashShakeEvent.Register(OnEvent);
}
public override void StopListening()
{
base.StopListening();
MMStrobeFlashShakeEvent.Unregister(OnEvent);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b009481b9292ba746a63d75b2e91e6c5