Kaynağa Gözat

可以写入读取的skeletonData数据

SZAND\msx_2 7 ay önce
ebeveyn
işleme
b98005ec35

+ 36 - 7
ActionTowerDefense/Assets/Scripts/Character.cs

@@ -53,6 +53,30 @@ public enum HpUpType
     Fixed = 2,      //加固定血量
 }
 
+[System.Serializable]
+public struct SpineAniKey
+{
+    public string aniName;
+    public List<AttackKeyType> keys;
+}
+
+public enum KeyType
+{
+    AttackStart,
+    AttackEnd,
+}
+
+[System.Serializable]
+public struct AttackKeyType
+{
+    public string startKeyName;
+    public float startKeyTime;
+    public KeyType attackType;
+    public string endKeyName;
+    public float endKeyTime;
+    public KeyType endType;
+}
+
 public class Character : MonoBehaviour
 {
     [Header("骨骼")]
@@ -64,7 +88,19 @@ public class Character : MonoBehaviour
     [Header("动画控制器")]
     public Animator ani;
     public Animator aniCollider;
+    
+    [Header("所有动画时间")]
+    public float totalDieKeepTime = 2f;
+    public float totalAttack_summonTime = 0.5f;
+    public float totalAttack_marchTime = 0.5f;
 
+    [Header("所有攻击帧事件及时间")]
+    public List<SpineAniKey> attackKeys;
+
+    [Header("死亡后多久尸体消失")]
+    [HideInInspector]
+    public float dieKeepTime;
+    
     [Header("组件")]
     public Rigidbody rb;
     public Transform bodyTrans;
@@ -96,18 +132,11 @@ public class Character : MonoBehaviour
     public LockSoul ls;
     public bool isInSoulTower;      //在锁魂塔范围内
 
-    [Header("死亡后多久尸体消失")]
-    public float totalDieKeepTime = 2f;
-    [HideInInspector]
-    public float dieKeepTime;
-
     [Header("普通攻击信息")]
     public bool canHitFly;
     [HideInInspector]
     public bool isNonAttack = false;            //无普攻
     public float attackTime;
-    public float totalAttack_summonTime = 0.5f;
-    public float totalAttack_marchTime = 0.5f;
     public AttackType attackType;               //攻击类型
     public GameObject bulletPrefab;             //远程攻击的子弹
     public List<Transform> shootPos;            //远程攻击的子弹发射位置

+ 39 - 4
ActionTowerDefense/Assets/Scripts/Spine/SkeletonDataReader.cs

@@ -1,18 +1,18 @@
 using UnityEngine;
 using Spine;
 using Spine.Unity;
+using System.Collections.Generic;
 
 public class SkeletonDataReader : MonoBehaviour
 {
     private SkeletonMecanim skeletonMecanim;
-    private Enemy ene;
+    private Character cha;
 
     [ContextMenu("Play")]
     private void WriteData()
     {
         ReadData();
-        ene = GetComponentInParent<Enemy>();
-        ene.totalBeRepelValue = 30;
+        cha = GetComponentInParent<Character>();
     }
 
     private void ReadData()
@@ -40,13 +40,32 @@ public class SkeletonDataReader : MonoBehaviour
             return;
         }
 
+        cha.attackKeys = new List<SpineAniKey>();
         // 遍历所有动画
         foreach (var animation in skeletonData.Animations)
         {
             string animationName = animation.Name;
             float animationDuration = animation.Duration;
             Debug.Log($"动画名称: {animationName}, 动画时长: {animationDuration}");
+            if (animationName == "die")
+            {
+                cha.totalDieKeepTime = animationDuration;
+            }
+            else if (animationName == "attack_summon")
+            {
+                cha.totalAttack_summonTime = animationDuration;
+            }
+            else if (animationName == "attack_march")
+            {
+                cha.totalAttack_marchTime = animationDuration;
+            }
 
+            SpineAniKey sak;
+            sak.aniName = animationName;
+            sak.keys = new List<AttackKeyType>();
+            AttackKeyType akt = new AttackKeyType();
+            bool isStartKey = true;
+            bool canWrite = false;
             // 遍历动画中的事件
             foreach (var timeline in animation.Timelines)
             {
@@ -54,12 +73,28 @@ public class SkeletonDataReader : MonoBehaviour
                 {
                     foreach (var eventFrame in eventTimeline.Events)
                     {
-                        string eventName = eventFrame.Name;
+                        string eventName = eventFrame.ToString();
                         float eventTime = eventFrame.Time;
                         Debug.Log($"事件名称: {eventName}, 事件时间: {eventTime}, 所在动画: {animationName}");
+                        if (isStartKey)
+                        {
+                            akt.startKeyName = eventName;
+                            akt.startKeyTime = eventTime;
+                            akt.attackType = KeyType.AttackStart;
+                        }
+                        else
+                        {
+                            akt.endKeyName = eventName;
+                            akt.endKeyTime = eventTime;
+                            akt.endType = KeyType.AttackEnd;
+                            sak.keys.Add(akt);
+                            canWrite = true;
+                        }
+                        isStartKey = !isStartKey;
                     }
                 }
             }
+            if(canWrite) cha.attackKeys.Add(sak);
         }
     }
 }

+ 0 - 2
ActionTowerDefense/Assets/Spine/Runtime/spine-csharp/Event.cs

@@ -51,8 +51,6 @@ namespace Spine {
 		public float Volume { get { return volume; } set { volume = value; } }
 		public float Balance { get { return balance; } set { balance = value; } }
 
-        public string Name { get; set; }
-
         public Event (float time, EventData data) {
 			if (data == null) throw new ArgumentNullException("data", "data cannot be null.");
 			this.time = time;