Beispiel #1
0
 public static bool AddListener(int index)
 {
     if (HasListener[index])
     {
         // Listener already registered
         Debug.LogError(string.Format(("[FMOD] Listener with index {0} already registered."), index));
         return(false);
     }
     HasListener[index] = true;
     numListeners       = RecalculateTotalListeners();
     StudioSystem.setNumListeners(numListeners);
     return(true);
 }
Beispiel #2
0
        public static bool RemoveListener(int index)
        {
            if (index != -1 && HasListener[index])
            {
                HasListener[index] = false;
                numListeners       = RecalculateTotalListeners();

                if (StudioSystem.isValid())
                {
                    StudioSystem.setNumListeners(Math.Max(numListeners, 1));
                    return(true);
                }
            }
            if (numListeners <= 0)
            {
                Debug.LogWarning("[FMOD] No Listeners currently assigned.");
            }
            return(false);
        }
        public static bool RemoveListener(StudioListener listener)
        {
            int index = listener.ListenerNumber;

            // Remove listener
            if (index != -1)
            {
                Listeners[index] = null;

                // Are there more listeners above the index of the one we are removing?
                if (numListeners - 1 > index)
                {
                    // Move any higher index listeners down
                    for (int i = index; i < Listeners.Count; i++)
                    {
                        if (i == Listeners.Count - 1)
                        {
                            Listeners[i] = null;
                        }
                        else
                        {
                            Listeners[i] = Listeners[i + 1];
                            if (Listeners[i])
                            {
                                Listeners[i].ListenerNumber = i;
                            }
                        }
                    }
                }
                // Decriment numListeners
                numListeners--;
                // Always need at least 1 listener, otherwise "[FMOD] assert : assertion: 'numListeners >= 1 && numListeners <= 8' failed"
                int numListenersClamped = Mathf.Min(Mathf.Max(numListeners, 1), FMOD.CONSTANTS.MAX_LISTENERS);
                StudioSystem.setNumListeners(numListenersClamped);
                // Listener attributes will be updated before the next update, due to the Script Execution Order.
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public static int AddListener(StudioListener listener)
        {
            // Is the listener already in the list?
            for (int i = 0; i < Listeners.Count; i++)
            {
                if (Listeners[i] != null && listener.gameObject == Listeners[i].gameObject)
                {
                    Debug.LogWarning(string.Format(("[FMOD] Listener has already been added at index {0}."), i));
                    return(i);
                }
            }
            // If already at the max numListeners
            if (numListeners >= FMOD.CONSTANTS.MAX_LISTENERS)
            {
                Debug.LogWarning(string.Format(("[FMOD] Max number of listeners reached : {0}."), FMOD.CONSTANTS.MAX_LISTENERS));
                //return -1;
            }

            // If not already in the list
            // The next available spot in the list should be at `numListeners`
            if (Listeners.Count <= numListeners)
            {
                Listeners.Add(listener);
            }
            else
            {
                Listeners[numListeners] = listener;
            }
            // Increment `numListeners`
            numListeners++;
            // setNumListeners (8 is the most that FMOD supports)
            int numListenersClamped = Mathf.Min(numListeners, FMOD.CONSTANTS.MAX_LISTENERS);

            StudioSystem.setNumListeners(numListenersClamped);
            return(numListeners - 1);
        }