示例#1
0
 /// <summary>
 /// Plays a UI sound effect
 /// </summary>
 /// <param name="name">the name of the sound effect</param>
 public void PlayUISoundEffect(UISoundEffect name)
 {
     if (uiSoundEffectsDict.ContainsKey(name))
     {
         uiAudioSource.PlayOneShot(uiSoundEffectsDict[name]);
     }
     else
     {
         Debug.Log("UI sound effect " + name.ToString() + " is not in the UI sound effects dictionary!");
     }
 }
示例#2
0
    protected virtual void OnDestroy()
    {
        if (m_current > 0 && AudioManager.instance)
        {
            AudioManager.Stop(m_current);
        }
        m_current = 0;

        m_sound = null;

        #if UNITY_EDITOR
        EventManager.RemoveEventListener(this);
        #endif
    }
示例#3
0
    private void OnEditorReloadConfig(Event_ e)
    {
        if (string.IsNullOrEmpty(tag))
        {
            return;
        }

        var config = (string)e.param1;

        if (config != "config_uisoundeffects")
        {
            return;
        }

        m_sound = UISoundEffect.GetSound(tag, name);
    }
示例#4
0
    public void PlayAudio(int type)
    {
        if (string.IsNullOrEmpty(tag))
        {
            return;
        }

        if (m_sound == null || m_sound.element != name)
        {
            m_sound = UISoundEffect.GetSound(tag, name);
        }

        var a = UISoundEffect.GetSound(m_sound == null ? null : type == 0 ? m_sound.onEnable : m_sound.onDisable);

        if (string.IsNullOrEmpty(a))
        {
            return;
        }

        AudioManager.PlayAudio(a, m_sound.type, false, 0, s => m_current = s ? s.id : 0);

        lastPlayed = type;
    }
示例#5
0
    private static void OnPreExecute(GameObject target, EventInterfaceTypes eventType)
    {
        onGlobalUIEvent?.Invoke(target, eventType);

        var tag = target.tag;
        var s   = string.IsNullOrEmpty(tag) ? UISoundEffect.empty : UISoundEffect.GetSound(tag, target.name);

        string[] ss = null;

        switch (eventType)
        {
        case EventInterfaceTypes.PointerEnter:              ss = s.onPointerEnter;             onPointerEnter?.Invoke(target);            break;

        case EventInterfaceTypes.PointerExit:               ss = s.onPointerExit;              onPointerExit?.Invoke(target);             break;

        case EventInterfaceTypes.PointerDown:               ss = s.onPointerDown;              onPointerDown?.Invoke(target);             break;

        case EventInterfaceTypes.PointerUp:                 ss = s.onPointerUp;                onPointerUp?.Invoke(target);               break;

        case EventInterfaceTypes.PointerClick:              ss = s.onPointerClick;             onPointerClick?.Invoke(target);            break;

        case EventInterfaceTypes.BeginDrag:                 ss = s.onBeginDrag;                onBeginDrag?.Invoke(target);               break;

        case EventInterfaceTypes.InitializePotentialDrag:   ss = s.onInitializePotentialDrag;  onInitializePotentialDrag?.Invoke(target); break;

        case EventInterfaceTypes.Drag:                      ss = s.onDrag;                     onDrag?.Invoke(target);                    break;

        case EventInterfaceTypes.EndDrag:                   ss = s.onEndDrag;                  onEndDrag?.Invoke(target);                 break;

        case EventInterfaceTypes.Drop:                      ss = s.onDrop;                     onDrop?.Invoke(target);                    break;

        case EventInterfaceTypes.Scroll:                    ss = s.onScroll;                   onScroll?.Invoke(target);                  break;

        case EventInterfaceTypes.UpdateSelected:            ss = s.onUpdateSelected;           onUpdateSelected?.Invoke(target);          break;

        case EventInterfaceTypes.Select:                    ss = s.onSelect;                   onSelect?.Invoke(target);                  break;

        case EventInterfaceTypes.Deselect:                  ss = s.onDeselect;                 onDeselect?.Invoke(target);                break;

        case EventInterfaceTypes.Move:                      ss = s.onMove;                     onMove?.Invoke(target);                    break;

        case EventInterfaceTypes.Submit:                    ss = s.onSubmit;                   onSubmit?.Invoke(target);                  break;

        case EventInterfaceTypes.Cancel:                    ss = s.onCancel;                   onCancel?.Invoke(target);                  break;

        case EventInterfaceTypes.Default:
        default: break;
        }

        var a = UISoundEffect.GetSound(ss);

        if (!string.IsNullOrEmpty(a))
        {
            if (s.type != AudioTypes.Sound)
            {
                var c = s.type == AudioTypes.Voice ? instance.m_lastVoice : instance.m_lastMusic;
                if (!string.IsNullOrEmpty(c))
                {
                    if (c == a && !s.@override && AudioManager.IsInPlayListOrLoading(a))
                    {
                        return;
                    }
                    AudioManager.Stop(c);
                }

                if (s.type == AudioTypes.Voice)
                {
                    instance.m_lastVoice = a;
                    AudioManager.PlayVoice(a);
                }
                else
                {
                    instance.m_lastMusic = a;
                    AudioManager.PlayMusic(a);
                }
            }
            else
            {
                AudioManager.PlaySound(a);
            }
        }
    }