| | |
| | | |
| | | using System; |
| | | using Spine.Unity; |
| | | using UnityEngine; |
| | | |
| | | using UnityEngine.Events; |
| | | using UnityEngine.EventSystems; |
| | | public class UIHeroController : MonoBehaviour |
| | | { |
| | | public static UIHeroController Create(HeroSkinConfig skinCfg, Transform _parent = null) |
| | | public void Create(int _skinID, Action _onComplete = null) |
| | | { |
| | | // GameObject battleGO = ResManager.Instance.LoadAsset<GameObject>("Hero/SpineRes", skinCfg == null ? "Hero_001" : skinCfg.SpineRes); |
| | | skinID = _skinID; |
| | | onComplete = _onComplete; |
| | | GameObject battleGO = ResManager.Instance.LoadAsset<GameObject>("Hero/SpineRes", "Hero_001"); |
| | | GameObject instanceGO = null; |
| | | if (_parent != null) |
| | | if (!transform.gameObject.activeSelf) |
| | | { |
| | | instanceGO = GameObject.Instantiate(battleGO, _parent); |
| | | transform.SetActive(true); |
| | | } |
| | | 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); |
| | | instanceGO = GameObject.Instantiate(battleGO, transform); |
| | | skeletonGraphic = instanceGO.GetComponentInChildren<SkeletonGraphic>(true); |
| | | var skinConfig = HeroSkinConfig.Get(skinID); |
| | | skeletonGraphic.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("Hero/SpineRes/", skinConfig.SpineRes + "_SkeletonData"); |
| | | skeletonGraphic.Initialize(true); |
| | | spineAnimationState = skeletonGraphic.AnimationState; |
| | | PlayAnimation(MotionName.idle, true); |
| | | |
| | | spineAnimationState.Complete += OnAnimationComplete; |
| | | } |
| | | private int skinID; |
| | | protected SkeletonGraphic skeletonGraphic; |
| | | |
| | | protected Spine.AnimationState spineAnimationState; |
| | | |
| | | private Spine.TrackEntry currentTrackEntry; |
| | | private Action onComplete; |
| | | |
| | | |
| | | |
| | | void Destroy() |
| | | { |
| | |
| | | return currentTrackEntry; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 动画完成事件处理 |
| | | /// </summary> |
| | | protected virtual void OnAnimationComplete(Spine.TrackEntry trackEntry) |
| | | { |
| | | // string animation = trackEntry.Animation.Name; |
| | | PlayAnimation(MotionName.idle, true); |
| | | /// <summary> |
| | | /// 动画完成事件处理 |
| | | /// </summary> |
| | | protected virtual void OnAnimationComplete(Spine.TrackEntry trackEntry) |
| | | { |
| | | onComplete?.Invoke(); |
| | | } |
| | | |
| | | protected void OnClick() |
| | | { |
| | | PlayAnimation(MotionName.attack); |
| | | } |
| | | } |