From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Assets/Scripts/XMainClient/XAudioComponent.cs | 177 +++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XAudioComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XAudioComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XAudioComponent.cs b/Client/Assets/Scripts/XMainClient/XAudioComponent.cs new file mode 100644 index 00000000..e091306c --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XAudioComponent.cs @@ -0,0 +1,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.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(); + } + 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.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.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.singleton.bUseFMOD; + if (bUseFMOD) + { + bool flag = this._emitter == null; + if (flag) + { + this._emitter = (XSingleton.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.singleton.GameCamera.CameraTrans.position, AudioChannel.Action); + } + else + { + bool flag5 = this._entity != null && this._entity.IsDummy; + if (flag5) + { + this._emitter.Update3DAttributes(XSingleton.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; + } + } +} -- cgit v1.1-26-g67d0