Inheritance: UnityEngine.MonoBehaviour
示例#1
0
        void Start()
        {
            SerenityEngine.Instance.RegisterAgent(this);
            isListenerChecker = isListener;
            if (isListener) {
                listener = gameObject.AddComponent<FMODUnity.StudioListener> ();
                SerenityEngine.Instance.RegisterAgentAsListener(this);
            }
            serenityEventHolder = new GameObject ();
            serenityEventHolder.name = "SerenityAgentContent";
            //serenityEventHolder.hideFlags = HideFlags.HideInHierarchy;
            serenityEventHolder.transform.SetParent (gameObject.transform);

            //TODO PUT IT IN ENGINE
            foreach (SerenityCallback sc in SerenityEngine.Instance.GetCallbacks (agentName))
                serenityEventHolder.AddComponent<SerenitySound>().Event = sc.fmodEvent;
        }
        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);
        }