summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/XFxMgr.cs
blob: b0da3691c4611e6a8c3f8e3580f5a917e4ce1073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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();
		}
	}
}