NG_/Scripts/UI/待定/Slideshow.cs

90 lines
2.5 KiB
C#
Raw Normal View History

2024-12-13 18:49:44 +08:00
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using TMPro;
public class Slideshow : MonoBehaviour
{
//开始消失的位置,重新出现的位置(即左右两端临界点)
public Vector2 startPos, endPos;
// 移动物体的x点
public float X;
// 移动物体的每次增量
public float Y;
//移动的value值
private float value;
//每个子物体的位置坐标(长度为子物体总量)
Vector2[] vc = new Vector2[4];
//是否开始移动
bool Move;
// 是否开始旋转
public bool isRotate = false;
void Start()
{
StartCoroutine(ExecuteEveryTwoSeconds());
}
public IEnumerator ExecuteEveryTwoSeconds()
{
while (isRotate) // 无限循环
{
// 执行事件
if (value == 0)
{
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)
{
print("MoveR");
yield return new WaitForEndOfFrame();
for (int i = 0; i < transform.childCount; i++)
{
if (value > 1)
{
if (transform.GetChild(transform.childCount-1).localPosition.y >= startPos.y)
{
//回到最左边
/*transform.GetChild(0).localPosition = new Vector2(transform.GetChild(3).localPosition.x,endPos.y);*/
//把它变成子物体中的第一个
// transform.GetChild(1).SetAsFirstSibling();
transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>().text = "1";
transform.GetChild(0).SetAsLastSibling();
value = 0;
}
Move = false;
break;
}
value += Time.deltaTime * 0.5f;
//new Vector2(vc[i].x + 1440, 0)在当前初始位置上向右移动1440
transform.GetChild(i).localPosition = Vector2.Lerp(vc[i], new Vector2(X, vc[i].y + Y), value);
}
}
}
}