62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using TMPro;
|
|
|
|
public class CarouselSmal2 : UIController
|
|
{
|
|
[SerializeField] Button[] buttons;
|
|
[SerializeField] Button Btn;
|
|
[SerializeField] Carousel2 carousel;
|
|
[SerializeField] int index;
|
|
Color32 dark = new Color32(255,255,255,100);
|
|
Color32 bright = new Color32(255,255,255,255);
|
|
public void init(int sum)
|
|
{
|
|
buttons = new Button[sum];
|
|
for (int i = 0; i < sum; i++)
|
|
{
|
|
buttons[i] = Instantiate(Btn,transform);
|
|
buttons[i].gameObject.SetActive(true);
|
|
buttons[i].name = i.ToString();
|
|
buttons[i].GetComponentInChildren<TextMeshProUGUI>().text = (i + 1).ToString();
|
|
}
|
|
foreach (var item in buttons)
|
|
{
|
|
item.onClick.AddListener(() =>
|
|
{
|
|
index = int.Parse(item.name);
|
|
carousel.show(index);
|
|
for (int i = 0; i < buttons.Length; i++)
|
|
{
|
|
if (i != index)
|
|
{
|
|
buttons[i].image.color = dark;
|
|
}
|
|
else
|
|
{
|
|
buttons[i].image.color = bright;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
public void show(int index)
|
|
{
|
|
for (int i = 0; i < buttons.Length; i++)
|
|
{
|
|
if (i != index&& buttons[i].image)
|
|
{
|
|
buttons[i].image.color = dark;
|
|
}
|
|
else if(buttons[i].image)
|
|
{
|
|
buttons[i].image.color = bright;
|
|
}
|
|
}
|
|
}
|
|
}
|