示例#1
0
 public static void Precache(SoundCue cue)
 {
     if (cue != null)
     {
         cue.Precache();
     }
 }
示例#2
0
    void Awake()
    {
#if UNITY_EDITOR
        if (!UnityEditor.EditorApplication.isPlaying)
        {
            OnValidate();
            return;
        }
#endif
        MusicList.Add(this);
        if (Current == null || audio.playOnAwake)
        {
            Current = this;
        }
        MusicSource  = new SoundCue(audio);
        SamplingRate = audio.clip.frequency;
        if (audio.loop)
        {
            SamplesInLoop = audio.clip.samples;
            Section lastSection    = sections[sections.Count - 1];
            long    samplesPerUnit = (long)(SamplingRate * (60.0 / (lastSection.Tempo_ * lastSection.mtBeat_)));
            long    samplesPerBar  = samplesPerUnit * lastSection.mtBar_;
            NumLoopBar = lastSection.StartTiming_.bar +
                         Mathf.RoundToInt((float)(SamplesInLoop - lastSection.StartTimeSamples_) / (float)samplesPerBar);
        }

        Initialize();

        OnSectionChanged();
    }
示例#3
0
    new void Awake()
    {
        if (CheckInstance())
        {
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
            return;
        }


        Current = this;
        MusicList.Add(this);
#if ADX
        MusicSource = new SoundCue(GetComponent <CriAtomSource>());
        ACBData     = CriAtom.GetAcb(MusicSource.source.cueSheet);
        ACBData.GetCueInfo(MusicSource.source.cueName, out CueInfo);
#else
        MusicSource = new SoundCue(GetComponent <AudioSource>());
#endif
        QuantizedCue = new List <SoundCue>();

        SamplesPerUnit = (long)(SamplingRate * (60.0 / (Tempo_ * mtBeat_)));
        SamplesPerBeat = SamplesPerUnit * mtBeat_;
        SamplesPerBar  = SamplesPerUnit * mtBar_;

        MusicTimeUnit = (double)SamplesPerUnit / (double)SamplingRate;

        Initialize();
    }
示例#4
0
        public void PlaySound(SoundCue cue)
        {
            if (!LoadedSongs.Keys.Contains(cue))
            {
                LoadedSongs.Add(cue, _content.Load<SoundEffect>(getFilename(cue)));
            }

            LoadedSongs[cue].Play(XnaDartsGame.Options.Volume, 0, 0);
        }
        public static void PrecacheSounds(this GameObject go)
        {
            var sounds = go.GetComponentsInAllChildren <SoundEntity>();

            for (int i = 0; i < sounds.Length; ++i)
            {
                SoundCue.Precache(sounds[i].soundCue);
            }
        }
示例#6
0
        public void PlaySound(SoundCue cue)
        {
            if (!LoadedSongs.Keys.Contains(cue))
            {
                LoadedSongs.Add(cue, _content.Load <SoundEffect>(getFilename(cue)));
            }

            LoadedSongs[cue].Play(XnaDartsGame.Options.Volume, 0, 0);
        }
示例#7
0
        private string getFilename(SoundCue cue)
        {
            var dir = @"Sounds\";

            switch (cue)
            {
            case SoundCue.MenuSelect:
                return(dir + "select");

            case SoundCue.MenuEnter:
                return(dir + "enter");

            case SoundCue.MenuBack:
                return(dir + "enter");

            case SoundCue.SingleBull:
                return(dir + "singlebullseye");

            case SoundCue.DoubleBull:
                return(dir + "doublebullseye");

            case SoundCue.GameStart:
                return(dir + "gamestart");

            case SoundCue.Won:
                return(dir + "applause");

            case SoundCue.Bust:
                return(dir + "bust");

            case SoundCue.LastRound:
                return(dir + "finalround");

            case SoundCue.NewRound:
                return(dir + "roundstart");

            case SoundCue.ThrowStart:
                return(dir + "throwstart");

            case SoundCue.Single:
                return(dir + "single");

            case SoundCue.Double:
                return(dir + "double");

            case SoundCue.Triple:
                return(dir + "triple");

            case SoundCue.CricketClosed:
                return(dir + "cricketclosed");
            }

            return("");
        }
    public AudioSource Play(Actor instigator, SoundCue sound, double time, float random, float random2, float random3, float random4, float random5)
    {
        if ((instigator != null) && (sound != null) && (sound.audioSourcePrefab != null))
        {
            MixerGroupState groupState;
            PlayingSource   playingSource;

            if (!CanPlay(instigator, instigator.go, sound, time, out groupState, out playingSource))
            {
                return(null);
            }

            var clip = sound.RandomClip(random, random2);
            if (clip != null)
            {
                AudioSource source = GameObject.Instantiate(sound.audioSourcePrefab);
                source.gameObject.name         = sound.name + "(" + clip.name + ")";
                source.transform.parent        = instigator.go.transform;
                source.transform.localPosition = Vector3.zero;
                source.transform.localRotation = Quaternion.identity;
                source.clip          = clip;
                source.volume        = sound.RandomVolume(random3);
                source.pitch         = sound.RandomPitch(random4);
                source.reverbZoneMix = sound.RandomReverb(random5);
                source.loop          = sound.loop;
                source.Play();

                if (groupState != null)
                {
                    groupState.hasPlayed    = true;
                    groupState.lastTime     = time;
                    playingSource.hasPlayed = true;
                    playingSource.lastTime  = time;
                    var sourcePair = new SourcePair();
                    sourcePair.audioSource   = source;
                    sourcePair.playingSource = playingSource;
                    playingSource.sources.Add(sourcePair);
                    groupState.activeSources.Add(sourcePair);
                    ++groupState.currentVoiceCount;
                }
                else
                {
                    source.gameObject.AddComponent <AudioSourceGC>();
                }

                return(source);
            }
        }

        return(null);
    }
