From fd4e6d88c439f3650fd17a177724a673852107d8 Mon Sep 17 00:00:00 2001 From: chenxi Date: Tue, 18 Apr 2023 17:43:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/battle/battle_manager.lua | 61 ++++++++++++++++++++++++ lua/app/ui/battle/battle_ui.lua | 4 +- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/lua/app/module/battle/battle_manager.lua b/lua/app/module/battle/battle_manager.lua index b9b401cb..b8caaa7a 100644 --- a/lua/app/module/battle/battle_manager.lua +++ b/lua/app/module/battle/battle_manager.lua @@ -75,6 +75,7 @@ function BattleManager:clear() self.battleController:clear() self.battleController = nil DataManager.BattleData:clear() + self.bindUnitAttributeData = nil end @@ -262,4 +263,64 @@ end ----------------------- end 一些公共相关的方法 ----------------------------- +function BattleManager:bindBattleUnitAttribute(hashCode, side) + if self.battleController then + local team = nil + if side == 1 then + team = self.battleController.atkTeam + else + team = self.battleController.defTeam + end + local unitAttrHelper = nil + local teamEntity = nil + for _, unit in ipairs(team.unitList) do + local code = unit.baseObject:getGameObject():GetHashCode() + if code == hashCode then + if side == 1 then + unitAttrHelper = unit.baseObject:getComponent(typeof(CS.BF.BattleUnitAttr)) + else + unitAttrHelper = unit.baseObject:getComponent(typeof(CS.BF.BattleUnitAttr)) + end + teamEntity = unit.unitEntity.team + break + end + end + if unitAttrHelper and teamEntity then + -- 创建并绑定相关数据 + if self.bindUnitAttributeData == nil then + self.bindUnitAttributeData = {} + end + -- 组合必要数据 + local unitData = {} + unitData.unitAttrHelper = unitAttrHelper + unitData.teamEntity = teamEntity + + self.bindUnitAttributeData[hashCode] = unitData + -- bind方法 + unitAttrHelper:BindGetAttributeFunc(function(hashCode) + self:getBattleUnitAttribute(hashCode) + end) + -- 刷新数据 + self:getBattleUnitAttribute(hashCode) + end + end +end + +-- 将lua端属性传回CS端 +function BattleManager:getBattleUnitAttribute(hashCode) + if self.bindUnitAttributeData and self.bindUnitAttributeData[hashCode] then + local data = self.bindUnitAttributeData[hashCode] + local unitAttrHelper = data.unitAttrHelper + local teamEntity = data.teamEntity + if unitAttrHelper and teamEntity then + local attr = {} + for key, value in pairs(teamEntity.attr) do + attr[key] = value + end + attr.sheild_hp = teamEntity.shieldHp + unitAttrHelper:GetAttribute(json.encode(attr)) + end + end +end + return BattleManager \ No newline at end of file diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index fad43cc4..3be95f5f 100644 --- a/lua/app/ui/battle/battle_ui.lua +++ b/lua/app/ui/battle/battle_ui.lua @@ -91,7 +91,9 @@ end function BattleUI:initHpNode() self.hpProgressLeft = self.uiMap["battle_ui.top_node.bg_l.atk_slider_green"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) - self.hpProgressRight = self.uiMap["battle_ui.top_node.bg_r.atk_slider_red"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) + self.hpProgressRight = self.uiMap["battle_ui.top_node.bg_r.def_slider_red"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) + self.hpProgressYellowLeft = self.uiMap["battle_ui.top_node.bg_l.atk_slider_yellow"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) + self.hpProgressYellowRight = self.uiMap["battle_ui.top_node.bg_r.def_slider_yellow"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) self.hpTextLeft = self.uiMap["battle_ui.top_node.atk_hp"] self.hpTextRight = self.uiMap["battle_ui.top_node.def_hp"] end