源战役客户端
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

91 líneas
4.0 KiB

hace 4 semanas
  1. --进度条
  2. ProgressBarComponent = ProgressBarComponent or BaseClass(BaseComponent)
  3. function ProgressBarComponent:__init(parent, max_value, curr_value, width, height, ab_name, bg_img_name, front_img_name, rect_off, font_size, show_ani)
  4. self:InitData(max_value, curr_value, width, height, ab_name, bg_img_name, front_img_name, rect_off, font_size, show_ani)
  5. self:CreateGameObject(UIType.ProgressBar2)
  6. end
  7. function ProgressBarComponent:InitData(max_value, curr_value, width, height, ab_name, bg_img_name, front_img_name, rect_off, font_size, show_ani)
  8. self.max_value = max_value or 100 --最大值
  9. self.curr_value = curr_value or 1 --当前值
  10. self.width = width or 64 --背景图片宽度
  11. self.height = height or 10 --背景图片高度
  12. self.ab_name = ab_name or "uiComponent_asset"
  13. self.bg_img_name = bg_img_name --背景图片名字 统一放在uicomponent里
  14. self.front_img_name = front_img_name --前景图片名字
  15. self.rect_off = rect_off or {x = 2, y = 2}--前景与背景的偏移量
  16. self.font_size = font_size --字体大小 默认不显示
  17. self.show_ani = show_ani --是否显示动画
  18. end
  19. function ProgressBarComponent:LoadSuccess()
  20. self.bg_img = self.gameObject:GetComponent("Image")
  21. self.front_bg = self:GetChild("front_img")
  22. self.front_bg_img = self:GetChild("front_img"):GetComponent(typeof(UnityEngine.UI.Image))
  23. self.middle_bg_obj = self:GetChild("middle_img").gameObject
  24. self.middle_bg_img = self.middle_bg_obj:GetComponent(typeof(UnityEngine.UI.Image))
  25. if self.bg_img_name then
  26. lua_resM:setImageSprite(self, self.bg_img, self.ab_name, self.bg_img_name)
  27. lua_resM:setImageSprite(self, self.front_bg:GetComponent("Image"), self.ab_name, self.front_img_name)
  28. end
  29. SetSizeDelta(self.transform, self.width, self.height)
  30. self.front_bg.sizeDelta = Vector2(self.width - 2 * self.rect_off.x, self.height - self.rect_off.y * 2)
  31. -- self.front_bg.localPosition = Vector3(self.rect_off.x - self.width / 2, -self.rect_off.y + self.height / 2, 0)
  32. self.front_bg.anchoredPosition = Vector3(self.rect_off.x, -self.rect_off.y, 0)
  33. self.transform.localPosition = Vector3(3, 0, 0)
  34. self:SetValue()
  35. end
  36. function ProgressBarComponent:SetValue(value, max_value, show_ani)
  37. self.curr_value = value or self.curr_value or 0
  38. self.max_value = max_value or self.max_value or 100
  39. self.curr_value = math.min(self.curr_value, self.max_value)
  40. local rate = self.curr_value / self.max_value
  41. self.front_bg_img.fillAmount = rate
  42. if self.effectCon then
  43. local x = (self.front_bg.sizeDelta.x - 16) * rate + 8
  44. self.effectCon.localPosition = Vector2(x, 0)
  45. end
  46. if self.roleEmptyCon then
  47. self.roleEmptyCon.localPosition = Vector2(self.front_bg.sizeDelta.x * rate, 0)
  48. end
  49. if self.imageCon then
  50. self.imageCon.anchoredPosition = Vector2(self.front_bg.sizeDelta.x * rate + 59, -38)
  51. end
  52. local can_show_anim = show_ani or false
  53. if self.middle_bg_obj and self.middle_bg_obj.activeSelf ~= can_show_anim then
  54. self.middle_bg_obj:SetActive(can_show_anim)
  55. end
  56. if can_show_anim then
  57. if self.tween_hp_id then
  58. TweenLite.Stop(self.tween_hp_id)
  59. self.tween_hp_id = nil
  60. end
  61. self.tween_hp_id = TweenLite.to(self, self.middle_bg_img, TweenLite.UiAnimationType.FILLAMOUNT, rate, 0.45)
  62. end
  63. end
  64. function ProgressBarComponent:SetFrontImageStyle(front_img_name)
  65. self.front_img_name = front_img_name
  66. lua_resM:setImageSprite(self, self.front_bg:GetComponent("Image"), self.ab_name, self.front_img_name)
  67. end
  68. function ProgressBarComponent:__delete()
  69. --destroy(self.gameObject)
  70. end
  71. function ProgressBarComponent:GetImageCon()
  72. if not self.imageCon then
  73. self.imageCon = UiFactory.createChild(self.front_bg, UIType.Image3, "imageCon").transform
  74. self.imageCon.pivot = Vector2(1, 0)
  75. self.imageCon.anchorMin = Vector2(0, 1)
  76. self.imageCon.anchorMax = Vector2(0, 1)
  77. self.imageCon.anchoredPosition = Vector2(59, -38)
  78. end
  79. return self.imageCon
  80. end