miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/View/Unit/MonsterView.lua

174 lines
6.6 KiB
Lua

local RoleConfig = ConfigManager.GetConfig(ConfigName.RoleConfig)
local SpiritAnimal = ConfigManager.GetConfig(ConfigName.SpiritAnimal)
local SkillLogicConfig = ConfigManager.GetConfig(ConfigName.SkillLogicConfig)
local healEffect = "c_xy_0012_skeff_tapsk_healeff"
local rageEffect = "s_jieling_hs_3006_skeff_casting_buff_nuqi"
MonsterView = BattleUnit.New()
function MonsterView.New(go, role, position, root)
local o = BattleUnit.New(go, role, position, root)
setmetatable(o, MonsterView)
MonsterView.__index = MonsterView
o:ctor(go, role, position, root)
return o
end
function MonsterView:onCreate(go, role, position, root)
self.spLoader = SpriteLoader.New()
self.RootPanel = root
self.GameObject = go
self.role = role
self.camp = role.camp
-- 创建技能播放器
self.castingEfectNode = role.camp == 0 and self.RootPanel.lingshouCastDown or self.RootPanel.lingshouCastUp
self.castingNameNode = Util.GetGameObject(self.castingEfectNode, role.camp == 0 and "EFFECT_Casting_LingShou_Xia/DongHua/MingZi" or "EFFECT_Casting_LingShou_Shang/DongHua/MingZi")
self.skillCastRoot = role.camp == 0 and self.RootPanel.lingshouCastDownRoot or self.RootPanel.lingshouCastUpRoot
self.liveRoot = role.camp == 0 and Util.GetGameObject(self.RootPanel.gameObject, "playerMonster/live") or Util.GetGameObject(self.RootPanel.gameObject, "enemyMonster/live")
self.icon = Util.GetGameObject(go, "icon"):GetComponent("Image")
-- 获取数据
self.livePath = GetResourcePath(SpiritAnimal[role.roleData.id].Live)
self.play_liveScale = SpiritAnimal[role.roleData.id].play_liveScale
self.enemy_liveScale = SpiritAnimal[role.roleData.id].enemy_liveScale
self.offset = SpiritAnimal[role.roleData.id].offset
self.outOffset = SpiritAnimal[role.roleData.id].enemy_offset
self.spAtkTime = SpiritAnimal[role.roleData.id].CastingSkills/1000
self.atkSoundTime = SpiritAnimal[role.roleData.id].CastingAudio/1000
self.attackSound = SpiritAnimal[role.roleData.id].sond
self.icon.sprite = self.spLoader:LoadSprite(GetResourcePath(SpiritAnimal[role.roleData.id].Icon))
-- 人物立绘
-- self.RoleLiveGO = poolManager:LoadLive(self.livePath, self.skillCastRoot.transform.parent, Vector3.one, Vector3.zero)
-- self.RoleLiveGO.transform:SetParent(self.liveRoot.transform)
-- self.RoleLiveGO:GetComponent("RectTransform").anchoredPosition = Vector2.New(self.outOffset[1], self.outOffset[2])-- * 0.5
-- self.RoleLiveGO.transform.localScale = Vector3.one * self.enemy_liveScale --* 0.75
-- self.RoleLiveGO:SetActive(false)
-- self.RoleLiveGOGraphic = self.RoleLiveGO:GetComponent("SkeletonGraphic")
-- self.RoleLiveGOTran = self.RoleLiveGO:GetComponent("RectTransform")
-- self.RoleLiveGOGraphic.AnimationState:SetAnimation(0, "idle", true)
-- self.RoleLiveGOTran.sizeDelta = Vector2.New(1000, 1000)
-- casting技能立绘
self.RoleLiveGO2 = poolManager:LoadLive(self.livePath, self.skillCastRoot.gameObject.transform.parent, Vector3.one, Vector3.zero)
self.RoleLiveGO2.transform:SetParent(self.skillCastRoot.gameObject.transform)
local offset = self.camp == 0 and self.offset or self.outOffset
self.RoleLiveGO2:GetComponent("RectTransform").anchoredPosition = Vector2.New(offset[1], offset[2])
if self.camp==1 then
self.RoleLiveGO2.transform.rotation=Vector3.New(0,180,0)
end
local scale = self.camp == 0 and self.play_liveScale or self.enemy_liveScale
self.RoleLiveGO2.transform.localScale = Vector3.one * scale --* 2
self.RoleLiveGO2:SetActive(false)
self.RoleLiveGOGraphic2 = self.RoleLiveGO2:GetComponent("SkeletonGraphic")
self.RoleLiveGOTran2 = self.RoleLiveGO2:GetComponent("RectTransform")
self.RoleLiveGOGraphic2.AnimationState:SetAnimation(0, "idle", true)
self.RoleLiveGOTran2.sizeDelta = Vector2.New(1000, 1000)
-- 创建技能播放器
self.SkillCaster = SkillCaster.New(self, self.spAtkTime, self.atkSoundTime, self.attackSound, self.castingEfectNode, self.castingNameNode)
if IsOpenBattleDebug then
local URoleProperty = go:GetComponent(typeof(RoleProperty))
if not URoleProperty then
URoleProperty = go:AddComponent(typeof(RoleProperty))
end
self.URoleProperty = URoleProperty
self.URoleProperty.uid = role.uid
role.data:Foreach(function (name, value)
self.URoleProperty:AddProperty(name, value)
end)
end
end
--
function MonsterView:OnSortingOrderChange(battleSorting)
end
function MonsterView:Update()
if IsOpenBattleDebug then
self.role.data:Foreach(function (name, value)
self.URoleProperty:SetValue(name, value)
end)
end
end
-- 缩放
function MonsterView:DoScale(scale, dur, func)
if func then
func()
end
end
-- 设置高亮
function MonsterView:SetHighLight(isLight, eScale, dur, func)
if func then
func()
end
end
-- 播放动画
function MonsterView:PlaySpineAnim(gog, time, name, isLoop)
if isLoop then
gog.AnimationState:SetAnimation(time, name, isLoop)
else
local _complete = nil
_complete = function(state)
gog.AnimationState.Complete = gog.AnimationState.Complete - _complete
gog.AnimationState:SetAnimation(0, "attack", true)
end
gog.AnimationState:ClearTracks() -- 清除上一个动画的影响(修复概率攻击动画播放错误的问题)
gog.AnimationState:SetAnimation(time, name, isLoop)
gog.AnimationState.Complete = gog.AnimationState.Complete + _complete
end
end
--
function MonsterView:OnSkillCastStart()
-- self.RoleLiveGO:SetActive(true)
end
--
function MonsterView:OnSkillPlay()
--self:PlaySpineAnim(self.RoleLiveGOGraphic, 0, "attack", false)
end
--
function MonsterView:OnSkillEnd()
-- self.RoleLiveGO:SetActive(false)
end
function MonsterView:OnSkillCastingStart()
if self.RoleLiveGO2 then
-- 提前进入下一阶段
self.RoleLiveGO2:SetActive(true)
self:PlaySpineAnim(self.RoleLiveGOGraphic2, 0, "attack", false)
end
end
function MonsterView:OnSkillCastingEnd()
if self.RoleLiveGO2 then
self.RoleLiveGO2:SetActive(false)
end
end
function MonsterView:onDispose()
self.spLoader:Destroy()
--
Util.SetSpineGray(self.RoleLiveGOGraphic2, false)
Util.SetColor(self.RoleLiveGOGraphic2, Color.New(1, 1, 1, 1))
self.RoleLiveGOGraphic2.freeze = false
-- poolManager:UnLoadLive(self.livePath, self.RoleLiveGO2)
GameObject.DestroyImmediate(self.RoleLiveGO2)
self.RoleLiveGO2 = nil
-- 回收本节点
BattlePool.RecycleItem(self.GameObject, BATTLE_POOL_TYPE.ENEMY_ROLE)
end