/// <summary>
        /// Load the music from path in runtime.
        /// </summary>
        /// <param name="ac"> A container for audio data. </param>
        /// <param name="fullFilePath"> Filpath to the target audio file. </param>
        /// <param name="type"> Audio clip type. </param>
        /// <param name="callback"> Callback after the audio is loaded. </param>
        /// <returns> Coroutine status. </returns>
        public static IEnumerator LoadAudio(
            AudioClip ac,
            string fullFilePath,
            AudioType type       = AudioType.OGGVORBIS,
            AudioLoaded callback = null)
        {
            string formatFullFilePath = string.Format("file://{0}", fullFilePath);

#if UNITY_2018_1_OR_NEWER
            UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(formatFullFilePath, type);
            yield return(request.SendWebRequest());

            ac = DownloadHandlerAudioClip.GetContent(request);
#else
            WWW request = new WWW(formatFullFilePath);
            yield return(request);

            ac = request.GetAudioClip(false, false);
#endif

            if (callback != null)
            {
                callback.Invoke(ac);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load the music from path in runtime.
        /// </summary>
        /// <param name="ac"> A container for audio data. </param>
        /// <param name="fullFilePath"> Filpath to the target audio file. </param>
        /// <param name="callback"> Callback after the audio is loaded. </param>
        /// <returns> Coroutine status. </returns>
        public static IEnumerator LoadAudio(
            AudioClip ac,
            string fullFilePath,
            AudioLoaded callback = null)
        {
            string formatFullFilePath = string.Format("file://{0}", fullFilePath);

            WWW request = new WWW(formatFullFilePath);

            yield return(request);

            ac = request.GetAudioClip(false, false);

            if (callback != null)
            {
                callback.Invoke(ac);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Load the audio from path/url in runtime.
        /// </summary>
        /// <param name="url"> Url to the target audio file. </param>
        /// <param name="type"> Type of the audio clip. </param>
        /// <param name="callback"> Callback after the audio is loaded. </param>
        /// <returns> Coroutine status. </returns>
        public static IEnumerator LoadAudio(
            string url,
            AudioType type       = AudioType.OGGVORBIS,
            AudioLoaded callback = null)
        {
#if UNITY_2018_1_OR_NEWER
            UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(url, type);
            yield return(request.SendWebRequest());

            AudioClip ac = DownloadHandlerAudioClip.GetContent(request);
#else
            WWW request = new WWW(url);
            yield return(request);

            AudioClip ac = request.GetAudioClip(false, false);
#endif

            if (callback != null)
            {
                callback.Invoke(ac);
            }
        }