diff --git a/lua/app/bf/unity/character_spine_object.lua b/lua/app/bf/unity/character_spine_object.lua index e7059913..7f443044 100644 --- a/lua/app/bf/unity/character_spine_object.lua +++ b/lua/app/bf/unity/character_spine_object.lua @@ -202,6 +202,13 @@ function CharacterSpineObject:getAnimationDuration(animationName) return 0 end +function CharacterSpineObject:getAnimationKeyFrameTime(animationName) + if self.characterSpineHelper then + return self.characterSpineHelper:GetAnimationKeyFrameTime(animationName) + end + return 0 +end + function CharacterSpineObject:addAnimationCompleteCallback(callback) if self._animationStateCompleteCallback then return diff --git a/lua/app/module/battle/battle_manager.lua b/lua/app/module/battle/battle_manager.lua index 1006ef01..03f0507f 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 @@ -267,4 +268,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/module/battle/component/battle_unit_comp.lua b/lua/app/module/battle/component/battle_unit_comp.lua index d2ef6d34..5a2c34c4 100644 --- a/lua/app/module/battle/component/battle_unit_comp.lua +++ b/lua/app/module/battle/component/battle_unit_comp.lua @@ -59,6 +59,7 @@ function BattleUnitComp:_initBase() self.switchTime = 0 self.isPlayHurt = 0 self.attackDurationMap = {} + self.attackKeyFrameTimeMap = {} self.shieldBuffList = {} self.activeSkillIndex = nil self.currActiveSkill = nil @@ -106,6 +107,18 @@ function BattleUnitComp:getAnimationDuration(aniName) return duration or 0 end +function BattleUnitComp:getAnimationKeyFrameTime(animationName) + local time = self.attackKeyFrameTimeMap[animationName] + if time == nil then + time = self.baseObject:getAnimationKeyFrameTime(animationName) + if time <= 0 then -- 容错处理 + time = 0.3 + end + self.attackKeyFrameTimeMap[animationName] = time + end + return time +end + function BattleUnitComp:useAssistingSkill(count, callback) local skill = self.unitEntity:getAssistingSkill() if skill == nil then @@ -379,11 +392,11 @@ function BattleUnitComp:enterAssistingAttackState() self.attackOver = false self.attackTime = 0 self.isMove = false - self.currAttackKeyTime = 0.3 local skill = self.unitEntity:getAssistingSkill() skill:startUse() local attackName = skill:getSkillAttackName() self.currAttackDuration = self:getAnimationDuration(attackName) + self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) self:initPosition() end @@ -415,7 +428,6 @@ end function BattleUnitComp:enterSkillAttackState() self.attackOver = false self.attackTime = 0 - self.currAttackKeyTime = 0.3 self.targetX = nil local skill if self.normalSkillCount > 0 then @@ -445,6 +457,7 @@ function BattleUnitComp:enterSkillAttackState() attackName = skill:getSkillAttackName() end self.currAttackDuration = self:getAnimationDuration(attackName) + self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) end end @@ -554,24 +567,23 @@ end function BattleUnitComp:doNextSkillAttack() self.attackTime = 0 - self.currAttackKeyTime = 0.3 local attackName = self.currActiveSkill:getSkillAttackName() self.currAttackDuration = self:getAnimationDuration(attackName) + self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) end function BattleUnitComp:doNextNormalAttack() self.attackTime = 0 - self.currAttackKeyTime = 0.3 local skill = self.unitEntity:getNormalSkill() local attackName = skill:getRandomNormalAttackName() self.currAttackDuration = self:getAnimationDuration(attackName) + self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) end function BattleUnitComp:doNextAttack() self.attackTime = 0 - self.currAttackKeyTime = 0.3 local attackName = nil if self.normalSkillCount > 0 then local skill = self.unitEntity:getNormalSkill() @@ -581,6 +593,7 @@ function BattleUnitComp:doNextAttack() end if attackName then self.currAttackDuration = self:getAnimationDuration(attackName) + self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) else -- 归位 self:moveBackToInitPosition() @@ -590,7 +603,6 @@ end function BattleUnitComp:enterNormalAttackState() self.attackOver = false self.attackTime = 0 - self.currAttackKeyTime = 0.3 local skill = self.unitEntity:getNormalSkill() skill:startUse() if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then @@ -609,6 +621,7 @@ function BattleUnitComp:enterNormalAttackState() self.attackTime = 0 local attackName = skill:getRandomNormalAttackName() self.currAttackDuration = self:getAnimationDuration(attackName) + self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName) self:playAnimation(attackName, false, false) end end diff --git a/lua/app/ui/battle/battle_ui.lua b/lua/app/ui/battle/battle_ui.lua index 35886858..cd1bab70 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