using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using UnityEngine.Networking; public class PhotoTransition : MonoBehaviour { public List imgPathList = null; [SerializeField] List _imgList = new List(); private Panorama180View.Panorama180View _panorama180View = null; private int _state = 0; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } IEnumerator BlendImage(Texture2D srcImg, Texture2D destImg) { _panorama180View.SetSrcTexture(srcImg); _panorama180View.SetDestTexture(destImg); _panorama180View.SetTransitionInterval(2.0f); _panorama180View.SetStateTransition(Panorama180View.Panorama180View.StateTransitionType.Blend); yield return new WaitForSeconds(2); } public IEnumerator LoadNextImage() { if (_state < imgPathList.Count - 1) { yield return StartCoroutine(BlendImage(_imgList[_state], _imgList[_state + 1])); _state++; } if (_imgList.Count < imgPathList.Count) { yield return StartCoroutine(ImageLoader(imgPathList[_state + 1])); } } public bool IsSlideshowFinished() { if (_state == imgPathList.Count-1) return true; return false; } public void Reset() { _imgList.Clear(); _state = 0; } public IEnumerator SetUp() { // Load first two images for (int i = 0; i < 2; i++) { yield return StartCoroutine(ImageLoader(imgPathList[i])); } _panorama180View = this.GetComponent(); _panorama180View.SetSrcTexture(_imgList[0]); _panorama180View.SetTransitionInterval(2.0f); _panorama180View.SetStateTransition(Panorama180View.Panorama180View.StateTransitionType.FadeIn); } IEnumerator ImageLoader(string path) { string imgPath = Path.Combine(Application.streamingAssetsPath, path); // imgPath = "file://" + imgPath; // For testing in editor using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(imgPath)) { yield return uwr.SendWebRequest(); if (uwr.result != UnityWebRequest.Result.Success) { Debug.Log(uwr.error); } else { Texture2D tex = DownloadHandlerTexture.GetContent(uwr); _imgList.Add(tex); } } } }