예제 #1
0
    public bool GenerateSound(string instrumentName, int soundCacheCount, List <string> instrumentSoundPath, Transform parent)
    {
        if (sounds.ContainsKey(instrumentName))
        {
            Debug.LogWarning("Already Sound Generated Instrument = " + instrumentName);
            return(false);
        }
        else
        {
            Queue <GameObject> queue     = new Queue <GameObject>();
            List <string>      soundPath = new List <string>();

            for (int i = 0; i < soundCacheCount; i++)
            {
                GameObject go = soundFactory.Load(SoundSystem.Instance.SoundMenu.SoundMenuPrefabPath);

                if (!go)
                {
                    Debug.LogError("SoundFactory GenerateSound Load Error!");
                    return(false);
                }

                go.transform.SetParent(parent);
                go.transform.localScale    = Vector3.one;
                go.transform.localPosition = new Vector3(transform.position.x, transform.position.y, 0);
                go.transform.localRotation = Quaternion.Euler(Vector3.zero);

                if (instrumentSoundPath[i] != String.Empty)
                {
                    AudioSource audio = go.AddComponent <AudioSource>();
                    audio.playOnAwake = false;
                    audio.clip        = Resources.Load(instrumentSoundPath[i]) as AudioClip;
                }
                else
                {
                    go.AddComponent <AudioSource>();
                }

                queue.Enqueue(go);
            }

            sounds.Add(instrumentName, queue);
        }

        return(true);
    }
예제 #2
0
        private void playPloep()
        {
            return;

            if (emitter.Playing)
            {
                return;
            }
            var sounds = new[]
            {
                SoundFactory.Load("Scattered\\Sound\\Ploep1.wav"),
                SoundFactory.Load("Scattered\\Sound\\Ploep2.wav"),
                SoundFactory.Load("Scattered\\Sound\\Ploep3.wav")
            };

            emitter.Sound = sounds[r.Next(0, 2)];
            emitter.Start();
        }
예제 #3
0
        public void TestSoundEmitter()
        {
            var engine = new LocalGame();

            engine.AddSimulator(new AudioSimulator());

            var emitter = new SoundEmitter();

            emitter.Sound   = SoundFactory.Load("Core\\TestSound.wav");
            emitter.Playing = true;
            emitter.Loop    = true;


            emitter         = new SoundEmitter();
            emitter.Sound   = SoundFactory.Load("Core\\TestSoundAmbient.wav");
            emitter.Playing = true;

            engine.Run();
        }