ProgressBarShowModle.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #if UNITY_EDITOR
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace xy002Editor.CombatEditor
  6. {
  7. public class ProgressBarShowModle
  8. {
  9. public VisualElement root;
  10. private Dictionary<string, HeroValueReport> valueReprot = new Dictionary<string, HeroValueReport>();
  11. public CombaReportEnditorManager manager;
  12. public ProgressBarShowModle(VisualElement root, CombaReportEnditorManager manager)
  13. {
  14. this.root = root;
  15. this.manager = manager;
  16. }
  17. public void CrendHarmValue(string vname, float currValue, float maxValue)
  18. {
  19. if (valueReprot.TryGetValue(vname, out HeroValueReport heroValueReport))
  20. {
  21. heroValueReport.progressBar.title = currValue.ToString();
  22. if (maxValue > 0)
  23. {
  24. heroValueReport.progressBar.lowValue = currValue;
  25. heroValueReport.progressBar.highValue = maxValue;
  26. heroValueReport.progressBar.title = currValue + "/" + maxValue;
  27. heroValueReport.progressBar.value = currValue ;
  28. }
  29. else
  30. {
  31. heroValueReport.progressBar.title = currValue.ToString();
  32. heroValueReport.progressBar.lowValue = 1;
  33. heroValueReport.progressBar.highValue = 1;
  34. heroValueReport.progressBar.value = 1 ;
  35. }
  36. }
  37. else
  38. {
  39. heroValueReport = new HeroValueReport();
  40. VisualElement herovaluegrid = manager.Copy<VisualElement>("value_data_entity_style");
  41. root.Add(herovaluegrid);
  42. Label testv = manager.Copy<Label>("valuename");
  43. testv.text = vname;
  44. testv.style.unityFontStyleAndWeight = FontStyle.Bold;
  45. testv.style.color = Color.magenta;
  46. herovaluegrid.Add(testv);
  47. ProgressBar progressBar = manager.Copy<ProgressBar>("valuebar");
  48. herovaluegrid.Add(progressBar);
  49. heroValueReport.progressBar = progressBar;
  50. if (maxValue > 0)
  51. {
  52. heroValueReport.progressBar.lowValue = currValue;
  53. heroValueReport.progressBar.highValue = maxValue;
  54. heroValueReport.progressBar.title = currValue + "/" + maxValue;
  55. heroValueReport.progressBar.value = currValue ;
  56. }
  57. else
  58. {
  59. heroValueReport.progressBar.title = currValue.ToString();
  60. heroValueReport.progressBar.lowValue = 1;
  61. heroValueReport.progressBar.highValue = 1;
  62. heroValueReport.progressBar.value = 1 ;
  63. }
  64. valueReprot.Add(vname, heroValueReport);
  65. }
  66. }
  67. }
  68. }
  69. #endif