summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/FMOD/XFmodUIEvent.cs
blob: 984a6ee28b4cf42eb9648fd58357a6774ae75794 (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
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<XFmod>();

        if (iFmod == null)
            iFmod = go.AddComponent<XFmod>();
        
        return iFmod;
    }
}