Ver Fonte

解决spine自动化导入脚本失效问题

SZAND\msx_2 há 6 meses atrás
pai
commit
9ad283b681

+ 68 - 3
ActionTowerDefense/Assets/Editor/SkeletonDataReader.cs

@@ -142,10 +142,18 @@ public class SkeletonDataMonitor
         }
     }
 
-    private static void ProcessSkeletonChange(string prefabPath, SkeletonDataAsset skeletonData)
+    private static void ProcessSkeletonChange(string prefabPath, SkeletonDataAsset skeletonData, bool forceRefresh = false)
     {
-        WriteData(prefabPath);
-        CachePrefab(prefabPath, skeletonData);
+        var currentModTime = File.GetLastWriteTime(prefabPath);
+
+        // 如果是强制刷新或者文件有修改
+        if (forceRefresh || !_prefabCache.TryGetValue(prefabPath, out var cache) ||
+            cache.skeletonDataAsset != skeletonData ||
+            cache.lastModified != currentModTime)
+        {
+            WriteData(prefabPath);
+            CachePrefab(prefabPath, skeletonData);
+        }
     }
 
     static Character cha;
@@ -200,6 +208,7 @@ public class SkeletonDataMonitor
         }
 
         attack.attackKeys = new List<AttackController.SpineAniKey>();
+        Debug.Log(2);
         // 遍历所有动画
         foreach (var animation in skeletonData.Animations)
         {
@@ -285,6 +294,62 @@ public class SkeletonDataMonitor
         }
     }
 
