| | |
| | | using System; |
| | | using Spine.Unity; |
| | | using UnityEngine; |
| | | using UnityEngine.Events; |
| | | using UnityEngine.EventSystems; |
| | | |
| | | public class UIHeroController : MonoBehaviour |
| | | { |
| | | private GameObjectPoolManager.GameObjectPool pool; |
| | |
| | | private GameObject instanceGO; |
| | | |
| | | private Action onComplete; |
| | | public void Create(int _skinID, float scale = 1f, Action _onComplete = null) |
| | | public void Create(int _skinID, float scale = 1f, Action _onComplete = null, string motionName = "idle", bool isLh = false) |
| | | { |
| | | if (skinID == _skinID) |
| | | { |
| | |
| | | |
| | | skeletonGraphic = instanceGO.GetComponentInChildren<SkeletonGraphic>(true); |
| | | var skinConfig = HeroSkinConfig.Get(skinID); |
| | | skeletonGraphic.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("Hero/SpineRes/", skinConfig.SpineRes); |
| | | if (isLh) |
| | | { |
| | | skeletonGraphic.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("Hero/SpineRes/", skinConfig.Tachie); |
| | | } |
| | | else |
| | | { |
| | | skeletonGraphic.skeletonDataAsset = ResManager.Instance.LoadAsset<SkeletonDataAsset>("Hero/SpineRes/", skinConfig.SpineRes); |
| | | } |
| | | skeletonGraphic.Initialize(true); |
| | | this.transform.localScale = Vector3.one * scale; |
| | | spineAnimationState = skeletonGraphic.AnimationState; |
| | | spineAnimationState.Data.DefaultMix = 0f; |
| | | PlayAnimation(MotionName.idle, true); |
| | | if (motionName == "") |
| | | motionName = GetFistSpineAnim(); |
| | | PlayAnimation(motionName, true); |
| | | spineAnimationState.Complete -= OnAnimationComplete; |
| | | spineAnimationState.Complete += OnAnimationComplete; |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | public virtual void PlayAnimation(MotionName motionName, bool loop = false) |
| | | public virtual void PlayAnimation(string motionName, bool loop = false) |
| | | { |
| | | if (spineAnimationState == null) return; |
| | | |
| | | // 直接使用 ToString() 而不是调用 GetAnimationName |
| | | spineAnimationState.SetAnimation(0, motionName.ToString(), loop); |
| | | } |
| | | |
| | | // 播放第一个动画(作为默认动画) |
| | | string GetFistSpineAnim() |
| | | { |
| | | var skeletonData = skeletonGraphic.Skeleton.Data; |
| | | if (skeletonData.Animations.Count > 0) |
| | | { |
| | | return skeletonData.Animations.Items[0].Name; |
| | | } |
| | | else |
| | | { |
| | | Debug.LogError("Spine 数据中没有找到任何动画!武将皮肤:" + skinID); |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | protected virtual void OnAnimationComplete(Spine.TrackEntry trackEntry) |
| | | { |
| | | onComplete?.Invoke(); |
| | | } |
| | | } |
| | | |
| | | } |