summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs')
-rw-r--r--Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs143
1 files changed, 143 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs b/Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs
new file mode 100644
index 00000000..b0da3691
--- /dev/null
+++ b/Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs
@@ -0,0 +1,143 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace XUtliPoolLib
+{
+ public class XFxMgr : XSingleton<XFxMgr>
+ {
+ private Dictionary<int, XFx> _fxs = new Dictionary<int, XFx>();
+
+ 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<XFxMgr>.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<XFxMgr>.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<XTimerMgr>.singleton.KillTimer(fx.Token);
+ bool flag = bImmediately || fx.DelayDestroy <= 0f;
+ if (flag)
+ {
+ this.InnerDestroyFx(fx);
+ }
+ else
+ {
+ fx.Token = XSingleton<XTimerMgr>.singleton.SetTimer(fx.DelayDestroy, this._innerDestroyFxCb, fx);
+ }
+ }
+
+ public void OnLeaveScene()
+ {
+ this.Clear();
+ }
+
+ public void OnLeaveStage()
+ {
+ this.Clear();
+ }
+
+ public void PostUpdate()
+ {
+ foreach (KeyValuePair<int, XFx> 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<XDebug>.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<int, XFx> keyValuePair in this._fxs)
+ {
+ XFx.DestroyXFx(keyValuePair.Value, false);
+ }
+ this._fxs.Clear();
+ }
+ }
+}