This commit is contained in:
xiekaidong 2023-04-18 17:58:32 +08:00
commit ac5183c0fe
4 changed files with 90 additions and 7 deletions

View File

@ -202,6 +202,13 @@ function CharacterSpineObject:getAnimationDuration(animationName)
return 0 return 0
end end
function CharacterSpineObject:getAnimationKeyFrameTime(animationName)
if self.characterSpineHelper then
return self.characterSpineHelper:GetAnimationKeyFrameTime(animationName)
end
return 0
end
function CharacterSpineObject:addAnimationCompleteCallback(callback) function CharacterSpineObject:addAnimationCompleteCallback(callback)
if self._animationStateCompleteCallback then if self._animationStateCompleteCallback then
return return

View File

@ -75,6 +75,7 @@ function BattleManager:clear()
self.battleController:clear() self.battleController:clear()
self.battleController = nil self.battleController = nil
DataManager.BattleData:clear() DataManager.BattleData:clear()
self.bindUnitAttributeData = nil
end end
@ -267,4 +268,64 @@ end
----------------------- 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 return BattleManager

View File

@ -59,6 +59,7 @@ function BattleUnitComp:_initBase()
self.switchTime = 0 self.switchTime = 0
self.isPlayHurt = 0 self.isPlayHurt = 0
self.attackDurationMap = {} self.attackDurationMap = {}
self.attackKeyFrameTimeMap = {}
self.shieldBuffList = {} self.shieldBuffList = {}
self.activeSkillIndex = nil self.activeSkillIndex = nil
self.currActiveSkill = nil self.currActiveSkill = nil
@ -106,6 +107,18 @@ function BattleUnitComp:getAnimationDuration(aniName)
return duration or 0 return duration or 0
end 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) function BattleUnitComp:useAssistingSkill(count, callback)
local skill = self.unitEntity:getAssistingSkill() local skill = self.unitEntity:getAssistingSkill()
if skill == nil then if skill == nil then
@ -379,11 +392,11 @@ function BattleUnitComp:enterAssistingAttackState()
self.attackOver = false self.attackOver = false
self.attackTime = 0 self.attackTime = 0
self.isMove = false self.isMove = false
self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getAssistingSkill() local skill = self.unitEntity:getAssistingSkill()
skill:startUse() skill:startUse()
local attackName = skill:getSkillAttackName() local attackName = skill:getSkillAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackDuration = self:getAnimationDuration(attackName)
self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName)
self:playAnimation(attackName, false, false) self:playAnimation(attackName, false, false)
self:initPosition() self:initPosition()
end end
@ -415,7 +428,6 @@ end
function BattleUnitComp:enterSkillAttackState() function BattleUnitComp:enterSkillAttackState()
self.attackOver = false self.attackOver = false
self.attackTime = 0 self.attackTime = 0
self.currAttackKeyTime = 0.3
self.targetX = nil self.targetX = nil
local skill local skill
if self.normalSkillCount > 0 then if self.normalSkillCount > 0 then
@ -445,6 +457,7 @@ function BattleUnitComp:enterSkillAttackState()
attackName = skill:getSkillAttackName() attackName = skill:getSkillAttackName()
end end
self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackDuration = self:getAnimationDuration(attackName)
self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName)
self:playAnimation(attackName, false, false) self:playAnimation(attackName, false, false)
end end
end end
@ -554,24 +567,23 @@ end
function BattleUnitComp:doNextSkillAttack() function BattleUnitComp:doNextSkillAttack()
self.attackTime = 0 self.attackTime = 0
self.currAttackKeyTime = 0.3
local attackName = self.currActiveSkill:getSkillAttackName() local attackName = self.currActiveSkill:getSkillAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackDuration = self:getAnimationDuration(attackName)
self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName)
self:playAnimation(attackName, false, false) self:playAnimation(attackName, false, false)
end end
function BattleUnitComp:doNextNormalAttack() function BattleUnitComp:doNextNormalAttack()
self.attackTime = 0 self.attackTime = 0
self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getNormalSkill() local skill = self.unitEntity:getNormalSkill()
local attackName = skill:getRandomNormalAttackName() local attackName = skill:getRandomNormalAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackDuration = self:getAnimationDuration(attackName)
self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName)
self:playAnimation(attackName, false, false) self:playAnimation(attackName, false, false)
end end
function BattleUnitComp:doNextAttack() function BattleUnitComp:doNextAttack()
self.attackTime = 0 self.attackTime = 0
self.currAttackKeyTime = 0.3
local attackName = nil local attackName = nil
if self.normalSkillCount > 0 then if self.normalSkillCount > 0 then
local skill = self.unitEntity:getNormalSkill() local skill = self.unitEntity:getNormalSkill()
@ -581,6 +593,7 @@ function BattleUnitComp:doNextAttack()
end end
if attackName then if attackName then
self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackDuration = self:getAnimationDuration(attackName)
self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName)
self:playAnimation(attackName, false, false) self:playAnimation(attackName, false, false)
else -- 归位 else -- 归位
self:moveBackToInitPosition() self:moveBackToInitPosition()
@ -590,7 +603,6 @@ end
function BattleUnitComp:enterNormalAttackState() function BattleUnitComp:enterNormalAttackState()
self.attackOver = false self.attackOver = false
self.attackTime = 0 self.attackTime = 0
self.currAttackKeyTime = 0.3
local skill = self.unitEntity:getNormalSkill() local skill = self.unitEntity:getNormalSkill()
skill:startUse() skill:startUse()
if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then if skill:getMoveType() == BattleConst.SKILL_MOVE_TYPE.MOVE then
@ -609,6 +621,7 @@ function BattleUnitComp:enterNormalAttackState()
self.attackTime = 0 self.attackTime = 0
local attackName = skill:getRandomNormalAttackName() local attackName = skill:getRandomNormalAttackName()
self.currAttackDuration = self:getAnimationDuration(attackName) self.currAttackDuration = self:getAnimationDuration(attackName)
self.currAttackKeyTime = self:getAnimationKeyFrameTime(attackName)
self:playAnimation(attackName, false, false) self:playAnimation(attackName, false, false)
end end
end end

View File

@ -91,7 +91,9 @@ end
function BattleUI:initHpNode() function BattleUI:initHpNode()
self.hpProgressLeft = self.uiMap["battle_ui.top_node.bg_l.atk_slider_green"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER) 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.hpTextLeft = self.uiMap["battle_ui.top_node.atk_hp"]
self.hpTextRight = self.uiMap["battle_ui.top_node.def_hp"] self.hpTextRight = self.uiMap["battle_ui.top_node.def_hp"]
end end