+    [MenuItem("Tools/Spine/强制更新选中SkeletonData")]
+    private static void ForceRefreshSelectedSkeletonData()
+    {
+        if (EditorApplication.isPlayingOrWillChangePlaymode)
+        {
+            EditorUtility.DisplayDialog("提示", "该功能只能在编辑模式下使用", "确定");
+            return;
+        }
+
+        var selected = Selection.activeObject as SkeletonDataAsset;
+        if (selected == null)
+        {
+            EditorUtility.DisplayDialog("提示", "请先选择一个SkeletonDataAsset", "确定");
+            return;
+        }
+
+        // 强制更新所有使用此SkeletonData的预制体
+        if (_skeletonToPrefabs.TryGetValue(selected, out var prefabPaths))
+        {
+            foreach (var path in prefabPaths)
+            {
+                ForceRefreshPrefab(path, selected);
+            }
+            AssetDatabase.SaveAssets();
+            Debug.Log($"已强制更新 {prefabPaths.Count} 个使用 {selected.name} 的预制体");
+        }
+        else
+        {
+            Debug.Log($"没有找到使用 {selected.name} 的预制体");
+        }
+    }
+
+    private static void ForceRefreshPrefab(string prefabPath, SkeletonDataAsset skeletonData)
+    {
+        GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
+        GameObject prefabInstance = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
+        try
+        {
+            // 强制重新读取数据
+            WriteData(prefabPath);
+
+            PrefabUtility.SaveAsPrefabAsset(prefabInstance, prefabPath);
+
+            // 更新缓存
+            CachePrefab(prefabPath, skeletonData);
+        }
+        catch (Exception ex)
+        {
+            Debug.LogError($"强制更新预制体 {prefabPath} 时出错: {ex.Message}");
+        }
+        finally
+        {
+            UnityEngine.Object.DestroyImmediate(prefabInstance);
+        }
+    }
+
     [MenuItem("Tools/Spine/手动刷新变更")]
     private static void ForceRefreshModified()
     {

+ 27 - 25
ActionTowerDefense/Assets/Resources/Prefab/MySoldier/Demonic_Sword.prefab

@@ -175,15 +175,6 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: c1bedfb340186164dbac1499b49b879e, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  mecanim: {fileID: 5617185463097218335}
-  meshRenderer: {fileID: 0}
-  ani: {fileID: 6496896669866891404}
-  totalDieKeepTime: 0
-  totalAttack_summonTime: 1.2667
-  totalAttack_marchTime: 1.8333
-  dieKeepTime: 0
-  beHitDistance: 0.1
-  attackDis: 0
   rb: {fileID: 2437299196472462355}
   bodyTrans: {fileID: 2730232521377132808}
   beSearchTrigger: {fileID: 1317309795988277421}
@@ -192,6 +183,15 @@ MonoBehaviour:
   uiHp: {fileID: 6433555643392153575}
   beHitTrigger: {fileID: 5333142802677931907}
   attackController: {fileID: 6797330787108410633}
+  mecanim: {fileID: 5617185463097218335}
+  meshRenderer: {fileID: 0}
+  ani: {fileID: 6496896669866891404}
+  totalDieKeepTime: 0.20000002
+  totalAttack_summonTime: 1.1666667
+  totalAttack_marchTime: 1
+  dieKeepTime: 0
+  beHitDistance: 0.1
+  attackDis: 0
   targetCharacter: {fileID: 0}
   attackTarget: {fileID: 0}
   state: 0
@@ -212,6 +212,8 @@ MonoBehaviour:
   cookEffect: {fileID: 0}
   Attack_summonShootCanTransmit: 0
   debugAttackFrom: 0
+  foot: {fileID: 2437299196663985756}
+  attributeStatus: {fileID: 0}
   hitResistance: 0
   matState: 1
   spinee: {fileID: 0}
@@ -221,8 +223,6 @@ MonoBehaviour:
   - {fileID: 2100000, guid: 7d50f910288e95b4285a5fb549c94fe6, type: 2}
   outline1Mats:
   - {fileID: 2100000, guid: 79dada70fee9fbc49a327168481d3def, type: 2}
-  foot: {fileID: 2437299196663985756}
-  attributeStatus: {fileID: 0}
   extraRiseGravity: -28.8
   extraFallGravity: -14.4
   moveSpeed: 3
@@ -303,33 +303,28 @@ MonoBehaviour:
     - attackMethod: 0
       attackType: 0
       startKeyName: attack_on
-      startKeyTime: 1.1333
+      startKeyTime: 0.3
       endType: 1
       endKeyName: attack_off
-      endKeyTime: 1.3333
+      endKeyTime: 0.40000004
   - aniName: attack_summon
     keys:
     - attackMethod: 0
       attackType: 0
       startKeyName: attack_on
-      startKeyTime: 0.1
-      endType: 1
-      endKeyName: attack_off
-      endKeyTime: 0.2
-    - attackMethod: 0
-      attackType: 0
-      startKeyName: attack_on
-      startKeyTime: 0.3667
+      startKeyTime: 0.10000001
       endType: 1
       endKeyName: attack_off
-      endKeyTime: 0.5333
+      endKeyTime: 0.33333334
+  - aniName: attack_summon02
+    keys:
     - attackMethod: 0
       attackType: 0
       startKeyName: attack_on
-      startKeyTime: 0.7667
+      startKeyTime: 0.20000002
       endType: 1
       endKeyName: attack_off
-      endKeyTime: 0.8667
+      endKeyTime: 0.33333334
   keyTimes: []
   attackTime: 0
   attackKeyCount: 0
@@ -428,6 +423,8 @@ MonoBehaviour:
     armorPiercing: 0
     bulletPrefab: {fileID: 0}
     shootPos: []
+    maxUpAngle: 0
+    maxDownAngle: 0
     shootTrack: 0
     shootAlwaysTrack: 0
     skillPrefab: {fileID: 0}
@@ -476,6 +473,8 @@ MonoBehaviour:
     armorPiercing: 0
     bulletPrefab: {fileID: 0}
     shootPos: []
+    maxUpAngle: 0
+    maxDownAngle: 0
     shootTrack: 0
     shootAlwaysTrack: 0
     skillPrefab: {fileID: 0}
@@ -525,6 +524,8 @@ MonoBehaviour:
     armorPiercing: 0
     bulletPrefab: {fileID: 0}
     shootPos: []
+    maxUpAngle: 0
+    maxDownAngle: 0
     shootTrack: 0
     shootAlwaysTrack: 0
     skillPrefab: {fileID: 0}
@@ -1384,9 +1385,10 @@ MonoBehaviour:
     ShotDown: 0
     Weak: 0
     armor: 0
+  floatingState: 0
+  hitState: 0
   decelerationRatioX: 2
   decelerationRatioY: 15
-  floatingState: 0
   haveVulnerable: 0
   vulnerableTime: 0
 --- !u!1 &8802879426389446295

+ 1 - 0
ActionTowerDefense/Assets/Resources/Prefab/MySoldier/Spirits_Invisible.prefab

@@ -797,6 +797,7 @@ MonoBehaviour:
   m_EditorClassIdentifier: 
   owner: {fileID: 0}
   attackerID: 0
+  curX: 0
 --- !u!1 &8802879426389446295
 GameObject:
   m_ObjectHideFlags: 0