--动画 local AnimSystem = {} local FP=FP local LuaConst=LuaConst local _animTempV1 = FP.newV1(1) local FPDegree360 = FP.Const.Degree360 --[[ Tick --]] function AnimSystem.OnLogicUpdate(entity) local components=entity.components local comp_Anim = components.anim local comp_Move = components.move local comp_TimeScale = components.timeScale local comp_SkillBase = components.skillBase --设置动画持续时间 _animTempV1:Reset(LuaConst.TimeSpanMs):Mul(comp_TimeScale:GetCurTimeScale()) comp_Anim.StateLastPassTime:Reset(comp_Anim.StatePassTime) comp_Anim.StatePassTime:Add(_animTempV1) --设置动画是否结束 local animDurationMs = (comp_Anim.CurAnimDataCount - 1) * LuaConst.TimeSpanMs if not comp_Anim.CurAnimMoveData or FP.Greater(comp_Anim.StatePassTime, animDurationMs) then comp_Anim.IsCurAnimOver = true end --设置动画水平位移比例 local curSkill = comp_SkillBase.CurSkillData if curSkill and curSkill.MSStartTime ~= FP.Const.NegOne then local passTime = comp_Anim.StatePassTime if passTime >= FP.Const.Zero then local lastPassTime = comp_Anim.StateLastPassTime --进入 if lastPassTime <= curSkill.MSStartTime and passTime >= curSkill.MSStartTime then local maxDis = curSkill.MSMaxDis if curSkill.MSIsStopAtAim then local target = entity.components.target.Target local targetPos = comp_SkillBase.AimPos local modelRadius = 0 if targetPos == nil then targetPos = comp_SkillBase.MSAimPos end if targetPos == nil and target then targetPos = target.components.move.LogicPos modelRadius = target.components.base:GetShoveRadius() end if targetPos ~= nil then local targetDis = FP.V2.Distance(comp_Move.LogicPos, targetPos):Add(curSkill.MSStopAimOffset):Sub(modelRadius) if targetDis > maxDis then targetDis:Reset(maxDis) end comp_Anim.AnimDisPercent:Reset(targetDis):Div(curSkill.MSTotalDis):Div(comp_Anim.MoveSize) end else comp_Anim.AnimDisPercent:Reset(maxDis):Div(curSkill.MSTotalDis):Div(comp_Anim.MoveSize) end end --退出 if lastPassTime <= curSkill.MSEndTime and passTime > curSkill.MSEndTime then comp_Anim.AnimDisPercent:Reset(FP.Const.One) SystemManager.OnSetSkillAimPos(entity,nil) -- 一旦自动连接的一套技能中,任意一个出现伸缩,立即清理动作目标点 end end end -- 设置动画旋转缩放比例 if curSkill and curSkill.RSStartTime ~= FP.Const.NegOne then local passTime = comp_Anim.StatePassTime if passTime >= FP.Const.Zero then local lastPassTime = comp_Anim.StateLastPassTime --进入 if lastPassTime <= curSkill.RSStartTime and passTime > curSkill.RSStartTime then local aimDir = comp_SkillBase.RSAimDir if aimDir ~= nil then -- 没有目标,则按照原始的动画播放 local aimAngle = FP.V2.Angle(aimDir, comp_Move.LogicRotateDir) -- 角度大小: 0-180 local isOnTheRightSide = FP.V2.IsRotateClockwise(comp_Move.LogicRotateDir,aimDir) --左右: ; RSTotalAngle<0 向左转 ;RSTotalAngle >0 向右转 --策划说有的技能旋转角度超过360,但是一定是单一方向,不会两个方向 _animTempV1:Reset(FP.Math.Abs(curSkill.RSTotalAngle)):Div(FPDegree360) -- 转了几圈 _animTempV1:Reset( FP.Math.Floor(_animTempV1) ):Mul(FPDegree360) -- 一般情况这_animTempV1 = 0 if not isOnTheRightSide then -- 需要向左旋转 if curSkill.RSTotalAngle > FP.Const.Zero then --原动作向右转 aimAngle:Negative():Add(FPDegree360):Add(_animTempV1) else -- 原动作左转 aimAngle:Negative():Sub(_animTempV1) end else -- 需要向右旋转 if curSkill.RSTotalAngle > FP.Const.Zero then --原动作向右转 aimAngle:Add(_animTempV1) else--原动作向左转 aimAngle:Sub(FPDegree360):Sub(_animTempV1)-- 总的需要旋转的角度 end end -- 旋转角度小于策划要求的最小旋转角度时,则需转一圈 if FP.LessEquals(FP.Math.Abs(aimAngle) , curSkill.RSMinAngleLimit) then if aimAngle >= FP.Const.Zero then aimAngle:Add(FPDegree360) else aimAngle:Sub(FPDegree360) end end comp_Anim.AnimRotatePercent:Reset(aimAngle):Div(curSkill.RSTotalAngle) -- 缩放倍数 if comp_Anim.AnimRotatePercent[1] < 0 then -- 倍数不能小于0,否则就是向相反方向转了 logging.error(LTAG.ERROR, "[GWS] : 旋转缩放的倍数是负数了 ,方向转反啦!--代码问题 " , comp_Anim.AnimRotatePercent[1]) end end end --退出 if lastPassTime <= curSkill.RSEndTime and passTime > curSkill.RSEndTime then comp_Anim.AnimRotatePercent:Reset(FP.Const.One) SystemManager.SetSkillRSAimDir(entity,nil) -- 一旦自动连接的一套技能中,任意一个出现伸缩,立即清理缩放朝向 end end end end function AnimSystem.OnLogicUpdate_NPC(entity) local comp_Anim = entity.components.anim local comp_TimeScale = entity.components.timeScale --设置动画持续时间 _animTempV1:Reset(LuaConst.TimeSpanMs):Mul(comp_TimeScale:GetCurTimeScale()) comp_Anim.StateLastPassTime:Reset(comp_Anim.StatePassTime) comp_Anim.StatePassTime:Add(_animTempV1) --设置动画是否结束 local animDurationMs = (comp_Anim.CurAnimDataCount - 1) * LuaConst.TimeSpanMs if not comp_Anim.CurAnimMoveData or FP.Greater(comp_Anim.StatePassTime, animDurationMs) then comp_Anim.IsCurAnimOver = true end end function AnimSystem.OnBreak(entity) local comp_Anim = entity.components.anim comp_Anim.CurAnimMoveData = nil comp_Anim.CurAnimDataCount = 0 comp_Anim.CurAnimDataLock = false end function AnimSystem.OnChangeModel(entity,keepAnim) local comp_Anim = entity.components.anim local modelData = entity.components.base.CurModelData comp_Anim.AnimMoveDic,comp_Anim.AnimConditionDic = LuaDataManager.GetAnimData(modelData.ID,modelData.AnimID,modelData.AnimTransID) comp_Anim.MoveSize:Reset(modelData.ModelScale) if keepAnim then comp_Anim:UpdateCurAnimDataCache() end end function AnimSystem.ChangeMoveAnimationPlaySpeedState(entity,speedState) entity.components.anim.RunAnimSpeedState = speedState end function AnimSystem.SetAnimIDOverride(entity, originID, overrideToID) entity.components.anim:SetAnimIDOverride(originID, overrideToID) end return AnimSystem