2024-04-10 09:44:23 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System.IO;
|
|
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
|
|
public class PhotoTransition : MonoBehaviour
|
|
|
|
{
|
2024-05-13 11:45:47 +02:00
|
|
|
public List<string> imgPathList = new List<string>();
|
2024-04-10 09:44:23 +02:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
List<Texture2D> _imgList = new List<Texture2D>();
|
|
|
|
|
|
|
|
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.Panorama180View>();
|
|
|
|
_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);
|
2024-05-06 16:53:42 +02:00
|
|
|
imgPath = "file://" + imgPath; // For testing in editor
|
2024-04-10 09:44:23 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|