NG_/Scripts/UI/环境监测/SlideShow.cs
2024-12-13 18:49:44 +08:00

93 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SlideShow : MonoBehaviour
{
public float x;
public float y;
public HttpController httpController;
// 是否向下移动
public bool down=true;
// 是否开始旋转
private bool isRotate = true;
//移动的value值
private float value;
//每个子物体的位置坐标(长度为子物体总量)
private Vector2[] vc;
//是否开始移动
bool Move;
void OnEnable()
{
/*GridLayoutGroup gridLayoutGroup = gameObject.GetComponent<GridLayoutGroup>();
x = gridLayoutGroup.cellSize.x/2f;
y = gridLayoutGroup.cellSize.y;*/
httpController = gameObject.GetComponent<HttpController>();
value = 0;
Move = true;
StartCoroutine(ExecuteEveryTwoSeconds());
}
public IEnumerator ExecuteEveryTwoSeconds()
{
yield return new WaitForSeconds(4f);
while (isRotate) // 无限循环
{
// 执行事件
if (value == 0)
{
vc=new Vector2[transform.childCount];
for (int i = 0; i < transform.childCount; i++)
{
vc[i] = transform.GetChild(i).localPosition;
}
Move = true;
StartCoroutine(MoveR());
}
// 等待2秒
yield return new WaitForSeconds(4f);
}
}
IEnumerator MoveR()
{
while (Move)
{
yield return new WaitForEndOfFrame();
for (int i = 0; i < transform.childCount; i++)
{
if (value > 1)
{
transform.GetChild(0).SetAsLastSibling();
value = 0;
Move = false;
if(httpController!=null)httpController.UpdateIndex();
break;
}
value += Time.deltaTime * 0.5f;
//new Vector2(vc[i].x + 1440, 0)在当前初始位置上向右移动1440
print("移动开始");
if (down)
{
transform.GetChild(i).localPosition = Vector2.Lerp(vc[i], new Vector2(x, vc[i].y + y), value);
}
else
{
// 向右移动
transform.GetChild(i).localPosition = Vector2.Lerp(vc[i], new Vector2(vc[i].x - x, y), value);
}
}
}
}
}