using System; using System.Collections.Generic; namespace ET { public static class FUI_pbHpAndShieldSystem { private static void SetMaxDestenty(this FUI_pbHpAndShield self, float value) { float actual = 0; var list = self.m_listLines; list.RemoveChildrenToPool(); using var listComponent = ListComponent.Create(); GetLineWidth(value, listComponent.List, out float extValue); actual = list.numItems = listComponent.List.Count; for (int i = 0; i < list.numItems; i++) { list.GetChildAt(i).width = listComponent.List[i]; } if (actual == 0) return; Log.Info(value+" , "+extValue); float normalWidth = list.actualWidth / (actual - 1 + extValue); list.columnGap = normalWidth - 1; } private static void GetLineWidth(float value, List list, out float extValue) { const int destenty_min = 2_0000; const int destenty_mid = 10_0000; const int destenty_max = 200_0000; const float largeMaxWidth = 3; const float largeWidth = 2; const float shortWidth = 1; if (value <= destenty_min) { //do nothing extValue = 0; } else if (value <= destenty_mid) { //全显示细 var actual = value / destenty_min; list.Add(shortWidth); int max = (int) actual; extValue = value % destenty_min / destenty_min; for (int i = 0; i < max; i++) { list.Add(shortWidth); } } else if (value <= destenty_mid * 5) { //粗细 int max = (int) value / destenty_min; extValue = value % destenty_min / destenty_min; int times = 5; int largeCount = (int) value / destenty_mid; //多余的 int extCount = max - largeCount * times; list.Add(shortWidth); for (int i = 0; i < largeCount; i++) { for (int j = 0; j < times-1; j++) { list.Add(shortWidth); } list.Add(largeWidth); } for (int i = 0; i < extCount; i++) { list.Add(shortWidth); } } else if (value <= destenty_max) { var actual = value / destenty_mid; int max = (int) actual; extValue = value % destenty_mid / destenty_mid; list.Add(shortWidth); for (int i = 0; i < max; i++) { list.Add(largeWidth); } } // else if (value <= destenty_max*5) // { // //粗细 // int max = (int) value / destenty_mid; // extValue = value % destenty_mid / destenty_mid; // int times = 5; // int largeCount = (int) value / destenty_max; // //多余的 // max = (int) (max * 5f /( destenty_max / destenty_mid)); // int extCount = max - largeCount * times; // list.Add(shortWidth); // for (int i = 0; i < largeCount; i++) // { // for (int j = 0; j < times-1; j++) // { // list.Add(largeWidth); // } // // list.Add(largeMaxWidth); // } // // for (int i = 0; i < extCount; i++) // { // list.Add(largeWidth); // } // } else { var actual = value / destenty_max; int max = (int) actual; extValue = value % destenty_max / destenty_max; list.Add(shortWidth); for (int i = 0; i < max; i++) { list.Add(largeMaxWidth); } } } public static void SetMaxShield(this FUI_pbHpAndShield self, float hp, float shield, float maxHp) { var max = maxHp; if (hp + shield > maxHp) { max = hp + shield; } self.m_hp.width = hp / max * self.m_defaultHp.width; self.m_shield.width = shield / max * self.m_defaultHp.width; self.m_hp.fillAmount = 100; self.m_shield.fillAmount = 100; SetMaxDestenty(self, max); } public static void SetHpAndShield(this FUI_pbHpAndShield self, float hp, float shield, float maxHp) { if (maxHp == 0) { throw new Exception("maxHp can not be 0"); } if (hp < 0) hp = 0; if (hp > maxHp) hp = maxHp; if (shield < 0) shield = 0; if (hp + shield > maxHp) { SetMaxShield(self, hp, shield, maxHp); return; } var oldWidth = self.m_defaultHp.width; self.m_hp.width = hp / maxHp * oldWidth; self.m_shield.width = shield / maxHp * oldWidth; self.m_upBar.visible = false; //优化 self.m_downBar.TweenScaleX(hp / maxHp, 1f); } } }