NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/UI/UIAnimProfileConfig.cs

100 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using PhxhSDK;
using Sirenix.OdinInspector;
using UnityEngine;
/// <summary>
/// 动画参数配置
/// </summary>
[Serializable]
public class UIAnimProfile
{
[LabelText("总时长")] public float totalDuration = 0.3f;
[LabelText("高斯模糊动效开关")] public bool useMask = true;
[LabelText("高斯模糊显隐时间")] [ShowIf("useMask")]
public UIAnimRange maskFade = new UIAnimRange(0f, 0.05f);
[LabelText("背景显隐时间")] public UIAnimRange bgFade = new UIAnimRange(0.02f, 0.2f);
[LabelText("背景缩放时间")] public UIAnimRange bgScale = new UIAnimRange(0.02f, 0.12f);
[LabelText("背景起始缩放大小")] public float bgScaleFrom = 1.1f;
[LabelText("背景最终缩放大小")] public float bgScaleTo = 1f;
[LabelText("内容主体显隐时间")] public UIAnimRange contentFade = new UIAnimRange(0.15f, 0.3f);
[LabelText("内容主体透明度缓动曲线")] public AnimationCurve alphaCurve = AnimationCurve.Linear(0, 0, 1, 1);
[LabelText("内容主体缩放缓动曲线")] public AnimationCurve scaleCurve = AnimationCurve.Linear(0, 0, 1, 1);
public UIAnimProfile Clone()
{
return new UIAnimProfile
{
totalDuration = totalDuration,
maskFade = maskFade,
bgFade = bgFade,
bgScale = bgScale,
bgScaleFrom = bgScaleFrom,
bgScaleTo = bgScaleTo,
contentFade = contentFade,
alphaCurve = new AnimationCurve(alphaCurve.keys),
scaleCurve = new AnimationCurve(scaleCurve.keys),
useMask = useMask
};
}
}
/// <summary>
/// 时间区间(秒)
/// </summary>
[Serializable]
public struct UIAnimRange
{
[LabelText("开始时间")] public float start;
[LabelText("结束时间")] public float end;
public float Duration => Mathf.Max(0f, end - start);
public UIAnimRange(float start, float end)
{
this.start = start;
this.end = end;
}
}
/// <summary>
/// ScriptableObject 用于配置动画参数,放到 Resources/UIAnimProfileConfig.asset 即可打包生效
/// </summary>
[CreateAssetMenu(fileName = "UIAnimProfileConfig", menuName = "UI/UI Anim Profile Config", order = 0)]
public class UIAnimProfileConfig : ScriptableObject
{
[Serializable]
public class Entry
{
[LabelText("弹窗类型")] public UIAnimPresetType presetType = UIAnimPresetType.Level1;
[LabelText("配置")] public UIAnimProfile profile = new UIAnimProfile();
}
[SerializeField] private List<Entry> entries = new List<Entry>();
/// <summary>
/// 获取指定预设的配置,返回克隆体避免运行时共享引用
/// </summary>
public UIAnimProfile GetProfile(UIAnimPresetType preset)
{
if (entries == null || entries.Count == 0)
return null;
for (int i = 0; i < entries.Count; i++)
{
var e = entries[i];
if (e != null && e.presetType == preset && e.profile != null)
{
return e.profile.Clone();
}
}
return null;
}
}