コード例 #1
0
ファイル: SoundBusControls.cs プロジェクト: uchr/LD44
    public void SetVoiceStealing(bool value)
    {
        useVoiceStealing = value;

        if (spawner == null)
        {
            return;
        }

        Stem.Sound sound = Stem.SoundManager.GetSound(spawner.soundName);
        if (sound == null)
        {
            return;
        }

        Stem.SoundBus bus = sound.Bus;
        if (bus != null)
        {
            bus.AllowVoiceStealing = useVoiceStealing;
        }

        if (text != null)
        {
            text.text = string.Format("Bus \"{0}\", Voices: {1}", bus.Name, bus.Polyphony);
        }
    }
コード例 #2
0
        private void PlayInternal(Vector3 position, AudioClip clip, float volume_, float pitch_, float delay_)
        {
            paused = false;

            volume = volume_;
            pitch  = pitch_;
            delay  = delay_;

            SoundBus bus = sound.Bus;

            source.clip   = clip;
            source.volume = volume * bus.Volume;
            source.pitch  = pitch;
            source.loop   = looped;

            source.spatialBlend = sound.SpatialBlend;
            source.panStereo    = sound.PanStereo;
            source.dopplerLevel = sound.DopplerLevel;
            source.spread       = sound.Spread;
            source.rolloffMode  = (AudioRolloffMode)sound.AttenuationMode;
            source.minDistance  = sound.MinDistance;
            source.maxDistance  = sound.MaxDistance;

            source.PlayDelayed(delay);
            source.outputAudioMixerGroup = bus.MixerGroup;

            transform.localPosition = position;
        }
コード例 #3
0
        internal void Play3D(string name, Vector3 position, float volume, float pitch)
        {
            Sound sound = bank.GetSound(name);

            if (sound == null)
            {
                return;
            }

            SoundBus bus = sound.Bus;

            if (bus == null)
            {
                bus = bank.DefaultBus;
            }

            SoundBusRuntime runtime = null;

            if (!busRuntimes.TryGetValue(bus, out runtime))
            {
                return;
            }

            SoundInstance instance = runtime.GrabSound(sound);

            if (instance == null)
            {
                return;
            }

            instance.Play3D(position, volume, pitch);
        }
コード例 #4
0
ファイル: SoundBankInspector.cs プロジェクト: uchr/LD44
        private void OnSoundBusPanelGUI(SoundBus bus, List <SoundBus> removedBuses)
        {
            EditorGUILayout.BeginHorizontal();

            bus.Name   = EditorGUILayout.TextField(bus.Name, GUILayout.ExpandWidth(true));
            bus.Volume = EditorGUILayout.Slider(bus.Volume, 0.0f, 1.0f);

            bus.Muted    = GUILayout.Toggle(bus.Muted, "M", "button", defaultWidth, GUILayout.ExpandWidth(false));
            bus.Soloed   = GUILayout.Toggle(bus.Soloed, "S", "button", defaultWidth, GUILayout.ExpandWidth(false));
            bus.Unfolded = GUILayout.Toggle(bus.Unfolded, "Edit", "button", GUILayout.ExpandWidth(false));

            bool canRemove = (bus != bank.DefaultBus);

            if (canRemove && GUILayout.Button("-", defaultWidth, GUILayout.ExpandWidth(false)))
            {
                removedBuses.Add(bus);
            }

            EditorGUILayout.EndHorizontal();

            if (bus.Unfolded)
            {
                EditorGUILayout.BeginVertical("groupbox");

                bus.MixerGroup         = (AudioMixerGroup)EditorGUILayout.ObjectField("Output", bus.MixerGroup, typeof(AudioMixerGroup), false);
                bus.Polyphony          = (byte)EditorGUILayout.IntSlider("Polyphony", bus.Polyphony, 1, 32);
                bus.AllowVoiceStealing = EditorGUILayout.Toggle("Allow Voice Stealing", bus.AllowVoiceStealing);

                EditorGUILayout.EndVertical();
            }
        }
コード例 #5
0
        /// <summary>
        /// Adds a new sound bus to the sound bank.
        /// </summary>
        /// <param name="name">Name of the sound bus.</param>
        /// <returns>
        /// A reference to a newly created sound bus.
        /// </returns>
        public SoundBus AddSoundBus(string name)
        {
            SoundBus bus = new SoundBus(this, name);

            buses.Add(bus);
            runtime.AddSoundBus(bus);
            return(bus);
        }
コード例 #6
0
 /// <summary>
 /// Prepares sound bank for serialization.
 /// </summary>
 /// <remarks>
 /// <para>This method is automatically called by Unity during serialization process. Don't call it manually.</para>
 /// </remarks>
 public void OnBeforeSerialize()
 {
     if (sounds.Count > 0)
     {
         busIndices = new int[sounds.Count];
         for (int i = 0; i < sounds.Count; i++)
         {
             SoundBus bus = sounds[i].Bus;
             busIndices[i] = buses.IndexOf(bus);
         }
     }
 }
コード例 #7
0
ファイル: SoundBankInspector.cs プロジェクト: uchr/LD44
        private int GetBusIndex(SoundBus bus)
        {
            for (int i = 0; i < bank.Buses.Count; i++)
            {
                if (bank.Buses[i] == bus)
                {
                    return(i);
                }
            }

            return(-1);
        }
コード例 #8
0
        internal void Update()
        {
            if (sound == null)
            {
                return;
            }

            SoundBus bus = sound.Bus;

            source.mute   = !sound.Audible;
            source.volume = volume * bus.Volume;
            source.pitch  = pitch;
        }
