123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using RenderHeads.Media.AVProVideo;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class InfoWindow : MonoBehaviour
- {
- public Text titlestr;
- public Text infoStr;
- public Text infoStr2;
- public RawImage img;
- public RawImage img2;
- public GameObject mp4;
- public MediaPlayer mp;
- public void init (string info,string url,string info2,int index,string title,string application)
- {
- StopAllCoroutines();
- idx=0;
- mp.Stop();
- titlestr.text = TabListManager.Instance.GetTextByKey(title);
- infoStr.text = TabListManager.Instance.GetTextByKey(application);
- infoStr2.text = TabListManager.Instance.GetTextByKey(info)+"\n\n\n"+TabListManager.Instance.GetTextByKey(info2);
- if(url.Contains("mp4"))
- {
- mp4.SetActive(true);
- img2.gameObject.SetActive(false);
- mp.OpenMedia(MediaPathType.RelativeToStreamingAssetsFolder,url,true);
- }
- else
- {
- mp4.SetActive(false);
- img2.gameObject.SetActive(true);
- }
-
- filePath = Application.streamingAssetsPath+"/DeMa/png/"+index;
- img.gameObject.SetActive(true);
- Debug.Log("文件路径==》"+filePath);
- #if UNITY_EDITOR
- string fileListPath = Path.Combine(Application.streamingAssetsPath, "DeMa/png/"+index);
-
- files= Directory.GetFiles(fileListPath, "*.png");
- if(files.Length<=0)
- {
- img.gameObject.SetActive(false);
- }
- else
- {
- StartCoroutine(LoadImages());
- }
- Debug.Log("文件路径llllll==》"+files.Length);
- #else
- StartCoroutine(loadImg());
- #endif
- }
- string filePath ;
- string[] files ;
- int idx=0;
- private void OnDisable() {
-
-
- }
- Texture2D texture ;
- IEnumerator loadImg()
- {
-
- string f = filePath+"/"+idx+".png";
- Debug.Log(" to load image: " + f);
-
- using (UnityWebRequest request = UnityWebRequestTexture.GetTexture(f))
- {
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
- {
- if(idx==0)
- {
- img.gameObject.SetActive(false);
- }
- else
- {
- idx=0;
- StartCoroutine(loadImg());
- }
- Debug.LogError("Failed to load image: " + request.error);
- }
- else
- {
- img.gameObject.SetActive(true);
- if(texture!=null)
- {
- Destroy(texture);
- }
-
- texture = DownloadHandlerTexture.GetContent(request);
-
- img.texture = texture;
-
- yield return new WaitForSeconds(3.0f);
- idx++;
- StartCoroutine(loadImg());
- }
- }
- }
- IEnumerator LoadImages()
- {
-
- string filePath = files[idx];
- if(texture!=null)
- {
- Destroy(texture);
- }
-
- byte[] fileData = File.ReadAllBytes(filePath);
-
- texture = new Texture2D(2, 2);
- texture.LoadImage(fileData);
-
- img.texture = texture;
-
- yield return new WaitForSeconds(3.0f);
- idx++;
- if(idx>=files.Length)
- {
- idx=0;
- }
- StartCoroutine(LoadImages());
- }
- }
|