示例#1
0
        /// <summary>
        /// Permanently deletes all AudioBuddyObjects and rebuilds AudioBuddySound objects from all available AudioClip assets in the project. This means that all settings on individual objects and randomizers and lists will be gone. Use with caution. Only works in editor.
        /// </summary>
        public void RebuildAudioBuddyObjectCollection()
        {
            if (AssetDatabase.IsValidFolder(CollectionAddress))
            {
                Debug.LogWarning("Rebuilding Audio Buddy database. This might take a bit...");

                RescanAudioBuddyObjects();
                DeletePartOfDatabase(ABObjectCollection);
                //ABDatabase.Clear();
                foreach (AudioClip clip in FindAllClips())
                {
                    AudioBuddySound absound = CreateInstance <AudioBuddySound>();
                    absound.File = clip;
                    //ABDatabase[absound.File.name] = absound;
                    ABObjectCollection.Add(absound);
                    AssetDatabase.CreateAsset(absound, $"{CollectionAddress}/{clip.name}.asset");
                    EditorUtility.SetDirty(absound);
                }
                Debug.Log("Creating Instances done. Saving assets...");
                AssetDatabase.SaveAssets();
                Debug.Log($"Done rebuilding Audio Buddy database into {CollectionAddress}");
                return;
            }
            Debug.LogError("Enter a valid path to build Audio Buddy database");
        }
示例#2
0
        /// <summary>
        /// Compares all AudioClip and AudioBuddySound assets in the project and creates AudioBuddySound assets for every AudioClip that is not part of the databse yet. Only works in editor.
        /// </summary>
        public void CreateMissingAudioBuddyObjects()
        {
            EnsureAssetDBPath();
            List <AudioBuddySound> onlySounds = new List <AudioBuddySound>();

            foreach (AudioBuddyObject sound in ABObjectCollection) //ABDatabase.Values)
            {
                if (sound.GetType() == typeof(AudioBuddySound))
                {
                    onlySounds.Add((AudioBuddySound)sound);
                }
            }
            int newObjectCounter = 0;

            foreach (AudioClip newClip in FindAllClips().Where(c => !onlySounds.Select(s => s.File).Contains(c)))
            {
                AudioBuddySound absound = CreateInstance <AudioBuddySound>();
                absound.File = newClip;
                //ABDatabase[absound.Name] = absound;
                ABObjectCollection.Add(absound);
                AssetDatabase.CreateAsset(absound, $"{CollectionAddress}/{newClip.name}.asset");
                EditorUtility.SetDirty(absound);
                newObjectCounter++;
            }
            DiscoverAudioBuddyObjects();
            Debug.Log($"Added {newObjectCounter} new Audio buddy Sounds to database at {CollectionAddress}");
        }
示例#3
0
 private void Update()
 {
     if (_playbackList.Count > 0) //While sounds should be played
     {
         _timeTillNextSound -= UseScaledTime ? Time.deltaTime : Time.unscaledDeltaTime;
         if (_timeTillNextSound <= 0) //Should the next sound be played?
         {
             _timeTillNextSound = 0;
             PlaySound(_playbackList[0].SoundEntry);
             if (_playbackList[0].SoundEntry.GetType() == typeof(AudioBuddySound) && _deleteNext)
             {
                 AudioBuddySound upcomingSound = (AudioBuddySound)_playbackList[0].SoundEntry;
                 OnPlayingNextSound?.Invoke(upcomingSound);
                 _playbackList.RemoveAt(0);
                 _timeTillNextSound += _playbackList.Count > 0 ? _playbackList[0].Delay : 0;
             }
             if (_playbackList.Count == 0)
             {
                 _timeTillNextSound = 0;
                 IsLooping          = false;
                 _busyPlayingList   = false;
             }
             _deleteNext = true;
         }
     }
     UpdateSourcePlayerVolume();
 }
示例#4
0
 private void CheckForReaddLoopingSound(AudioBuddySound lastSound)
 {
     if (lastSound.IsLoop)
     {
         IsLooping = true;
         _playbackList.Add(_playbackList[0]); //First entry is itself - so it clones
     }
 }
示例#5
0
 private void PlaySimpleSound(AudioBuddySound sound)
 {
     _timeTillNextSound += sound.Duration;
     SourcePlayer.clip   = sound.File;
     SourcePlayer.volume = sound.Volume * _externalVolumeMultipilier * _internalVolumeMultipilier;
     SourcePlayer.pitch  = sound.Pitch;
     SourcePlayer.Play();
 }
示例#6
0
        /// <summary>
        /// Allows for the manual creation of an AudioBuddySound asset based on an AudioClip. Only works in editor.
        /// </summary>
        /// <param name="clip"></param>
        /// <returns></returns>
        public AudioBuddySound CreateAudioBuddySoundFromClip(AudioClip clip)
        {
            AudioBuddySound absound = CreateInstance <AudioBuddySound>();

            absound.File = clip;
            ABObjectCollection.Add(absound);
            AssetDatabase.CreateAsset(absound, $"{CollectionAddress}/{clip.name}.asset");
            return(absound);
        }
 void OnPostprocessAudio(AudioClip clip) //Is called when assets are imported but also when they are reimported
 {
     abImportManager ??= AudioBuddy.Importer;
     if (abImportManager.CreateABOjectsOnClipImport && AssetDatabase.IsValidFolder(abImportManager.CollectionAddress))
     {
         //string a = abImportManager.CollectionAddress;
         string          clipName = ExtractAssetNameFromPath(assetPath);
         AudioBuddySound absound  = ScriptableObject.CreateInstance <AudioBuddySound>();
         AssetDatabase.CreateAsset(absound, $"{abImportManager.CollectionAddress}/{clipName}.asset");
         abImportManager.ABObjectCollection.Add(absound);
         absound.FilePath = assetPath;
         abImportManager.SoundsCreatedThroughImport.Add(absound, assetPath);
         Debug.Log($"Automatically created AudioBuddySound for {clipName} at {absound.FilePath}");
     }
 }
示例#8
0
 private void OnEnable()
 {
     soundObject            = (AudioBuddySound)target;
     soundObject.CustomName = false;
 }