コード例 #9
0
ファイル: SoundBusRuntime.cs プロジェクト: uchr/LD44
        internal SoundBusRuntime(Transform transform, SoundBus bus_)
        {
            bus = bus_;

            root = new GameObject();
            root.transform.parent = transform;
            root.name             = bus.Name;

            freeSounds = new List <SoundInstance>(bus.Polyphony);
            usedSounds = new List <SoundInstance>(bus.Polyphony);

            for (int i = 0; i < bus.Polyphony; i++)
            {
                SoundInstance managedInstance = new SoundInstance(null, string.Format("Sound {0}", i + 1), root.transform);
                freeSounds.Add(managedInstance);
            }
        }
コード例 #10
0
        internal void AddSoundBus(SoundBus bus)
        {
            List <SoundBus> busList = null;

            if (!busByName.TryGetValue(bus.Name, out busList))
            {
                busList = new List <SoundBus>();
                busByName.Add(bus.Name, busList);
            }

            busList.Add(bus);

            if (bus.Soloed)
            {
                SoloedSoundBuses++;
            }
        }
コード例 #11
0
ファイル: SoundBankInspector.cs プロジェクト: uchr/LD44
        private void OnSoundPanelGUI(Sound sound, List <Sound> removedSounds)
        {
            EditorGUILayout.BeginHorizontal();

            sound.Name = EditorGUILayout.TextField(sound.Name, GUILayout.ExpandWidth(true));

            int index = GetBusIndex(sound.Bus);

            index = EditorGUILayout.Popup(index, GetBusNames(), GUILayout.ExpandWidth(true));

            SoundBus newBus = (index != -1) ? bank.Buses[index] : bank.DefaultBus;

            sound.Bus = newBus;

            sound.Muted    = GUILayout.Toggle(sound.Muted, "M", "button", defaultWidth, GUILayout.ExpandWidth(false));
            sound.Soloed   = GUILayout.Toggle(sound.Soloed, "S", "button", defaultWidth, GUILayout.ExpandWidth(false));
            sound.Unfolded = GUILayout.Toggle(sound.Unfolded, "Edit", "button", GUILayout.ExpandWidth(false));

            if (GUILayout.Button("-", defaultWidth, GUILayout.ExpandWidth(false)))
            {
                removedSounds.Add(sound);
            }

            EditorGUILayout.EndHorizontal();

            if (sound.Unfolded)
            {
                EditorGUILayout.BeginVertical("groupbox");

                sound.PanStereo    = SliderWithLabels("Stereo Pan", sound.PanStereo, "Left", "Right", -1.0f, 1.0f);
                sound.SpatialBlend = SliderWithLabels("Spatial Blend", sound.SpatialBlend, "2D", "3D", 0.0f, 1.0f);

                sound.DopplerLevel    = EditorGUILayout.Slider("Doppler Level", sound.DopplerLevel, 0.0f, 5.0f);
                sound.Spread          = EditorGUILayout.Slider("Spread", sound.Spread, 0.0f, 360.0f);
                sound.AttenuationMode = (AttenuationMode)EditorGUILayout.EnumPopup("Volume Rolloff", (System.Enum)sound.AttenuationMode);
                sound.MinDistance     = EditorGUILayout.FloatField("Min Distance", Mathf.Max(0.0f, sound.MinDistance));
                sound.MaxDistance     = EditorGUILayout.FloatField("Max Distance", Mathf.Max(0.0f, sound.MaxDistance));

                sound.VariationRetriggerMode = (RetriggerMode)EditorGUILayout.EnumPopup("Retrigger Mode", (System.Enum)sound.VariationRetriggerMode);

                ReorderableList list = FetchReorderableList(sound);
                list.DoLayoutList();

                EditorGUILayout.EndVertical();
            }
        }
コード例 #12
0
        internal void RemoveSoundBus(SoundBus bus)
        {
            List <SoundBus> busList = null;

            if (!busByName.TryGetValue(bus.Name, out busList))
            {
                return;
            }

            int index = busList.IndexOf(bus);

            if (index != -1)
            {
                busList.RemoveAt(index);
            }

            if (bus.Soloed)
            {
                SoloedSoundBuses--;
            }
        }
コード例 #13
0
        /// <summary>
        /// Prepares sound bank for runtime use after deserialization.
        /// </summary>
        /// <remarks>
        /// <para>This method is automatically called by Unity during deserialization process. Don't call it manually.</para>
        /// </remarks>
        public void OnAfterDeserialize()
        {
            for (int i = 0; i < sounds.Count; i++)
            {
                Sound    sound = sounds[i];
                SoundBus bus   = null;
                if (busIndices != null)
                {
                    int index = busIndices[i];
                    bus = (index != -1) ? buses[index] : null;
                }
                sound.Bus  = bus;
                sound.Bank = this;
            }

            foreach (SoundBus bus in buses)
            {
                bus.Bank = this;
            }

            SoundManager.RegisterBank(this);
        }
コード例 #14
0
        /// <summary>
        /// Removes existing sound bus from the sound bank.
        /// </summary>
        /// <param name="bus">A reference to a sound bus.</param>
        /// <remarks>
        /// <para>This method does nothing if the sound bus was not found in the sound bank.</para>
        /// </remarks>
        public void RemoveSoundBus(SoundBus bus)
        {
            if (buses.Count == 1)
            {
                return;
            }

            int index = buses.IndexOf(bus);

            if (index != -1)
            {
                buses.RemoveAt(index);
            }

            foreach (Sound sound in sounds)
            {
                if (sound.Bus == bus)
                {
                    sound.Bus = DefaultBus;
                }
            }

            runtime.RemoveSoundBus(bus);
        }