summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XAudioComponent.cs
blob: e091306c0454ebcbfce2b3e277aa66733e3013ca (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using UnityEngine;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XAudioComponent : XComponent
	{
		public override uint ID
		{
			get
			{
				return XAudioComponent.uuID;
			}
		}

		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("Audio");

		private IXFmod _emitter = null;

		private static CommandCallback _initCb = new CommandCallback(XAudioComponent._Init);

		private GameObject cachedGo;

		private static void _Init(XGameObject gameObject, object o, int commandID)
		{
			XAudioComponent xaudioComponent = o as XAudioComponent;
			xaudioComponent.cachedGo = gameObject.Get();
			xaudioComponent.InitEmitter();
		}

		private void InitEmitter()
		{
			bool flag = this._emitter != null && this.cachedGo != null;
			if (flag)
			{
				Rigidbody rigidbody = null;
				bool flag2 = this.cachedGo != null;
				if (flag2)
				{
					rigidbody = this.cachedGo.GetComponent<Rigidbody>();
				}
				this._emitter.Init(this.cachedGo, rigidbody);
			}
		}

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			bool flag = this._entity != null && this._entity.EngineObject != null;
			if (flag)
			{
				this._entity.EngineObject.CallCommand(XAudioComponent._initCb, this, -1, false);
			}
		}

		public override void Attached()
		{
		}

		protected override void EventSubscribe()
		{
			base.RegisterEvent(XEventDefine.XEvent_PlaySound, new XComponent.XEventHandler(this.Play));
		}

		public override void OnDetachFromHost()
		{
			bool flag = this._emitter != null;
			if (flag)
			{
				this._emitter.Destroy();
				XSingleton<XUpdater.XUpdater>.singleton.XPlatform.ReturnClass(EClassType.ERuntimeFMOD, this._emitter);
				this._emitter = null;
			}
			base.OnDetachFromHost();
		}

		public void StopChannel(AudioChannel channel)
		{
			bool flag = this._emitter != null;
			if (flag)
			{
				this._emitter.Stop(channel);
			}
		}

		public bool IsPlaying(AudioChannel channel)
		{
			bool flag = this._emitter != null;
			return flag && this._emitter.IsPlaying(channel);
		}

		public void Set3DPos(Vector3 pos)
		{
			bool flag = this._host == null;
			if (!flag)
			{
				bool flag2 = this._emitter == null;
				if (flag2)
				{
					this._emitter = (XSingleton<XUpdater.XUpdater>.singleton.XPlatform.CreateClass(EClassType.ERuntimeFMOD) as IXFmod);
					this.InitEmitter();
				}
				this._emitter.Update3DAttributes(pos, AudioChannel.Action);
			}
		}

		protected bool Play(XEventArgs e)
		{
			XPlaySoundArgs xplaySoundArgs = e as XPlaySoundArgs;
			XPlaySoundArgs.Action soundAction = xplaySoundArgs.SoundAction;
			AudioChannel soundChannel = xplaySoundArgs.SoundChannel;
			bool bUseFMOD = XSingleton<XAudioMgr>.singleton.bUseFMOD;
			if (bUseFMOD)
			{
				bool flag = this._emitter == null;
				if (flag)
				{
					this._emitter = (XSingleton<XUpdater.XUpdater>.singleton.XPlatform.CreateClass(EClassType.ERuntimeFMOD) as IXFmod);
					this.InitEmitter();
				}
				XPlaySoundArgs.Action action = soundAction;
				if (action != XPlaySoundArgs.Action.Play)
				{
					if (action == XPlaySoundArgs.Action.Stop)
					{
						this._emitter.Stop(soundChannel);
					}
				}
				else
				{
					bool flag2 = soundChannel == AudioChannel.Behit;
					if (flag2)
					{
						bool flag3 = xplaySoundArgs.ExParam != null && XEntity.ValideEntity(xplaySoundArgs.ExParam._caster) && xplaySoundArgs.ExParam._caster.IsRole;
						if (flag3)
						{
							float value = xplaySoundArgs.ExParam._caster.TypeID % 10u;
							this._emitter.StartEvent("event:/" + xplaySoundArgs.EventName, soundChannel, false, "attacktype", value);
							goto IL_24F;
						}
					}
					bool flag4 = this._entity != null && this._entity.IsPlayer && (soundChannel == AudioChannel.Skill || soundChannel == AudioChannel.SkillCombine);
					if (flag4)
					{
						this._emitter.Update3DAttributes(XSingleton<XScene>.singleton.GameCamera.CameraTrans.position, AudioChannel.Action);
					}
					else
					{
						bool flag5 = this._entity != null && this._entity.IsDummy;
						if (flag5)
						{
							this._emitter.Update3DAttributes(XSingleton<XScene>.singleton.GameCamera.CameraTrans.position, AudioChannel.Action);
						}
					}
					bool flag6 = xplaySoundArgs.ExParam != null && xplaySoundArgs.ExParam._3dPos != Vector3.zero;
					if (flag6)
					{
						this._emitter.Update3DAttributes(xplaySoundArgs.ExParam._3dPos, AudioChannel.Action);
					}
					bool flag7 = xplaySoundArgs.ExParam != null && !string.IsNullOrEmpty(xplaySoundArgs.ExParam._fmodParam);
					if (flag7)
					{
						this._emitter.StartEvent("event:/" + xplaySoundArgs.EventName, soundChannel, true, xplaySoundArgs.ExParam._fmodParam, xplaySoundArgs.ExParam._fmodValue);
					}
					else
					{
						this._emitter.StartEvent("event:/" + xplaySoundArgs.EventName, soundChannel, true, "", 0f);
					}
				}
				IL_24F:;
			}
			return true;
		}
	}
}