private IEnumerator UniGifProcessorLoad(string url, Action<GifFrameData[]> OnSuccess, Action OnFail) { webRequestOp = DCL.Environment.i.platform.webRequest.Get(url: url, disposeOnCompleted: false); yield return webRequestOp; if (webRequestOp.isSucceded) { var bytes = webRequestOp.webRequest.downloadHandler.data; yield return UniGif.GetTextureListCoroutine(bytes, (frames, loopCount, width, height) => { if (frames != null) { OnSuccess?.Invoke(frames); } else { OnFail?.Invoke(); } }); } else { OnFail?.Invoke(); } webRequestOp.Dispose(); }
private IEnumerator UniGifProcessorLoad(string url, Action <GifFrameData[]> OnSuccess, Action OnFail) { webRequest = UnityWebRequest.Get(url); yield return(webRequest.SendWebRequest());; bool success = webRequest != null && webRequest.WebRequestSucceded(); if (success) { var bytes = webRequest.downloadHandler.data; yield return(UniGif.GetTextureListCoroutine(bytes, (frames, loopCount, width, height) => { if (frames != null) { OnSuccess?.Invoke(frames); } else { OnFail?.Invoke(); } })); } else { OnFail?.Invoke(); } webRequest.Dispose(); webRequest = null; }
/// <summary> /// Set GIF texture from url /// </summary> /// <param name="url">GIF image url (WEB or StreamingAssets path)</param> /// <param name="autoPlay">Auto play after decode</param> /// <returns>IEnumerator</returns> public IEnumerator SetGifFromUrlCoroutine(string url, bool autoPlay = true) { if (string.IsNullOrEmpty(url)) { UnityEngine.Debug.LogError("URL is nothing."); yield break; } m_loading = true; string path; if (url.StartsWith("http")) { // from WEB path = url; } else { // from StreamingAssets path = System.IO.Path.Combine("file:///" + Application.persistentDataPath, url); } // Load file using (WWW www = new WWW(path)) { yield return(www); if (string.IsNullOrEmpty(www.error) == false) { UnityEngine.Debug.LogError("File load error.\n" + www.error); } else { m_gifTexList.Clear(); // Get GIF textures if (m_useCoroutineGetTexture) { print("here!!!!~"); // use coroutine (avoid lock up but more slow) yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, www.bytes, (gtList, loop, w, h) => { m_gifTexList = gtList; FinishedGetTextureList(loop, w, h, autoPlay); }, m_filterMode, m_wrapMode, m_outputDebugLog))); } else { // dont use coroutine (there is a possibility of lock up) int loop, w, h; m_gifTexList = UniGif.GetTextureList(www.bytes, out loop, out w, out h, m_filterMode, m_wrapMode, m_outputDebugLog); FinishedGetTextureList(loop, w, h, autoPlay); } } } }
/// <summary> /// Set GIF texture from url /// </summary> /// <param name="url">GIF image url (WEB or StreamingAssets path)</param> /// <param name="autoPlay">Auto play after decode</param> /// <returns>IEnumerator</returns> public IEnumerator SetGifFromUrlCoroutine(string url, bool autoPlay = true) { if (string.IsNullOrEmpty(url)) { Debug.LogError("URL is nothing."); yield break; } loading = true; string path; if (url.StartsWith("http")) { // from WEB path = url; } else { // from StreamingAssets path = System.IO.Path.Combine("file:///" + Application.streamingAssetsPath, url); } // Load file using (WWW www = new WWW("http://q.qlogo.cn/qqapp/1104827980/6A620F446800E6A4C0970D9C7A78CDE5/100")) { yield return(www); if (string.IsNullOrEmpty(www.error) == false) { Debug.LogError("File load error.\n" + www.error); } else { gifTexList.Clear(); // Get GIF textures if (useCoroutineGetTexture) { // use coroutine (avoid lock up but more slow) yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, www.bytes, (gtList, loop, w, h) => { gifTexList = gtList; FinishedGetTextureList(loop, w, h, autoPlay); }, filterMode, wrapMode, outputDebugLog))); } else { // dont use coroutine (there is a possibility of lock up) int loop, w, h; gifTexList = UniGif.GetTextureList(www.bytes, out loop, out w, out h, filterMode, wrapMode, outputDebugLog); FinishedGetTextureList(loop, w, h, autoPlay); } } } }
private IEnumerator BeginInitRes() { TextAsset[] gifTextAssets = Resources.LoadAll <TextAsset>("Raw/Gif"); foreach (var gifTextAsset in gifTextAssets) { yield return(0); StartCoroutine(UniGif.GetTextureListCoroutine(this, gifTextAsset.bytes, gifTextAsset.GetInstanceID(), null, null, FilterMode.Trilinear, TextureWrapMode.Clamp, false)); } }
public IEnumerator Load(byte[] bytes, Action onFinish) { if (isLoaded) { Dispose(); } yield return(UniGif.GetTextureListCoroutine(bytes, OnGifLoaded, FilterMode.Bilinear, TextureWrapMode.Clamp)); onFinish?.Invoke(); }
public IEnumerator Load() { if (isLoaded) { Dispose(); } bool processedGIFInJS = false; #if !UNITY_EDITOR && UNITY_WEBGL yield return(DCL.GIFProcessingBridge.i.RequestGIFProcessor(url, (List <UniGif.GifTexture> newTextures) => // Override textures with JS processed ones { if (newTextures == null || newTextures.Count == 0) { return; } processedGIFInJS = true; OnGifLoaded(newTextures, 0, newTextures[0].m_texture2d.width, newTextures[0].m_texture2d.height); }, () => { processedGIFInJS = false; })); #endif if (!processedGIFInJS) { byte[] bytes = null; yield return(Utils.FetchAsset(url, UnityWebRequest.Get(url), (request) => { bytes = request.downloadHandler.data; })); if (bytes == null) { OnFailEvent?.Invoke(); yield break; } yield return(UniGif.GetTextureListCoroutine(bytes, OnGifLoaded)); } SetMaxTextureSize(maxSize); Play(); OnSuccessEvent?.Invoke(this, null); }
/// <summary> /// Set GIF texture from url /// </summary> /// <param name="url">GIF image url (WEB or StreamingAssets path)</param> /// <param name="autoPlay">Auto play after decode</param> /// <returns>IEnumerator</returns> public IEnumerator SetGifFromUrlCoroutine(string url, bool autoPlay = true) { if (string.IsNullOrEmpty(url)) { Debug.LogError("URL is nothing."); yield break; } if (nowState == State.Loading) { Debug.LogWarning("Already loading."); yield break; } nowState = State.Loading; string path; if (url.StartsWith("http")) { // from WEB path = url; } else { // from StreamingAssets path = Path.Combine("file:///" + Application.streamingAssetsPath, url); } // Load file using (WWW www = new WWW(path)) { yield return(www); if (string.IsNullOrEmpty(www.error) == false) { Debug.LogError("File load error.\n" + www.error); nowState = State.None; yield break; } Clear(); nowState = State.Loading; // Get GIF textures yield return(StartCoroutine(UniGif.GetTextureListCoroutine(www.bytes, (gifTexList, loopCount, width, height) => { if (gifTexList != null) { m_gifTextureList = gifTexList; this.loopCount = loopCount; this.width = width; this.height = height; nowState = State.Ready; m_imgAspectCtrl.FixAspectRatio(width, height); if (m_rotateOnLoading) { transform.localEulerAngles = Vector3.zero; } if (autoPlay) { Play(); } } else { Debug.LogError("Gif texture get error."); nowState = State.None; } }, m_filterMode, m_wrapMode, m_outputDebugLog))); } }
IEnumerator Start() { rootDirectory = Application.dataPath + "/../"; if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer) { useWebMInsteadOfMp4 = true; } if (Application.platform == RuntimePlatform.OSXPlayer) { // OSX の場合にはアプリが別のパスに隔離されてしまうので問い合わせが必要 var dir = PlayerPrefs.HasKey("RootDirectory") ? PlayerPrefs.GetString("RootDirectory") : ""; var paths = StandaloneFileBrowser.OpenFilePanel("audio.wav を選択してください", dir, "wav", false); if (paths.Length == 0) { Application.Quit(); yield break; } rootDirectory = Uri.UnescapeDataString(Path.GetDirectoryName(paths[0]).Replace("file:", "") + "/"); PlayerPrefs.SetString("RootDirectory", rootDirectory); } print("rootDir:" + rootDirectory); if (File.Exists(GetFilePath("background.png"))) { print(GetFilePath("background.png")); var imageWWW = new WWW("file://" + GetFilePath("background.png")); yield return(imageWWW); image.texture = imageWWW.texture; SetResolution(imageWWW.texture.width, imageWWW.texture.height); } else if (File.Exists(GetFilePath("background.jpg"))) { print(GetFilePath("background.jpg")); var imageWWW = new WWW("file://" + GetFilePath("background.jpg")); yield return(imageWWW); image.texture = imageWWW.texture; SetResolution(imageWWW.texture.width, imageWWW.texture.height); } else if (File.Exists(GetFilePath("background.gif"))) { print(GetFilePath("background.gif")); var imageWWW = new WWW("file://" + GetFilePath("background.gif")); yield return(imageWWW); yield return(StartCoroutine(UniGif.GetTextureListCoroutine(imageWWW.bytes, (gifTexList, loopCount, width, height) => { SetResolution(width, height); gifPlayer = GifPlayer.Create(image, gifTexList); }))); } else { SetResolution(720, 304); } print(GetFilePath("audio.wav")); var audiosource = gameObject.AddComponent <AudioSource>(); var audioWWW = new WWW("file://" + GetFilePath("audio.wav")); yield return(audioWWW); audiosource.clip = audioWWW.GetAudioClip(false); var recorder = mp4Recorder; if (useWebMInsteadOfMp4) { recorder = webMRecorder; } recorder.outputDir = new DataPath(GetFilePath("Movie")); recorder.BeginRecording(); if (gifPlayer != null) { gifPlayer.PlaySyncWith(audiosource); } audiosource.Play(); print(LastPath); yield return(new WaitWhile(() => audiosource.isPlaying)); recorder.EndRecording(); yield return(new WaitForSeconds(2f)); if (useWebMInsteadOfMp4) { var webmPath = "\"" + LastPath + ".webm" + "\""; var mp4Path = "\"" + LastPath + ".mp4" + "\""; var exeExtension = Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer ? ".exe" : ""; var process = Process.Start(GetFilePath("ffmpeg/ffmpeg" + exeExtension), "-i " + webmPath + " " + mp4Path); process.WaitForExit(); File.Delete(LastPath + ".webm"); } Application.Quit(); }
/// <summary> /// Set GIF texture from url /// </summary> /// <param name="url">GIF image url (WEB or StreamingAssets path)</param> /// <param name="autoPlay">Auto play after decode</param> /// <returns>IEnumerator</returns> public IEnumerator SetGifFromUrlCoroutine(string url, bool autoPlay = true) { if (gifTextAsset != null) { if (gifTexList.Count != 0 && rawImage != null) { rawImage.texture = gifTexList[0].texture2d; } yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, gifTextAsset.bytes, gifTextAsset.GetInstanceID(), gifTexList, (gtList, loop, w, h) => { gifTexList = gtList; FinishedGetTextureList(loop, w, h, autoPlay); }, filterMode, wrapMode, outputDebugLog))); yield break; } if (string.IsNullOrEmpty(url)) { Debug.LogError("URL is nothing."); yield break; } loading = true; string path; if (url.StartsWith("http")) { // from WEB path = url; } else { // from StreamingAssets path = System.IO.Path.Combine("file:///" + Application.streamingAssetsPath, url); } // Load file using (WWW www = new WWW(path)) { yield return(www); if (string.IsNullOrEmpty(www.error) == false) { Debug.LogError("File load error.\n" + www.error); } else { gifTexList.Clear(); // Get GIF textures if (useCoroutineGetTexture) { // use coroutine (avoid lock up but more slow) yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, www.bytes, (gtList, loop, w, h) => { gifTexList = gtList; FinishedGetTextureList(loop, w, h, autoPlay); }, filterMode, wrapMode, outputDebugLog))); } else { // dont use coroutine (there is a possibility of lock up) int loop, w, h; gifTexList = UniGif.GetTextureList(www.bytes, out loop, out w, out h, filterMode, wrapMode, outputDebugLog); FinishedGetTextureList(loop, w, h, autoPlay); } } } }
/// <summary> /// Set GIF texture from url /// </summary> /// <param name="url">GIF image url (WEB or StreamingAssets path)</param> /// <param name="autoPlay">Auto play after decode</param> /// <returns>IEnumerator</returns> public IEnumerator SetGifFromUrlCoroutine(string url, bool autoPlay = true) { if (string.IsNullOrEmpty(url)) { Debug.LogError("URL is nothing."); yield break; } loading = true; string path; if (url.StartsWith("http")) { // from WEB path = url; } else { // from StreamingAssets path = #if true #if UNITY_ANDROID && !UNITY_EDITOR System.IO.Path.Combine(Application.streamingAssetsPath, url); //"jar:file://" + Application.dataPath + "!/assets/" + flodername + "/"; #elif UNITY_IPHONE && !UNITY_EDITOR System.IO.Path.Combine("file://" + Application.streamingAssetsPath, url); #elif UNITY_STANDALONE_WIN || UNITY_EDITOR System.IO.Path.Combine("file:///" + Application.streamingAssetsPath, url); #else string.Empty; #endif #endif } // Load file using (WWW www = new WWW(path)) { yield return(www); if (string.IsNullOrEmpty(www.error) == false) { Debug.LogError("File load error.\n" + www.error); } else { gifTexList.Clear(); // Get GIF textures if (useCoroutineGetTexture) { // use coroutine (avoid lock up but more slow) yield return(StartCoroutine(UniGif.GetTextureListCoroutine(this, www.bytes, (gtList, loop, w, h) => { gifTexList = gtList; FinishedGetTextureList(loop, w, h, autoPlay); }, filterMode, wrapMode, outputDebugLog))); } else { // dont use coroutine (there is a possibility of lock up) int loop, w, h; gifTexList = UniGif.GetTextureList(www.bytes, out loop, out w, out h, filterMode, wrapMode, outputDebugLog); FinishedGetTextureList(loop, w, h, autoPlay); } } } }