CombaReportEnditorManager.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #if UNITY_EDITOR
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using GameLogic.Combat.CombatTool.CombatReport;
  5. using UnityEditor;
  6. using UnityEngine;
  7. using UnityEngine.UIElements;
  8. using xy002Editor.CombatEditor;
  9. public class CombaReportEnditorManager : EditorWindow
  10. {
  11. [SerializeField] private VisualTreeAsset visualTreeAsset;
  12. private Dictionary<string, StyleSheet> allStyleSheets = new Dictionary<string, StyleSheet>();
  13. public Foldout myHeroRoot;
  14. public Foldout enemyHeroRoot;
  15. private Label combatTimeLabel;
  16. private Dictionary<CombatReportEntityInfo, HeroEntityCombatReport> allHeroReportEditors =
  17. new Dictionary<CombatReportEntityInfo, HeroEntityCombatReport>();
  18. [MenuItem("CombatData/实时战报分析")]
  19. public static void ShowExample()
  20. {
  21. CombaReportEnditorManager wnd = GetWindow<CombaReportEnditorManager>();
  22. wnd.titleContent = new GUIContent("CombatR");
  23. }
  24. public void CreateGUI()
  25. {
  26. // Each editor window contains a root VisualElement object
  27. VisualElement root = rootVisualElement;
  28. visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/UIAsset/CombatR.uxml");
  29. foreach (var UPPER in visualTreeAsset.stylesheets)
  30. {
  31. allStyleSheets.Add(UPPER.name, UPPER);
  32. }
  33. combatTimeLabel = new Label("战斗时长");
  34. root.Add( combatTimeLabel);
  35. ScrollView scrollView = new ScrollView();
  36. root.Add(scrollView);
  37. myHeroRoot = Copy<Foldout>("foldout_style");
  38. scrollView.Add(myHeroRoot);
  39. enemyHeroRoot = Copy<Foldout>("foldout_style");
  40. scrollView.Add(enemyHeroRoot);
  41. }
  42. public T Copy<T>(string name) where T : VisualElement, new()
  43. {
  44. T root1 = new T();
  45. // root1.styleSheets.Clear();
  46. StyleSheet styleSheet = GetUUS("CombatR");
  47. if (styleSheet != null)
  48. {
  49. root1.styleSheets.Add(styleSheet);
  50. }
  51. root1.AddToClassList(name);
  52. root1.visible = true;
  53. return root1;
  54. }
  55. public StyleSheet GetUUS(string name)
  56. {
  57. if (allStyleSheets.ContainsKey(name))
  58. {
  59. return allStyleSheets[name];
  60. }
  61. return null;
  62. }
  63. private void CretaHeroEditor(CombatReportEntityInfo combatReportHeroInfo)
  64. {
  65. HeroEntityCombatReport heroReportEditor = new HeroEntityCombatReport();
  66. heroReportEditor.Init(combatReportHeroInfo, this);
  67. allHeroReportEditors.Add(combatReportHeroInfo, heroReportEditor);
  68. }
  69. private void Update()
  70. {
  71. Repaint();
  72. }
  73. private void OnGUI()
  74. {
  75. foreach (var VARIABLE in allHeroReportEditors.Values)
  76. {
  77. VARIABLE.OnGUI();
  78. }
  79. List<CombatReportEntityInfo> allCombatReportInfo = CombatReportManager.Instance.allCombatReportInfo;
  80. List<CombatReportEntityInfo> remove = new List<CombatReportEntityInfo>();
  81. combatTimeLabel.text= "战斗时长:" + CombatReportManager.Instance.combatTime;
  82. for (int i = 0; i < allCombatReportInfo.Count; i++)
  83. {
  84. if (!allHeroReportEditors.ContainsKey(allCombatReportInfo[i]))
  85. {
  86. CretaHeroEditor(allCombatReportInfo[i]);
  87. }
  88. }
  89. foreach (var UPPER in allHeroReportEditors.Keys)
  90. {
  91. if (!allCombatReportInfo.Contains(UPPER))
  92. {
  93. allHeroReportEditors[UPPER].Dispose();
  94. remove.Add(UPPER);
  95. }
  96. }
  97. for (int i = 0; i < remove.Count; i++)
  98. {
  99. allHeroReportEditors.Remove(remove[i]);
  100. }
  101. }
  102. }
  103. #endif