-- UIParticle.lua module("logic.common.ugui.UIParticle", package.seeall) local UIParticle = class("UIParticle") functionUIParticle:ctor(container) self._go = container.gameObject self._loader = PrefabLoader.Get(self._go) self._url = nil self._goInst = nil end functionUIParticle:load(url) if GameUtils.isEmptyString(url) then return end if url == self._url then return end self._url = url self._loader:load(url, self._onResLoaded, self) end functionUIParticle:_onResLoaded(loader) local goInst = loader and loader:getInst() if goutil.isNil(goInst) then return end goutil.addChildToParent(goInst, self._go) self._goInst = goInst self._comUIParticle = goInst:GetComponent(typeof(Coffee.UIExtensions.UIParticle)) ifself._effectLoadedCallback then ifself._effectLoadedCallbackObj then self._effectLoadedCallback(self._effectLoadedCallbackObj, goInst, res) else self._effectLoadedCallback(goInst, res) end end --检查美术是否有挂载EffectPlayer的组件 local _effectCSComp = goInst:GetComponent(typeof(Pjg.EffectPlayer)) if _effectCSComp andnot goutil.isNil(_effectCSComp) then --参数默认以组件的,暂不支持外部设置参数 _effectCSComp:AddFinishListener(self._onEffectPlayFinish, self) --加载好就立即执行play _effectCSComp:Play() end end --暂时没有全部播放完毕逻辑回调 functionUIParticle:_onEffectPlayFinish() if goutil.isNil(self._go) then return end ifself._effectFinishCallback then ifself._effectFinishCallbackObj then self._effectFinishCallback(self._effectFinishCallbackObj, self) else self._effectFinishCallback() end end end functionUIParticle:clear() if goutil.isNil(self._goInst) then return end --检查美术是否有挂载EffectPlayer的组件 local _effectCSComp = self._goInst:GetComponent(typeof(Pjg.EffectPlayer)) if _effectCSComp andnot goutil.isNil(_effectCSComp) then _effectCSComp:Stop() _effectCSComp:RemoveFinishListener() end end functionUIParticle:OnDestroy() self:clear() self._go = nil self._loader = nil self._url = nil self._goInst = nil self._effectLoadedCallback = nil self._effectLoadedCallbackObj = nil self._effectFinishCallback = nil self._effectFinishCallbackObj = nil end functionUIParticle:getGo() returnself._go end functionUIParticle:setEffectLoadedCallback(callback, callbackObj) self._effectLoadedCallback = callback self._effectLoadedCallbackObj = callbackObj end functionUIParticle:setEffectFinishCallback(callback, callbackObj) self._effectFinishCallback = callback self._effectFinishCallbackObj = callbackObj end functionUIParticle:play() if goutil.isNil(self._goInst) then return end ifself._goInst.activeSelf then goutil.setActive(self._goInst, false) end goutil.setActive(self._goInst, true) --检查美术是否有挂载EffectPlayer的组件 local _effectCSComp = self._goInst:GetComponent(typeof(Pjg.EffectPlayer)) if _effectCSComp andnot goutil.isNil(_effectCSComp) then _effectCSComp:Stop() _effectCSComp:RemoveFinishListener() --参数默认以组件的,暂不支持外部设置参数 _effectCSComp:AddFinishListener(self._onEffectPlayFinish, self) _effectCSComp:Play() end end functionUIParticle:setScale(scale) self._comUIParticle.scale = scale end functionUIParticle:setPos(x, y, z) GameUtils.setLocalPos(self._goInst, x, y, z or0) end return UIParticle