ProgressBarShowModle.cs 3.0 KB

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