224 lines
9.3 KiB
C#
224 lines
9.3 KiB
C#
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);
|
|
}
|
|
}
|
|
} |