From 4b553f114fdf1c2fc9d8a7f39dea9fc31c27189e Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期五, 04 七月 2025 19:38:53 +0800
Subject: [PATCH] uihero控制器

---
 Main/System/Hero/UIHeroController.cs.meta |   11 +++++
 Main/System/Hero/UIHeroController.cs      |   67 +++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/Main/System/Hero/UIHeroController.cs b/Main/System/Hero/UIHeroController.cs
new file mode 100644
index 0000000..2891565
--- /dev/null
+++ b/Main/System/Hero/UIHeroController.cs
@@ -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);
+    }
+}
\ No newline at end of file
diff --git a/Main/System/Hero/UIHeroController.cs.meta b/Main/System/Hero/UIHeroController.cs.meta
new file mode 100644
index 0000000..3144903
--- /dev/null
+++ b/Main/System/Hero/UIHeroController.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e3a7f159d1436164f8be802f2eea4d66
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

--
Gitblit v1.8.0