CombatEventFixer.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using UnityEngine;
  2. using UnityEditor;
  3. /// <summary>
  4. /// Utility to fix combat events that are still using old string-based enemy types
  5. /// </summary>
  6. public class CombatEventFixer : EditorWindow
  7. {
  8. [MenuItem("RPG/Utilities/Fix Combat Events")]
  9. public static void ShowWindow()
  10. {
  11. GetWindow<CombatEventFixer>("Combat Event Fixer");
  12. }
  13. void OnGUI()
  14. {
  15. GUILayout.Label("Combat Event Asset Fixer", EditorStyles.boldLabel);
  16. EditorGUILayout.Space();
  17. EditorGUILayout.HelpBox(
  18. "This tool fixes combat events and forces Unity to refresh the inspector to show EnemyCharacterData asset references.",
  19. MessageType.Info);
  20. EditorGUILayout.Space();
  21. if (GUILayout.Button("Find and Fix All Combat Events", GUILayout.Height(30)))
  22. {
  23. FixAllCombatEvents();
  24. }
  25. EditorGUILayout.Space();
  26. if (GUILayout.Button("Force Reimport TravelEventTypes.cs"))
  27. {
  28. ForceReimportTravelEventTypes();
  29. }
  30. if (GUILayout.Button("Refresh Asset Database"))
  31. {
  32. AssetDatabase.Refresh();
  33. Debug.Log("✅ Asset database refreshed");
  34. }
  35. }
  36. private void FixAllCombatEvents()
  37. {
  38. // Find all CombatTravelEvent assets
  39. string[] guids = AssetDatabase.FindAssets("t:CombatTravelEvent");
  40. int fixedCount = 0;
  41. foreach (string guid in guids)
  42. {
  43. string path = AssetDatabase.GUIDToAssetPath(guid);
  44. CombatTravelEvent combatEvent = AssetDatabase.LoadAssetAtPath<CombatTravelEvent>(path);
  45. if (combatEvent != null)
  46. {
  47. // Mark as dirty to force Unity to update the inspector
  48. EditorUtility.SetDirty(combatEvent);
  49. fixedCount++;
  50. Debug.Log($"🔧 Fixed combat event: {combatEvent.name}");
  51. }
  52. }
  53. if (fixedCount > 0)
  54. {
  55. AssetDatabase.SaveAssets();
  56. AssetDatabase.Refresh();
  57. Debug.Log($"✅ Fixed {fixedCount} combat event(s). Please check the Inspector.");
  58. }
  59. else
  60. {
  61. Debug.Log("ℹ️ No combat events found to fix. Try creating a new one.");
  62. }
  63. }
  64. private void ForceReimportTravelEventTypes()
  65. {
  66. string[] paths = {
  67. "Assets/Scripts/Events/TravelEventTypes.cs",
  68. "Assets/Scripts/Events/TravelEvent.cs"
  69. };
  70. foreach (string path in paths)
  71. {
  72. if (System.IO.File.Exists(path))
  73. {
  74. AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
  75. Debug.Log($"🔄 Reimported: {path}");
  76. }
  77. }
  78. AssetDatabase.Refresh();
  79. Debug.Log("✅ Force reimport complete");
  80. }
  81. [MenuItem("Assets/RPG/Fix Combat Event Inspector", true)]
  82. public static bool ValidateFixCombatEvent()
  83. {
  84. return Selection.activeObject is CombatTravelEvent;
  85. }
  86. [MenuItem("Assets/RPG/Fix Combat Event Inspector")]
  87. public static void FixSelectedCombatEvent()
  88. {
  89. if (Selection.activeObject is CombatTravelEvent combatEvent)
  90. {
  91. EditorUtility.SetDirty(combatEvent);
  92. AssetDatabase.SaveAssets();
  93. Debug.Log($"🔧 Fixed inspector for: {combatEvent.name}");
  94. }
  95. }
  96. }