源战役客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

92 řádky
4.0 KiB

--进度条
ProgressBarComponent = ProgressBarComponent or BaseClass(BaseComponent)
function ProgressBarComponent:__init(parent, max_value, curr_value, width, height, ab_name, bg_img_name, front_img_name, rect_off, font_size, show_ani)
self:InitData(max_value, curr_value, width, height, ab_name, bg_img_name, front_img_name, rect_off, font_size, show_ani)
self:CreateGameObject(UIType.ProgressBar2)
end
function ProgressBarComponent:InitData(max_value, curr_value, width, height, ab_name, bg_img_name, front_img_name, rect_off, font_size, show_ani)
self.max_value = max_value or 100 --最大值
self.curr_value = curr_value or 1 --当前值
self.width = width or 64 --背景图片宽度
self.height = height or 10 --背景图片高度
self.ab_name = ab_name or "uiComponent_asset"
self.bg_img_name = bg_img_name --背景图片名字 统一放在uicomponent里
self.front_img_name = front_img_name --前景图片名字
self.rect_off = rect_off or {x = 2, y = 2}--前景与背景的偏移量
self.font_size = font_size --字体大小 默认不显示
self.show_ani = show_ani --是否显示动画
end
function ProgressBarComponent:LoadSuccess()
self.bg_img = self.gameObject:GetComponent("Image")
self.front_bg = self:GetChild("front_img")
self.front_bg_img = self:GetChild("front_img"):GetComponent(typeof(UnityEngine.UI.Image))
self.middle_bg_obj = self:GetChild("middle_img").gameObject
self.middle_bg_img = self.middle_bg_obj:GetComponent(typeof(UnityEngine.UI.Image))
if self.bg_img_name then
lua_resM:setImageSprite(self, self.bg_img, self.ab_name, self.bg_img_name)
lua_resM:setImageSprite(self, self.front_bg:GetComponent("Image"), self.ab_name, self.front_img_name)
end
SetSizeDelta(self.transform, self.width, self.height)
self.front_bg.sizeDelta = Vector2(self.width - 2 * self.rect_off.x, self.height - self.rect_off.y * 2)
-- self.front_bg.localPosition = Vector3(self.rect_off.x - self.width / 2, -self.rect_off.y + self.height / 2, 0)
self.front_bg.anchoredPosition = Vector3(self.rect_off.x, -self.rect_off.y, 0)
self.transform.localPosition = Vector3(3, 0, 0)
self:SetValue()
end
function ProgressBarComponent:SetValue(value, max_value, show_ani)
self.curr_value = value or self.curr_value or 0
self.max_value = max_value or self.max_value or 100
self.curr_value = math.min(self.curr_value, self.max_value)
local rate = self.curr_value / self.max_value
self.front_bg_img.fillAmount = rate
if self.effectCon then
local x = (self.front_bg.sizeDelta.x - 16) * rate + 8
self.effectCon.localPosition = Vector2(x, 0)
end
if self.roleEmptyCon then
self.roleEmptyCon.localPosition = Vector2(self.front_bg.sizeDelta.x * rate, 0)
end
if self.imageCon then
self.imageCon.anchoredPosition = Vector2(self.front_bg.sizeDelta.x * rate + 59, -38)
end
local can_show_anim = show_ani or false
if self.middle_bg_obj and self.middle_bg_obj.activeSelf ~= can_show_anim then
self.middle_bg_obj:SetActive(can_show_anim)
end
if can_show_anim then
if self.tween_hp_id then
TweenLite.Stop(self.tween_hp_id)
self.tween_hp_id = nil
end
self.tween_hp_id = TweenLite.to(self, self.middle_bg_img, TweenLite.UiAnimationType.FILLAMOUNT, rate, 0.45)
end
end
function ProgressBarComponent:SetFrontImageStyle(front_img_name)
self.front_img_name = front_img_name
lua_resM:setImageSprite(self, self.front_bg:GetComponent("Image"), self.ab_name, self.front_img_name)
end
function ProgressBarComponent:__delete()
--destroy(self.gameObject)
end
function ProgressBarComponent:GetImageCon()
if not self.imageCon then
self.imageCon = UiFactory.createChild(self.front_bg, UIType.Image3, "imageCon").transform
self.imageCon.pivot = Vector2(1, 0)
self.imageCon.anchorMin = Vector2(0, 1)
self.imageCon.anchorMax = Vector2(0, 1)
self.imageCon.anchoredPosition = Vector2(59, -38)
end
return self.imageCon
end