Ejemplo n.º 1
0
        public IEnumerator RequestImage(DownloadMediaEventArgs media)
        {
            Debug.Log(string.Format("Requesting Image {0}", media.FileName));

            if (media.FileName.Length <= 0 || media.FileName == null)
            {
                yield break;
            }
            var www =
                UnityWebRequestTexture.GetTexture(
                    ServerURL.DownloadMediaUrl(media.FileName));

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                yield break;
            }

            var texture =
                ((DownloadHandlerTexture)www.downloadHandler).texture;

            var textureArgs = new DownloadTextureEventArgs
            {
                DownloadGuid = media.DownloadGuid,
                FileName     = media.FileName,
                MediaType    = media.MediaType,
                ImageTexture = texture
            };

            Debug.Log("Image Download Successful.");

            EventManager.OnTextureDownloaded(textureArgs);
        }
Ejemplo n.º 2
0
        public IEnumerator RequestAudio(DownloadMediaEventArgs media)
        {
            Debug.Log(string.Format("Requesting Audio {0}", media.FileName));

            if (media.FileName.Length <= 0 || media.FileName == null)
            {
                yield break;
            }
            var www = UnityWebRequestMultimedia.GetAudioClip(
                ServerURL.DownloadMediaUrl(media.FileName),
                AudioType.OGGVORBIS);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                yield break;
            }


            var audioClip = ((DownloadHandlerAudioClip)www.downloadHandler)
                            .audioClip;


            var audioArgs = new DownloadAudioClipEventArgs {
                DownloadGuid = media.DownloadGuid,
                FileName     = media.FileName,
                MediaType    = media.MediaType,
                Clip         = audioClip
            };

            Debug.Log("Audio Download Successful.");

            EventManager.OnAudioClipDownloaded(audioArgs);
        }