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/FMOD/XFmodUIEvent.cs | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Client/Assets/Scripts/FMOD/XFmodUIEvent.cs (limited to 'Client/Assets/Scripts/FMOD/XFmodUIEvent.cs') diff --git a/Client/Assets/Scripts/FMOD/XFmodUIEvent.cs b/Client/Assets/Scripts/FMOD/XFmodUIEvent.cs new file mode 100644 index 00000000..984a6ee2 --- /dev/null +++ b/Client/Assets/Scripts/FMOD/XFmodUIEvent.cs @@ -0,0 +1,46 @@ +using UnityEngine; +using System.Collections; + +public class XFmodUIEvent : MonoBehaviour { + + static private GameObject _ui_audio = null; + + public string Name = ""; + public float Delay = 0; + private float _start_time; + void Start () { + if (_ui_audio == null) + { + if (GameObject.Find("UIRoot") != null) + _ui_audio = GameObject.Find("UIRoot").gameObject; + else + _ui_audio = GameObject.Find("UIRoot(Clone)").gameObject; + } + _start_time = UnityEngine.Time.time; + } + + void FixedUpdate () { + + if (UnityEngine.Time.time - _start_time > Delay) + { + XFmod iFmod; + if (_ui_audio != null) + { + iFmod = GetFmodComponent(_ui_audio); + iFmod.PlayOneShot("event:/" + Name, Vector3.zero); + } + + Destroy(this); + } + } + + public XFmod GetFmodComponent(GameObject go) + { + XFmod iFmod = go.GetComponent(); + + if (iFmod == null) + iFmod = go.AddComponent(); + + return iFmod; + } +} -- cgit v1.1-26-g67d0