using System; using System.Collections.Generic; using UnityEngine; namespace XUtliPoolLib { public class XFxMgr : XSingleton { private Dictionary _fxs = new Dictionary(); private XTimerMgr.ElapsedEventHandler _innerDestroyFxCb = null; public int CameraLayerMask = -1; public static bool EmptyFx = false; public static bool FilterFarFx = false; public static float FilterFxDis0 = 200f; public static float FilterFxDis1 = 300f; public static float FilterFxDis2 = 500f; public static float FilterFxDis4 = 1600f; public static int maxBehitFx = 3; public static int currentBeHitFx = 0; public static float minBehitFxTime = 0.1f; public static float lastBehitFxTime = 0f; public static int MaxParticelCount = -1; public XFxMgr() { this._innerDestroyFxCb = new XTimerMgr.ElapsedEventHandler(this.InnerDestroyFx); } public XFx CreateFx(string prefab_location, LoadCallBack loadFinish = null, bool async = true) { XFx xfx = XFx.CreateXFx(prefab_location, loadFinish, async); this._fxs.Add(xfx._instanceID, xfx); return xfx; } public XFx CreateAndPlay(string location, XGameObject parent, Vector3 offset, Vector3 scale, float speed_ratio = 1f, bool follow = false, float duration = -1f, bool async = true) { XFx xfx = this.CreateFx(location, null, async); xfx.Play(parent, offset, scale, speed_ratio, follow, false, "", 0f); xfx.DelayDestroy = duration; XSingleton.singleton.DestroyFx(xfx, false); return xfx; } public XFx CreateAndPlay(string location, Transform parent, Vector3 offset, Vector3 scale, float speed_ratio = 1f, bool follow = false, float duration = -1f, bool async = true) { XFx xfx = this.CreateFx(location, null, async); xfx.Play(parent, offset, scale, speed_ratio, follow, false); xfx.DelayDestroy = duration; XSingleton.singleton.DestroyFx(xfx, false); return xfx; } public XFx CreateUIFx(string location, Transform parent, bool processMesh = false) { return this.CreateUIFx(location, parent, Vector3.one, processMesh); } public XFx CreateUIFx(string location, Transform parent, Vector3 scale, bool processMesh = false) { XFx xfx = this.CreateFx(location, processMesh ? XFx._ProcessMesh : null, true); int renderLayer = LayerMask.NameToLayer("UI"); xfx.SetRenderLayer(renderLayer); xfx.Play(parent, Vector3.zero, scale, 1f, true, false); xfx.RefreshUIRenderQueue(); return xfx; } public void DestroyFx(XFx fx, bool bImmediately = true) { XSingleton.singleton.KillTimer(fx.Token); bool flag = bImmediately || fx.DelayDestroy <= 0f; if (flag) { this.InnerDestroyFx(fx); } else { fx.Token = XSingleton.singleton.SetTimer(fx.DelayDestroy, this._innerDestroyFxCb, fx); } } public void OnLeaveScene() { this.Clear(); } public void OnLeaveStage() { this.Clear(); } public void PostUpdate() { foreach (KeyValuePair keyValuePair in this._fxs) { XFx value = keyValuePair.Value; bool flag = value != null; if (flag) { value.StickToGround(); } } } private void InnerDestroyFx(object o) { XFx xfx = o as XFx; bool flag = xfx == null; if (flag) { XSingleton.singleton.AddErrorLog("Destroy Fx error: ", o.ToString(), null, null, null, null); } else { this._fxs.Remove(xfx._instanceID); XFx.DestroyXFx(xfx, true); } } public void Clear() { foreach (KeyValuePair keyValuePair in this._fxs) { XFx.DestroyXFx(keyValuePair.Value, false); } this._fxs.Clear(); } } }