From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs | 143 +++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs (limited to 'Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs') 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 + { + 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(); + } + } +} -- cgit v1.1-26-g67d0