From 5bc2cc9a3e007b96a0de96e70e87f25bc5a254a2 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期一, 21 七月 2025 19:22:45 +0800
Subject: [PATCH] 125 【战斗】战斗系统 战斗系统迭代 协议接入 阵容部分代码
---
Main/System/Hero/UIHeroController.cs | 64 +++++++++++++++-----------------
1 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/Main/System/Hero/UIHeroController.cs b/Main/System/Hero/UIHeroController.cs
index 2891565..241063a 100644
--- a/Main/System/Hero/UIHeroController.cs
+++ b/Main/System/Hero/UIHeroController.cs
@@ -1,40 +1,41 @@
+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, float scale = 1f, Action _onComplete = 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");
+ skinID = _skinID;
+ onComplete = _onComplete;
+ GameObject battleGO = UILoader.LoadPrefab("UIHero");
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);
+ this.transform.localScale = Vector3.one * scale;
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()
{
@@ -51,17 +52,12 @@
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);
- }
}
\ No newline at end of file
--
Gitblit v1.8.0