示例#9
0
        public void AddSoundCue()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Audio Files|*.mp3;*.wav;*.aiff";

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                SoundCue cue = new SoundCue();
                cue.FileName = ofd.FileName;
                cue.Title    = Path.GetFileName(ofd.FileName);

                _cueList.Add(cue);
            }
        }
示例#10
0
        private string getFilename(SoundCue cue)
        {
            var dir = @"Sounds\";
            switch (cue)
            {
                case SoundCue.MenuSelect:
                    return dir + "select";
                case SoundCue.MenuEnter:
                    return dir + "enter";
                case SoundCue.MenuBack:
                    return dir + "enter";
                case SoundCue.SingleBull:
                    return dir + "singlebullseye";
                case SoundCue.DoubleBull:
                    return dir + "doublebullseye";
                case SoundCue.GameStart:
                    return dir + "gamestart";
                case SoundCue.Won:
                    return dir + "applause";
                case SoundCue.Bust:
                    return dir + "bust";
                case SoundCue.LastRound:
                    return dir + "finalround";
                case SoundCue.NewRound:
                    return dir + "roundstart";
                case SoundCue.ThrowStart:
                    return dir + "throwstart";
                case SoundCue.Single:
                    return dir + "single";
                case SoundCue.Double:
                    return dir + "double";
                case SoundCue.Triple:
                    return dir + "triple";
                case SoundCue.CricketClosed:
                    return dir + "cricketclosed";
            }

            return "";
        }
示例#11
0
文件: Sfx.cs 项目: puos/EAProjectV2
    private void Awake()
    {
        if (m_anim == null)
        {
            m_anim = gameObject.GetComponent <Animation>();
        }

        if (soundCue == null)
        {
            soundCue = gameObject.GetComponent <SoundCue>();
        }

        if (m_anim != null)
        {
            m_anim.playAutomatically = false;
        }

        for (int i = 0; i < m_particles.Count; ++i)
        {
            ParticleSystem.MainModule main = EAFrameUtil.Call <ParticleSystem.MainModule>(m_particles[i].main);
            main.playOnAwake = false;
        }

        ParticleSystem selfparticle = gameObject.GetComponent <ParticleSystem>();

        if (selfparticle != null)
        {
            int idx = m_particles.FindIndex(x => x.GetInstanceID() == selfparticle.GetInstanceID());

            if (idx == -1)
            {
                ParticleSystem.MainModule main = EAFrameUtil.Call <ParticleSystem.MainModule>(selfparticle.main);
                main.playOnAwake = false;

                m_particles.Add(selfparticle);
            }
        }
    }
