144 lines
3.6 KiB
C#
144 lines
3.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
|
|
public class Carousel : UIController
|
|
{
|
|
[SerializeField] Button[] Btn;
|
|
[SerializeField] Button PrototypeBtn;
|
|
[SerializeField] Transform ParentGame;
|
|
/// <summary>
|
|
/// 芞⑵華硊
|
|
/// </summary>
|
|
[SerializeField] List<string> url;
|
|
int MoveSum = 0;
|
|
[SerializeField] CarouselSmall CarouselSmall;
|
|
[SerializeField] Button Btn1;
|
|
[SerializeField] Button Btn2;
|
|
/// <summary>
|
|
/// 蟈諉華硊
|
|
/// </summary>
|
|
[SerializeField] List<string> links;
|
|
void Start()
|
|
{
|
|
Btn1.onClick.AddListener(() =>
|
|
{
|
|
if (MoveSum % Btn.Length == 0)
|
|
{
|
|
MoveSum = 0;
|
|
}
|
|
show(MoveSum);
|
|
MoveSum++;
|
|
Debug.Log(MoveSum);
|
|
});
|
|
Btn2.onClick.AddListener(() =>
|
|
{
|
|
if (MoveSum % Btn.Length == 0)
|
|
{
|
|
MoveSum = Btn.Length;
|
|
}
|
|
MoveSum--;
|
|
show(MoveSum);
|
|
Debug.Log(MoveSum);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 場宎趙
|
|
/// </summary>
|
|
/// <param name="urls">芞⑵華硊</param>
|
|
/// <param name="links">蟈諉華硊</param>
|
|
public void init(List<string> urls, List<string> links=null)
|
|
{
|
|
if (Btn != null)
|
|
{
|
|
//ラ諾item
|
|
for (int i = 0; i < Btn.Length; i++)
|
|
{
|
|
Destroy(Btn[i].gameObject);
|
|
}
|
|
Btn = null;
|
|
}
|
|
|
|
this.url = urls;
|
|
this.links = links;
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
//汜傖item
|
|
if (url.Count != 0)
|
|
{
|
|
Btn = new Button[url.Count];
|
|
for (int i = 0; i < url.Count; i++)
|
|
{
|
|
Btn[i] = Instantiate(PrototypeBtn, ParentGame);
|
|
Btn[i].name = i.ToString();
|
|
}
|
|
PrototypeBtn.gameObject.SetActive(false); //蔥腴batches
|
|
|
|
if (Btn.Length != 0)
|
|
{
|
|
foreach (var item in Btn)
|
|
{
|
|
item.gameObject.SetActive(true);
|
|
item.onClick.AddListener(() => Application.OpenURL(links[int.Parse(item.name)]));
|
|
UIManager.ins.LoadImageAsync(url[int.Parse(item.name)], item.image, false);
|
|
}
|
|
for (int i = 0; i < Btn.Length; i++)
|
|
{
|
|
if (i > 0)
|
|
{
|
|
Btn[i].transform.DOLocalMoveX(Btn[i].transform.GetComponent<RectTransform>().sizeDelta.x * i, 0.01f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//CarouselSmall.init(Btn.Length);
|
|
//CarouselSmall.show(MoveSum);
|
|
}
|
|
|
|
float time = 0;
|
|
private void Update()
|
|
{
|
|
time += Time.deltaTime;
|
|
if(time>=3)
|
|
{
|
|
time = 0;
|
|
show();
|
|
}
|
|
}
|
|
|
|
new void show()
|
|
{
|
|
if (Btn != null)
|
|
{
|
|
if (Btn.Length > 1)
|
|
{
|
|
if (MoveSum % Btn.Length != 0)
|
|
{
|
|
ParentGame.DOLocalMoveX(-MoveSum * 736, 0.25f);
|
|
CarouselSmall.show(MoveSum);
|
|
}
|
|
else
|
|
{
|
|
MoveSum = 0;
|
|
ParentGame.DOLocalMoveX(-MoveSum * 736, 0.25f);
|
|
CarouselSmall.show(MoveSum);
|
|
}
|
|
MoveSum++;
|
|
}
|
|
}
|
|
}
|
|
public void show(int sum)
|
|
{
|
|
if (Btn.Length > 1)
|
|
{
|
|
ParentGame.DOLocalMoveX(-sum * 736, 0.25f);
|
|
}
|
|
MoveSum = sum;
|
|
}
|
|
}
|