| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using UnityEngine;
- using UnityEditor;
- /// <summary>
- /// Utility to fix combat events that are still using old string-based enemy types
- /// </summary>
- public class CombatEventFixer : EditorWindow
- {
- [MenuItem("RPG/Utilities/Fix Combat Events")]
- public static void ShowWindow()
- {
- GetWindow<CombatEventFixer>("Combat Event Fixer");
- }
- void OnGUI()
- {
- GUILayout.Label("Combat Event Asset Fixer", EditorStyles.boldLabel);
- EditorGUILayout.Space();
- EditorGUILayout.HelpBox(
- "This tool fixes combat events and forces Unity to refresh the inspector to show EnemyCharacterData asset references.",
- MessageType.Info);
- EditorGUILayout.Space();
- if (GUILayout.Button("Find and Fix All Combat Events", GUILayout.Height(30)))
- {
- FixAllCombatEvents();
- }
- EditorGUILayout.Space();
- if (GUILayout.Button("Force Reimport TravelEventTypes.cs"))
- {
- ForceReimportTravelEventTypes();
- }
- if (GUILayout.Button("Refresh Asset Database"))
- {
- AssetDatabase.Refresh();
- Debug.Log("✅ Asset database refreshed");
- }
- }
- private void FixAllCombatEvents()
- {
- // Find all CombatTravelEvent assets
- string[] guids = AssetDatabase.FindAssets("t:CombatTravelEvent");
- int fixedCount = 0;
- foreach (string guid in guids)
- {
- string path = AssetDatabase.GUIDToAssetPath(guid);
- CombatTravelEvent combatEvent = AssetDatabase.LoadAssetAtPath<CombatTravelEvent>(path);
- if (combatEvent != null)
- {
- // Mark as dirty to force Unity to update the inspector
- EditorUtility.SetDirty(combatEvent);
- fixedCount++;
- Debug.Log($"🔧 Fixed combat event: {combatEvent.name}");
- }
- }
- if (fixedCount > 0)
- {
- AssetDatabase.SaveAssets();
- AssetDatabase.Refresh();
- Debug.Log($"✅ Fixed {fixedCount} combat event(s). Please check the Inspector.");
- }
- else
- {
- Debug.Log("ℹ️ No combat events found to fix. Try creating a new one.");
- }
- }
- private void ForceReimportTravelEventTypes()
- {
- string[] paths = {
- "Assets/Scripts/Events/TravelEventTypes.cs",
- "Assets/Scripts/Events/TravelEvent.cs"
- };
- foreach (string path in paths)
- {
- if (System.IO.File.Exists(path))
- {
- AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
- Debug.Log($"🔄 Reimported: {path}");
- }
- }
- AssetDatabase.Refresh();
- Debug.Log("✅ Force reimport complete");
- }
- [MenuItem("Assets/RPG/Fix Combat Event Inspector", true)]
- public static bool ValidateFixCombatEvent()
- {
- return Selection.activeObject is CombatTravelEvent;
- }
- [MenuItem("Assets/RPG/Fix Combat Event Inspector")]
- public static void FixSelectedCombatEvent()
- {
- if (Selection.activeObject is CombatTravelEvent combatEvent)
- {
- EditorUtility.SetDirty(combatEvent);
- AssetDatabase.SaveAssets();
- Debug.Log($"🔧 Fixed inspector for: {combatEvent.name}");
- }
- }
- }
|