示例#12
0
 /// <summary>
 /// Quantize to musical time( default is 16 beat ).
 /// </summary>
 /// <param name="source">your sound source( Unity AudioSource or ADX CriAtomSource )</param>
 public static void QuantizePlay(SoundCue source)
 {
     Current.QuantizedCue.Add(source);
 }
 void Awake()
 {
     snd           = GetComponent <SoundCue>();
     refireTimeout = tapFireTime - .01f;
     justDrawn     = true;
 }
    bool CanPlay(Actor actor, GameObject go, SoundCue sound, double time, out MixerGroupState groupState, out PlayingSource playingSource)
    {
        groupState    = null;
        playingSource = null;

        if (sound.audioSourcePrefab.outputAudioMixerGroup != null)
        {
            if (_mixerState.TryGetValue(sound.audioSourcePrefab.outputAudioMixerGroup, out groupState))
            {
                if (groupState.hasPlayed && (groupState.mixerControl.maxGroupRate > 0f))
                {
                    double d = time - groupState.lastTime;
                    if (d < groupState.mixerControl.maxGroupRate)
                    {
                        return(false);
                    }
                }

                if (go != null)
                {
                    if (!groupState.playingSources.TryGetValue(go, out playingSource))
                    {
                        playingSource       = new PlayingSource();
                        playingSource.go    = go;
                        playingSource.actor = actor;
                        groupState.playingSources.Add(go, playingSource);
                    }
                }
                else
                {
                    playingSource = groupState.positionalSource;
                }

                if (playingSource.hasPlayed && (groupState.mixerControl.maxSourceRate > 0f))
                {
                    double d = time - playingSource.lastTime;
                    if (d < groupState.mixerControl.maxSourceRate)
                    {
                        return(false);
                    }
                }

                if (groupState.mixerControl.maxGroupVoices > 0)
                {
                    if (groupState.currentVoiceCount >= groupState.mixerControl.maxGroupVoices)
                    {
                        var  stopSource = groupState.activeSources[0];
                        bool shouldStop = true;

                        if (groupState.mixerControl.groupLimit == ELimitMode.Discard)
                        {
                            bool discard = true;

                            if (groupState.mixerControl.maxSourceVoices > 0)
                            {
                                if (playingSource.sources.Count >= groupState.mixerControl.maxSourceVoices)
                                {
                                    if (groupState.mixerControl.sourceLimit != ELimitMode.Discard)
                                    {
                                        if (playingSource != stopSource.playingSource)
                                        {
                                            // the group limit has been reached and the source
                                            // will not stop it.
                                            return(false);
                                        }

                                        // the source voice limit will force a sound on the group to stop from
                                        // this source, satisfying the group limit
                                        discard    = false;
                                        shouldStop = false;
                                    }
                                }
                            }

                            if (discard)
                            {
                                return(false);
                            }
                        }

                        if (shouldStop)
                        {
                            // stop the oldest playing voice...
                            if (groupState.mixerControl.maxSourceVoices > 0)
                            {
                                if (playingSource.sources.Count >= groupState.mixerControl.maxSourceVoices)
                                {
                                    if (groupState.mixerControl.sourceLimit == ELimitMode.Discard)
                                    {
                                        if (playingSource != stopSource.playingSource)
                                        {
                                            // the source limit has been reached, even if we stopped this voice
                                            // it won't play so don't stop it.
                                            return(false);
                                        }
                                    }

                                    // the source voice limit will force a sound on the group to stop from
                                    // this source, satisfying the group limit
                                    shouldStop = false;
                                }
                            }
                        }

                        if (shouldStop)
                        {
                            if (stopSource.audioSource != null)
                            {
                                Utils.DestroyGameObject(stopSource.audioSource.gameObject);
                            }
                            stopSource.playingSource.sources.Remove(stopSource);
                            groupState.activeSources.RemoveAt(0);
                            --groupState.currentVoiceCount;
                        }
                    }
                }

                if (groupState.mixerControl.maxSourceVoices > 0)
                {
                    if (playingSource.sources.Count >= groupState.mixerControl.maxSourceVoices)
                    {
                        if (groupState.mixerControl.sourceLimit == ELimitMode.Discard)
                        {
                            return(false);
                        }

                        var stopSource = playingSource.sources[0];

                        if (stopSource.audioSource != null)
                        {
                            Utils.DestroyGameObject(stopSource.audioSource.gameObject);
                        }

                        groupState.activeSources.Remove(stopSource);
                        playingSource.sources.RemoveAt(0);
                        --groupState.currentVoiceCount;
                    }
                }
            }
        }

        return(true);
    }
示例#15
0
 private void OnSoundCueDead(SoundCue soundCue)
 {
     m_aliveSoundCueList.Remove(soundCue);
     m_deadSoundCueList.Add(soundCue);
 }
