UICharactorController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using I2.Loc;
  5. using UnityEngine;
  6. public class UICharactorController : MonoBehaviour
  7. {
  8. private PlayerAttribute playerAttribute
  9. {
  10. get
  11. {
  12. return R.Player.Attribute;
  13. }
  14. }
  15. private void Awake()
  16. {
  17. this._roleNameLocalize = this._roleNameLabel.GetComponent<Localize>();
  18. }
  19. private void Start()
  20. {
  21. Transform child = this.hp2Bar.transform.GetChild(0);
  22. this.cursorTweenAlpha = child.GetComponent<TweenAlpha>();
  23. this.cursorSprite = child.GetComponent<UISprite>();
  24. base.StartCoroutine(this.HPValueHistoryRecorder());
  25. base.StartCoroutine(this.HPChangeAnim());
  26. }
  27. private void Update()
  28. {
  29. this.DataBind();
  30. }
  31. private void DataBind()
  32. {
  33. if (this.playerAttribute == null)
  34. {
  35. return;
  36. }
  37. this.UpdateHpBarShape();
  38. this.UpdateCharInfo();
  39. }
  40. private void UpdateHpBarShape()
  41. {
  42. if (this._lastPlayerMaxHP != R.Player.Attribute.maxHP)
  43. {
  44. this._lastPlayerMaxHP = R.Player.Attribute.maxHP;
  45. int num = (int)((double)this._lastPlayerMaxHP * 2.48);
  46. this._hp1Sprite.width = num;
  47. this._hp2Sprite.width = num;
  48. this._hpBgSprite.width = num + 56;
  49. }
  50. }
  51. private void UpdateCharInfo()
  52. {
  53. float num = (float)this.playerAttribute.currentHP / (float)Mathf.Max(this.playerAttribute.maxHP, 1);
  54. if (Math.Abs(this.hp1Bar.value - num) > 1.401298E-45f)
  55. {
  56. this.hp1Bar.value = num;
  57. }
  58. if (this.hpValueHistory.Count >= 10 && (double)Mathf.Abs(this.hp1Bar.value - this.hpValueHistory.Peek()) < 0.0001 && (double)Mathf.Abs(this.hp1Bar.value - this.hpValueWhenLastPlayAnim) > 0.0001)
  59. {
  60. this.hpValueWhenLastPlayAnim = this.hp1Bar.value;
  61. this.play = true;
  62. }
  63. if (this.playerAttribute.currentHP == 0)
  64. {
  65. this.hpValueWhenLastPlayAnim = this.hp1Bar.value;
  66. this.play = true;
  67. }
  68. this.energyController.EnergyMaxValue = this.playerAttribute.maxEnergy * 2;
  69. this.energyController.EnergyValue = this.playerAttribute.currentEnergy * 2;
  70. if (this._roleName != R.Player.RoleName)
  71. {
  72. this._roleName = R.Player.RoleName;
  73. string roleName = R.Player.RoleName;
  74. if (roleName != null)
  75. {
  76. if (roleName == "ICEY")
  77. {
  78. this._roleNameLocalize.enabled = true;
  79. this._roleNameLocalize.Term = "ui/ICEY";
  80. return;
  81. }
  82. if (roleName == "UCEY")
  83. {
  84. this._roleNameLocalize.enabled = true;
  85. this._roleNameLocalize.Term = "ui/UCEY";
  86. return;
  87. }
  88. if (roleName == "anonymous")
  89. {
  90. this._roleNameLocalize.enabled = true;
  91. this._roleNameLocalize.Term = "ui/anonymous";
  92. return;
  93. }
  94. }
  95. this._roleNameLocalize.enabled = false;
  96. this._roleNameLabel.text = R.Player.RoleName;
  97. }
  98. }
  99. private IEnumerator HPChangeAnim()
  100. {
  101. for (;;)
  102. {
  103. if (this.play)
  104. {
  105. this.play = false;
  106. this.cursorTweenAlpha.enabled = true;
  107. this.cursorSprite.enabled = true;
  108. float start = this.hp2Bar.value;
  109. float targe = this.hp1Bar.value;
  110. for (float x = 0f; x < 1f; x += 0.02f)
  111. {
  112. float current = start + (targe - start) * x;
  113. this.hp2Bar.value = current;
  114. yield return new WaitForSeconds(0.02f);
  115. }
  116. this.cursorTweenAlpha.enabled = false;
  117. this.cursorSprite.alpha = 0f;
  118. }
  119. yield return null;
  120. }
  121. yield break;
  122. }
  123. private IEnumerator HPValueHistoryRecorder()
  124. {
  125. for (;;)
  126. {
  127. this.hpValueHistory.Enqueue(this.hp1Bar.value);
  128. if (this.hpValueHistory.Count > 10)
  129. {
  130. this.hpValueHistory.Dequeue();
  131. }
  132. yield return new WaitForSeconds(0.1f);
  133. }
  134. yield break;
  135. }
  136. public void OnRoleNameLocalized()
  137. {
  138. this._roleNameLabel.spacingX = ((!UILanguage.IsSimplifiedChinese) ? 0 : 8);
  139. }
  140. private bool play;
  141. [SerializeField]
  142. private UISprite _hp1Sprite;
  143. [SerializeField]
  144. private UISprite _hp2Sprite;
  145. [SerializeField]
  146. private UISprite _hpBgSprite;
  147. [SerializeField]
  148. private UIProgressBar hp1Bar;
  149. [SerializeField]
  150. private UIProgressBar hp2Bar;
  151. private TweenAlpha cursorTweenAlpha;
  152. private UISprite cursorSprite;
  153. private readonly Queue<float> hpValueHistory = new Queue<float>();
  154. private float hpValueWhenLastPlayAnim = 1f;
  155. private int _lastPlayerMaxHP;
  156. [SerializeField]
  157. private UIEnergyController energyController;
  158. [SerializeField]
  159. private UILabel _roleNameLabel;
  160. private Localize _roleNameLocalize;
  161. private string _roleName;
  162. }