64 lines
1.4 KiB
C#
64 lines
1.4 KiB
C#
|
using DG.Tweening;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Runtime.CompilerServices;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class ScrollImage : MonoBehaviour
|
|||
|
{
|
|||
|
[SerializeField]
|
|||
|
private float m_PerImageSize;
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private float m_PerImageSpace;
|
|||
|
|
|||
|
[SerializeField]
|
|||
|
private int m_ImageCount;
|
|||
|
|
|||
|
private int nowImageIndex = 0;
|
|||
|
|
|||
|
private float jumpTime = 3;
|
|||
|
private float realTime = 3;
|
|||
|
|
|||
|
private RectTransform m_RectTrans;
|
|||
|
|
|||
|
private float m_TargetPosX = 0;
|
|||
|
// Start is called before the first frame update
|
|||
|
void Start()
|
|||
|
{
|
|||
|
realTime = Time.time;
|
|||
|
m_RectTrans = GetComponent<RectTransform>();
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
float a = Time.time - realTime;
|
|||
|
if(a >= jumpTime)
|
|||
|
{
|
|||
|
realTime = Time.time;
|
|||
|
//<2F>л<EFBFBD>
|
|||
|
nowImageIndex++;
|
|||
|
if(nowImageIndex >= m_ImageCount)
|
|||
|
{
|
|||
|
nowImageIndex = 0;
|
|||
|
}
|
|||
|
JumpToIndex();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>½<EFBFBD>
|
|||
|
/// </summary>
|
|||
|
private void JumpToIndex()
|
|||
|
{
|
|||
|
float posY = m_RectTrans.anchoredPosition.x;//<2F><>ǰ<EFBFBD>ߴ<EFBFBD>
|
|||
|
m_TargetPosX = posY - m_PerImageSize - m_PerImageSpace;
|
|||
|
if(m_TargetPosX < -(m_PerImageSize * m_ImageCount))
|
|||
|
{
|
|||
|
m_TargetPosX = 0;
|
|||
|
}
|
|||
|
m_RectTrans.DOAnchorPosX(m_TargetPosX, 0.6f);
|
|||
|
}
|
|||
|
}
|