CleanUpClassName.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace DCGO.Tools.Repair{
  6. public class CleanUpClassName : MonoBehaviour
  7. {
  8. [MenuItem("Window/DCGO/Repair/Fix Entity Class Names")]
  9. static void FixEntityClassNames()
  10. {
  11. List<CEntity_Base> List = GetAsset.LoadAll<CEntity_Base>("Assets/CardBaseEntity/");
  12. foreach (CEntity_Base card in List)
  13. {
  14. card.CardEffectClassName = FixCharactersInClassName(card.CardEffectClassName);
  15. EditorUtility.SetDirty(card);
  16. }
  17. Debug.Log("Fixed all class names in CardBaseEntity");
  18. return;
  19. //Parse ScriptableObject Class Name
  20. string FixCharactersInClassName(string str)
  21. {
  22. string name = str;
  23. name = FixCharactersInName(name);
  24. name = name
  25. .Replace("-", "_")
  26. .Replace(".", "")
  27. .Replace("'", "")
  28. .Replace("&", "And")
  29. .Replace("(", "")
  30. .Replace(")", "");
  31. return name;
  32. }
  33. //Parse ScriptableObject Name
  34. string FixCharactersInName(string str)
  35. {
  36. string name = str;
  37. name = name
  38. .Replace(" ", "_")
  39. .Replace(":", "")
  40. .Replace("?", "")
  41. .Replace("!", "")
  42. .Replace("<", "")
  43. .Replace(">", "");
  44. return name;
  45. }
  46. }
  47. [MenuItem("Window/DCGO/Repair/Convert Entity Class Names")]
  48. static void ConvertEntityClassNames()
  49. {
  50. string path = "Assets/CardBaseEntity/";
  51. if (Selection.assetGUIDs.Length != 0)
  52. path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
  53. List<CEntity_Base> List = GetAsset.LoadAll<CEntity_Base>(path);
  54. string cardList = "";
  55. int count = 0;
  56. foreach (CEntity_Base card in List)
  57. {
  58. string cardID = card.CardID.Replace("-", "_");
  59. if(!String.IsNullOrEmpty(card.CardEffectClassName))
  60. card.CardEffectClassName = card.CardEffectClassName.Substring(card.CardEffectClassName.IndexOf("_") + 1);
  61. EditorUtility.SetDirty(card);
  62. Debug.Log($"{card.CardSpriteName.Replace("-", "_")} - {cardID} - {card.CardEffectClassName}");
  63. AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(card), card.CardSpriteName.Replace("-", "_"));
  64. count++;
  65. EditorUtility.SetDirty(card);
  66. }
  67. Debug.Log("Cards using another class:\n" + cardList);
  68. Debug.Log($"Fixed all class names in CardBaseEntity: {count}");
  69. return;
  70. }
  71. }
  72. }