Ejemplo n.º 1
0
    public static void _playSoundDo(string eventName, GameObject voicer = null)
    {
        StudioEventEmitter studioEvent = null;

        if (!voicer)
        {
            var eventNameGo = eventName.Replace('/', '_');
            studioEvent = _root.FindChild <StudioEventEmitter>(eventNameGo, false);
            if (!studioEvent)
            {
                var go = new GameObject(eventNameGo);
                go.name = eventNameGo;
                go.transform.SetParent(_root.transform);
                go.transform.localPosition = Vector3.zero;
                studioEvent = go.GetMissComponent <StudioEventEmitter>();
                studioEvent.OverrideAttenuation = true;
                studioEvent.OverrideMaxDistance = int.MaxValue;
                studioEvent.OverrideMinDistance = int.MaxValue;
                studioEvent.SetVolume(Volume_Music);
            }
        }
        else
        {
            studioEvent = voicer.GetMissComponent <StudioEventEmitter>();
            if (studioEvent.IsPlaying())
            {
                studioEvent.Stop();
            }
            studioEvent.OverrideAttenuation = true;
            studioEvent.OverrideMaxDistance = 20;
            studioEvent.OverrideMinDistance = 3;
            studioEvent.SetVolume(Volume_Music);
            if (!_3dstudioEventList.Contains(studioEvent))
            {
                _3dstudioEventList.Add(studioEvent);
            }
        }
        studioEvent.Event = eventName;
        studioEvent.Play();
    }