示例#16
0
        public override void Initialize()
        {
            try
            {
                string filePath = Game.Content.RootDirectory + "\\corecontent\\sounds\\sounddefs.xml";
                var document = new XmlDocument();
                document.Load(filePath);
                var soundNodes = document.SelectNodes("group/sound");
                var errors = false;
                foreach (XmlNode sound in soundNodes)
                {
                    var baseName = sound.Attributes["name"].Value.ToLower(CultureInfo.InvariantCulture);

                    var loopAttribute = sound.Attributes["loop"];
                    bool loop = (loopAttribute != null ? Boolean.Parse(loopAttribute.Value) : false);

                    var spatialAttribute = sound.Attributes["spatial"];
                    bool spatial = (spatialAttribute != null ? Boolean.Parse(spatialAttribute.Value) : true);

                    var volumeAttribute = sound.Attributes["volume"];
                    float volume = (volumeAttribute != null ? (float)Double.Parse(volumeAttribute.Value, CultureInfo.InvariantCulture) : 1.0f);

                    var distAttribute = sound.Attributes["distancescale"];
                    float dist = (distAttribute != null ? (float)Double.Parse(distAttribute.Value, CultureInfo.InvariantCulture) : 200.0f);

                    // Find all variations for a sound
                    var effects = Enumerable.Range(1, 99)
                        .Select(i => string.Format("{0}{1:00}", baseName, i))
                        .TakeWhile(name => Game.Content.Exists<SoundEffect>(name))
                        .Select(name => Game.Content.Load<SoundEffect>(name))
                        .ToArray();
                    if (!effects.Any())
                    {
                        errors = true;
                        Log.Write("Error loading sound " + baseName);
                    }
                    var cue = new SoundCue(effects, volume, dist, loop);
                    _soundCues.Add(baseName, cue);
                }
                if (errors) throw new ApplicationException("Couldn't load some sounds");
                Log.Write("Sound engine initialized.");
            }
            catch (NoAudioHardwareException e)
            {
                Log.Write("ERROR: There will be no sound. Sound engine initialization failed. Exception details: " + e);
                Enabled = false;
            }
        }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(_playChance);

        _volume.vector2Value = GUILayoutHelpers.MinMaxSlider("Volume", _volume.vector2Value, 0, 1);
        _pitch.vector2Value  = GUILayoutHelpers.MinMaxSlider("Pitch", _pitch.vector2Value, -3, 3);
        _reverb.vector2Value = GUILayoutHelpers.MinMaxSlider("Reverb", _reverb.vector2Value, 0, 1.1f);

        EditorGUILayout.PropertyField(_loop);
        EditorGUILayout.PropertyField(_clipRef);

        var newClip = _clip.Load();

        if (newClip != _loaded)
        {
            _loaded = newClip;
            StopPlaying();
        }

        var oldPrefab = _audioSourcePrefab.objectReferenceValue;

        EditorGUILayout.PropertyField(_audioSourcePrefab, true);
        if (!ReferenceEquals(oldPrefab, _audioSourcePrefab.objectReferenceValue))
        {
            StopPlaying();
        }

        SoundCue self = (SoundCue)target;

        var wasEnabled = GUI.enabled;

        if (_source == null)
        {
            GUI.enabled = (_loaded != null) && (self.audioSourcePrefab != null);
            if (GUILayout.Button("Play"))
            {
                string unused;
                var    clipToPlay = _loaded.RandomClip(Random.value, out unused);
                if (clipToPlay != null)
                {
                    var go = (GameObject)GameObject.Instantiate(self.audioSourcePrefab.gameObject, Vector3.zero, Quaternion.identity);
                    go.hideFlags = HideFlags.HideAndDontSave;

                    _source = go.GetComponent <AudioSource>();
                    go.AddComponent <AudioSourceGC>();

                    _source.spatialBlend  = 0f;
                    _source.clip          = clipToPlay;
                    _source.volume        = self.RandomVolume(Random.value);
                    _source.pitch         = self.RandomPitch(Random.value);
                    _source.reverbZoneMix = self.RandomReverb(Random.value);
                    _source.loop          = _loop.boolValue;
                    _source.Play();

                    EditorApplication.update += Update;
                }
            }
        }
        else
        {
            GUI.enabled = true;
            if (GUILayout.Button("Stop"))
            {
                StopPlaying();
            }
        }
        GUI.enabled = wasEnabled;

        serializedObject.ApplyModifiedProperties();
    }
示例#18
0
 public void RemoveCue(SoundCue cue)
 {
     _cueList.Remove(cue);
 }
		public void ClientPrecache() {
			SoundUtils.PrecacheWithSounds(fxPrefab);
			SoundCue.Precache(soundCue);
		}