Exemplo n.º 1
0
        private static void CreateSoundBankFromClips()
        {
            List <AudioClip> clips = new List <AudioClip>();

            for (int i = 0; i < Selection.objects.Length; i++)
            {
                AudioClip clip = Selection.objects[i] as AudioClip;
                if (clip != null)
                {
                    clips.Add(clip);
                }
            }

            clips.Sort((x, y) => x.name.CompareTo(y.name));

            if (clips.Count > 0)
            {
                EffectSoundBank bank = ScriptableObject.CreateInstance <EffectSoundBank>();
                bank.SetClips(clips.ToArray());

                string path = AssetDatabase.GetAssetPath(clips[0]);
                path  = path.Substring(0, path.LastIndexOf("/"));
                path += "/" + clips[0].name + ".asset";

                AssetDatabase.CreateAsset(bank, AssetDatabase.GenerateUniqueAssetPath(path));
                AssetDatabase.SaveAssets();

                Selection.activeObject = bank;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fetches and then plays a sound that will follow a transform around.
        /// </summary>
        /// <param name="followTransform">The transform to follow</param>
        public static EffectSoundInstance Play(this EffectSoundBank soundBank, Transform followTransform)
        {
            if (soundBank != null && (soundBank.Cooldown <= 0 || soundBank.TimeSinceLastPlayed > soundBank.Cooldown))
            {
                EffectSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance);
                sound.Play3D(followTransform);
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Fetches and then plays a sound at a specific position.
        /// </summary>
        /// <param name="position">The world-space position of the sound emission</param>
        public static EffectSoundInstance Play(this EffectSoundBank soundBank, Vector3 position)
        {
            if (soundBank != null && (soundBank.Cooldown <= 0 || soundBank.TimeSinceLastPlayed > soundBank.Cooldown))
            {
                EffectSoundInstance sound = soundBank.Fetch(RuntimeSoundPool.Instance);
                sound.Play3D(position);
                soundBank.OnPlayed(sound);

                return(sound);
            }

            return(null);
        }