yyl
2025-07-04 4b553f114fdf1c2fc9d8a7f39dea9fc31c27189e
uihero控制器
2个文件已添加
78 ■■■■■ 已修改文件
Main/System/Hero/UIHeroController.cs 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Hero/UIHeroController.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/Hero/UIHeroController.cs
New file
@@ -0,0 +1,67 @@
using Spine.Unity;
using UnityEngine;
public class UIHeroController : MonoBehaviour
{
    public static UIHeroController Create(HeroSkinConfig skinCfg, Transform _parent = null)
    {
        // GameObject battleGO = ResManager.Instance.LoadAsset<GameObject>("Hero/SpineRes", skinCfg == null ? "Hero_001" : skinCfg.SpineRes);
        GameObject battleGO = ResManager.Instance.LoadAsset<GameObject>("Hero/SpineRes", "Hero_001");
        GameObject instanceGO = null;
        if (_parent != null)
        {
            instanceGO = GameObject.Instantiate(battleGO, _parent);
        }
        else
        {
            instanceGO = GameObject.Instantiate(battleGO);
        }
        UIHeroController heroController = instanceGO.AddMissingComponent<UIHeroController>();
        return heroController;
    }
    protected SkeletonGraphic skeletonGraphic;
    protected Spine.AnimationState spineAnimationState;
    private Spine.TrackEntry currentTrackEntry;
    void Awake()
    {
        skeletonGraphic = gameObject.GetComponentInChildren<SkeletonGraphic>(true);
        spineAnimationState = skeletonGraphic.AnimationState;
        PlayAnimation(MotionName.idle, true);
        spineAnimationState.Complete += OnAnimationComplete;
    }
    void Destroy()
    {
        spineAnimationState.Complete -= OnAnimationComplete;
    }
    public virtual Spine.TrackEntry PlayAnimation(MotionName motionName, bool loop = false)
    {
        if (spineAnimationState == null) return null;
        // 直接使用 ToString() 而不是调用 GetAnimationName
        currentTrackEntry = spineAnimationState.SetAnimation(0, motionName.ToString(), loop);
        return currentTrackEntry;
    }
    /// <summary>
    /// 动画完成事件处理
    /// </summary>
    protected virtual void OnAnimationComplete(Spine.TrackEntry trackEntry)
    {
        // string animation = trackEntry.Animation.Name;
        PlayAnimation(MotionName.idle, true);
    }
    protected void OnClick()
    {
        PlayAnimation(MotionName.attack);
    }
}
Main/System/Hero/UIHeroController.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3a7f159d1436164f8be802f2eea4d66
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant: