131 lines
3.7 KiB
C#
131 lines
3.7 KiB
C#
using DG.Tweening;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class Carousel2 : UIController
|
||
{
|
||
[SerializeField] Button[] Btn;
|
||
[SerializeField] Button PrototypeBtn;
|
||
[SerializeField] Transform ParentGame;
|
||
public List<string> url;
|
||
int MoveSum = 0;
|
||
[SerializeField] CarouselSmal2 CarouselSmall;
|
||
bool isok = true;
|
||
public List<string> tips = new List<string>();
|
||
[SerializeField] TextMeshProUGUI text;
|
||
[SerializeField] bool isStart = false;
|
||
[SerializeField] GameObject g1;
|
||
[SerializeField] Toggle tog;
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
try
|
||
{
|
||
init();
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
Debug.LogError(ex.Message);
|
||
throw;
|
||
}
|
||
}
|
||
void init()
|
||
{
|
||
tog.onValueChanged.AddListener((x) => isStart = x);
|
||
isStart = PlayerPrefs.GetInt("isStart") > 0 ? true : false;
|
||
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();
|
||
}
|
||
}
|
||
if (Btn.Length != 0)
|
||
{
|
||
foreach (var item in Btn)
|
||
{
|
||
item.gameObject.SetActive(true);
|
||
//item.onClick.AddListener(() => Application.OpenURL(url[int.Parse(item.name)]));
|
||
item.image.GetComponent<RectTransform>().sizeDelta = new Vector2(1008, 450);
|
||
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);
|
||
StartIE();
|
||
text.text = tips[MoveSum];
|
||
if (!isStart)
|
||
{
|
||
g1.gameObject.SetActive(true);
|
||
}
|
||
else
|
||
{
|
||
g1.gameObject.SetActive(false);
|
||
}
|
||
}
|
||
async void StartIE()
|
||
{
|
||
while (isok)
|
||
{
|
||
await Task.Delay(5000);
|
||
try
|
||
{
|
||
show();
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
#region ˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>Ϊ<EFBFBD>ű<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>while<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
Debug.Log("һ<><D2BB>С<EFBFBD><D0A1><EFBFBD><EFBFBD><F3A3ACB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + ex.Message);
|
||
#endregion
|
||
}
|
||
}
|
||
}
|
||
new void show()
|
||
{
|
||
if (Btn.Length > 1)
|
||
{
|
||
if (MoveSum % Btn.Length != 0)
|
||
{
|
||
ParentGame?.DOLocalMoveX(-MoveSum * Btn[MoveSum].GetComponent<RectTransform>().sizeDelta.x, 0.25f);
|
||
text.text = tips[MoveSum];
|
||
CarouselSmall?.show(MoveSum);
|
||
}
|
||
else
|
||
{
|
||
MoveSum = 0;
|
||
ParentGame?.DOLocalMoveX(-MoveSum * Btn[MoveSum].GetComponent<RectTransform>().sizeDelta.x, 0.25f);
|
||
text.text = tips[MoveSum];
|
||
CarouselSmall?.show(MoveSum);
|
||
}
|
||
MoveSum++;
|
||
}
|
||
|
||
}
|
||
public void show(int sum)
|
||
{
|
||
if (Btn.Length > 1)
|
||
{
|
||
ParentGame?.DOLocalMoveX(-sum * Btn[sum].GetComponent<RectTransform>().sizeDelta.x, 0.25f);
|
||
}
|
||
MoveSum = sum;
|
||
text.text = tips[MoveSum];
|
||
CarouselSmall?.show(MoveSum);
|
||
}
|
||
private void OnDestroy()
|
||
{
|
||
isok = false;
|
||
}
|
||
}
|