首次提交

This commit is contained in:
Bob.Song
2026-03-05 18:07:55 +08:00
commit e125bb869e
4534 changed files with 563920 additions and 0 deletions

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using FairyGUI;
namespace NBC
{
public class UIComponentTween : Dictionary<string, string>
{
}
/// <summary>
/// 组件动效配置包。与 UIComponentLanguagePack 结构类似,根据 resourceURL 映射到每个组件的子节点动效名称。
/// </summary>
public abstract class UIComponentTweenPack : Dictionary<string, UIComponentTween>
{
public bool Has(string url)
{
return ContainsKey(url);
}
public void TryPlayComponentTween(GComponent component)
{
if (component == null || component.packageItem == null) return;
if (!Has(component.resourceURL)) return;
PlayComponentTween(component);
}
/// <summary>
/// 面板调用,不判断是否存在,根节点如果配置了 __root__ 会播放。
/// </summary>
public void TryPlayPanelTween(GComponent component)
{
if (component == null) return;
PlayComponentTween(component);
}
public string GetRootTween(string url)
{
if (TryGetValue(url, out var cfg) && cfg != null && cfg.TryGetValue("__root__", out var tween))
return tween;
return null;
}
public void PlayComponentTween(GComponent component)
{
if (component == null) return;
bool comHasTweenConfig = false;
UIComponentTween tweenCfg = null;
if (component.packageItem != null && TryGetValue(component.resourceURL, out tweenCfg))
{
comHasTweenConfig = true;
}
var count = component.numChildren;
for (var i = 0; i < count; i++)
{
var child = component.GetChildAt(i);
if (child.packageItem != null && child is GComponent childCom)
{
PlayComponentTween(childCom); // 先递归子组件
}
if (comHasTweenConfig)
{
var id = child.id;
if (tweenCfg.TryGetValue(id, out var tweenName))
{
PlayTween(child, tweenName);
}
}
}
// 顶层UIPanel根节点动效改由 UIManager 设置 ShowAnim不在这里直接播放
if (component.parent == GRoot.inst) return;
// if (comHasTweenConfig && tweenCfg.TryGetValue("__root__", out var rootTween))
// {
// PlayTween(component, rootTween);
// }
}
private static readonly Dictionary<string, Action<GObject>> TweenMap =
new()
{
["Fade"] = o => o.TweenFadeShow(),
["Scale"] = o => o.TweenScaleShow(),
["Pop"] = o => o.TweenPopShow(),
["SlideInL"] = o => o.TweenSlideInLeft(),
["SlideInR"] = o => o.TweenSlideInRight(),
["SlideInT"] = o => o.TweenSlideInTop(),
["SlideInB"] = o => o.TweenSlideInBottom(),
["Bounce"] = o => o.TweenBounceShow(),
["Rotate"] = o => o.TweenRotateShow(),
["Shake"] = o => o.TweenShake()
};
private void PlayTween(GObject target, string tweenName)
{
if (target == null || string.IsNullOrEmpty(tweenName)) return;
if (TweenMap.TryGetValue(tweenName, out var act))
act(target);
}
}
}