|
|
- -- <*
- -- @Author: Saber
- -- @Description: 经验副本主界面子弹粒子特效容器
- -- *>
- ExpHangupBulletItem = ExpHangupBulletItem or BaseClass(BaseItem)
- local ExpHangupBulletItem = ExpHangupBulletItem
-
- local sin = math.sin
- local cos = math.cos
- local rad = math.rad
- local ClearTrailRenderer = ClearTrailRenderer
-
- local lua_soundM = lua_soundM
-
- function ExpHangupBulletItem:__init(parent_wnd,prefab_asset,layer_name, bullet_type)
- self.base_file = "expDun"
- self.layout_file = "ExpHangupBulletItem"
- self.parent_wnd = parent_wnd
- self.layer_name = layer_name
- self.bullet_type = bullet_type or 1
- self.is_animing = false -- 是否在动画中
- self.model = ExpDunModel:getInstance()
- self.bullet_sound_shot1 = LuaSoundManager.SOUND_UI.EXPBULLETSHOT1
- self.bullet_sound_shot2 = LuaSoundManager.SOUND_UI.EXPBULLETSHOT2
- self.bullet_sound_laser = LuaSoundManager.SOUND_UI.EXPBULLETLASER
- self:Load()
- end
-
- function ExpHangupBulletItem:Load_callback()
- local nodes = {
- "effect:obj",
- "extra_effect1:obj",
- "extra_effect2:obj",
- }
- self:GetChildren(nodes)
-
- self:AddEvents()
- if self.need_refreshData then
- if self.is_normal_bullet then -- 正常特效子弹
- self:UpdateNormalBulletEffect()
- else -- 另一种特效子弹
- self:StartSlayBulletAnim()
- end
- end
- end
-
- function ExpHangupBulletItem:AddEvents( )
-
- end
-
- function ExpHangupBulletItem:SetData( data )
- self.start_pos = data.start_pos
- self.anim_time = data.anim_time
- self.callback = data.callback
- self.show_effect_type = data.show_effect_type
- self.is_normal_bullet = data.is_normal_bullet
-
- if self.is_loaded then
- self.need_refreshData = false
- if self.is_normal_bullet then -- 正常特效子弹
- self:UpdateNormalBulletEffect()
- else -- 另一种特效子弹
- self:StartSlayBulletAnim()
- end
- else
- self.need_refreshData = true
- end
- end
- function ExpHangupBulletItem:SetItemIndex(index)
- self.index = index
- end
- function ExpHangupBulletItem:GetItemIndex( )
- return self.index
- end
- function ExpHangupBulletItem:GetIsAnimating( )
- return self.is_animing
- end
- function ExpHangupBulletItem:UpdateNormalBulletEffect( )
- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.transform)
- local hited = false
- local function hit_anim_druation(percent)
- if not hited and percent >= 0.75 then
- if self.callback then
- self.callback()
- self.callback = nil -- 回调执行一次就销毁
- end
- hited = true
- end
- if percent >= 1 then
- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.transform)
- self.is_animing = false
- end
- end
- local hit_anim_action = cc.CustomUpdate.New(self.anim_time, hit_anim_druation)
- -- 调整坐标,创建动画
- local function load_finished_func()
- SetAnchoredPosition(self.transform, self.start_pos.x, self.start_pos.y)
- cc.ActionManager:getInstance():addAction(hit_anim_action, self.transform)
- end
- -- 创建粒子效果
- local p_config = {
- resname = "effect_fangzhi_attack",
- uiTranform = self.effect,
- layer_name = self.layer_name,
- pos = Vector2(0,0),
- scale = 0.7,
- is_loop = false,
- last_time = -1,
- load_finish_func = load_finished_func,
- layer = UIPartical.RenderingOther_List.UI,
- use_ex_depth = true,
- }
- self:AddUIEffectConfig(p_config)
- -- 播放声音
- local random_num = math.random(0, 100)
- if random_num < 50 then
- lua_soundM:PlayUIEffectSound(self.bullet_sound_shot1)
- else
- lua_soundM:PlayUIEffectSound(self.bullet_sound_shot2)
- end
- self.is_animing = true
- end
-
- function ExpHangupBulletItem:StartSlayBulletAnim( )
- -- 根据类型调整特效
- if self.show_effect_type then
- self:ClearUIEffect(self.effect)
- -- 创建粒子效果
- local p_config = {
- resname = self.show_effect_type % 2 == 1 and "effect_fangzhi_attack2" or "effect_fangzhi_attack3",
- uiTranform = self.show_effect_type % 2 == 1 and self.extra_effect1 or self.extra_effect2,
- layer_name = self.layer_name,
- pos = Vector2(0,0),
- scale = 0.7,
- is_loop = false,
- last_time = -1,
- layer = UIPartical.RenderingOther_List.UI,
- use_ex_depth = true,
- }
- self:AddUIEffectConfig(p_config)
- self:ClearUIEffect(self.show_effect_type % 2 == 1 and self.extra_effect2 or self.extra_effect1)
- -- 播放声音
- if self.show_effect_type % 2 == 1 then
- local random_num = math.random(0, 100)
- if random_num < 50 then
- lua_soundM:PlayUIEffectSound(self.bullet_sound_shot1)
- else
- lua_soundM:PlayUIEffectSound(self.bullet_sound_shot2)
- end
- else
- lua_soundM:PlayUIEffectSound(self.bullet_sound_laser)
- end
- end
- -- 调整坐标,创建动画
- SetAnchoredPosition(self.transform, self.start_pos.x, self.start_pos.y)
- end
-
- function ExpHangupBulletItem:StopUnHitBulletAnim( )
- if self.unhit_bullet_anim_id then
- GlobalTimerQuest:CancelQuest(self.unhit_bullet_anim_id)
- self.unhit_bullet_anim_id = nil
- end
- end
-
- function ExpHangupBulletItem:__delete( )
- cc.ActionManager:getInstance():removeAllActionsFromTarget(self.transform)
- self:ClearUIEffect(self.effect)
- self:ClearUIEffect(self.extra_effect1)
- self:ClearUIEffect(self.extra_effect2)
- self:StopUnHitBulletAnim()
- end
|