2025-06-27 14:38:05 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 选关场景循环
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class LevelSelectLoop : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
#region 配置参数
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 地块间隔
|
|
|
|
|
/// </summary>
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float spacing = 12;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 速度
|
|
|
|
|
/// </summary>
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float speed = 3;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 起始位置
|
|
|
|
|
/// </summary>
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private float startPos = -80f;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 地块列表根节点
|
|
|
|
|
/// </summary>
|
|
|
|
|
[SerializeField]
|
|
|
|
|
private Transform tsPlotRoot;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当前地图节点
|
|
|
|
|
/// </summary>
|
|
|
|
|
private Transform curTsMap;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 地块列表
|
|
|
|
|
/// </summary>
|
2025-06-27 15:03:13 +08:00
|
|
|
private List<Transform> listPlot;
|
2025-06-27 14:38:05 +08:00
|
|
|
private float curPos = 0f;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 上一次地块数量
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int lastCount;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
curTsMap = GetComponent<Transform>();
|
2025-06-27 15:03:13 +08:00
|
|
|
listPlot = new List<Transform>();
|
2025-06-27 14:38:05 +08:00
|
|
|
for (int i = 0; i < tsPlotRoot.childCount; ++i)
|
|
|
|
|
{
|
|
|
|
|
listPlot.Add(tsPlotRoot.GetChild(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
curPos = startPos;
|
|
|
|
|
curTsMap.localPosition = new Vector3(curTsMap.localPosition.x, curTsMap.localPosition.y, curPos);
|
|
|
|
|
lastCount = (int)((startPos - curPos) / spacing) - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
curPos -= Time.deltaTime * speed;
|
|
|
|
|
int count = (int)((startPos - curPos) / spacing) - 1;
|
|
|
|
|
if (lastCount != count)
|
|
|
|
|
{
|
|
|
|
|
int index = count % listPlot.Count;
|
|
|
|
|
if (index >= 0 && listPlot.Count > index)
|
|
|
|
|
{
|
|
|
|
|
Transform tsPlot = listPlot[index];
|
|
|
|
|
tsPlot.localPosition = new Vector3((listPlot.Count + count) * spacing, tsPlot.localPosition.y, tsPlot.localPosition.z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lastCount = count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curTsMap.localPosition = new Vector3(curTsMap.localPosition.x, curTsMap.localPosition.y, curPos);
|
|
|
|
|
}
|
|
|
|
|
}
|