Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- public class LoadFiles : MonoBehaviour {
- // Use this for initialization
- void Start () {
- Debug.Log ((RestoreSoundFiles (SOUND_PATH)).Length);
- }
- /// <summary>
- /// final soundpath of the assetsfolder
- /// </summary>
- public readonly string SOUND_PATH = "/_sounds";
- /// <summary>
- /// The file extension.
- /// </summary>
- private readonly string fileExtension = "*.mp3";
- /// <summary>
- /// Restores the sound files from the given filePath
- /// </summary>
- /// <returns>The sound files.</returns>
- /// <param name="filePath">File path.</param>
- private AudioClip[] RestoreSoundFiles(string filePath)
- {
- //Declare the direction of the passed filepath
- DirectoryInfo dir = new DirectoryInfo(Assets.ASSETS_FOLDER + filePath);
- //Get all files from folder - files will be filtered by the filExtension
- FileInfo[] info = dir.GetFiles(fileExtension);
- //Declare a array of audioclips with the given length of the info array
- AudioClip[] soundClips = new AudioClip[info.Length];
- for (int i = 0; i < soundClips.Length; i++)
- soundClips[i] = (AudioClip)Resources.Load(info[i].FullName, typeof(AudioClip));
- return soundClips;
- }
- }
- ///utilities
- using UnityEngine;
- using System.Collections;
- using System.IO;
- public class Assets {
- public static readonly string ASSETS_FOLDER = Application.dataPath;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement