ict.shenzhi/Assets/Scripts/UI/MainScenesUI/OneImage.cs

73 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class OneImage : UIController
{
[SerializeField] Image Bg;
[SerializeField] Image im;
public string name;
List<(string, string, string, string)> nameinit;
List<(string, string, string, string)> nametest;
[SerializeField] oneimageSon oneimage;
[SerializeField] Transform trans;
[SerializeField] List<Button> btn = new List<Button>();
[SerializeField] TMP_InputField field;
[SerializeField] Button determineBtn;
// Start is called before the first frame update
void Start()
{
nametest = new List<(string, string, string, string)>
{
("asdasd", "asdasd", "gasfasd", "iukagjhsdg"),
("asdasd1", "asdasd1", "gasfasd1", "iukagjhsdg1"),
("asdasd12", "asdasd21", "gasfasd12", "iukagjhsdg12"),
("asdasd123", "asdasd213", "gasfasd123", "iukagjhsdg123")
};
init(nametest);
determineBtn.onClick.AddListener(() =>
{
if (!string.IsNullOrEmpty(field.text))
{
name = field.text;
base.hide(im, Bg);
}
else
{
field.placeholder.GetComponent<TextMeshProUGUI>().text = "Ãû³Æ²»ÄÜΪ¿Õ";
return;
}
});
}
public void init(List<(string, string, string, string)> item)
{
nameinit = new List<(string, string, string, string)> (item);
for (int i = 0; i < nameinit.Count; i++)
{
oneimageSon one1 = Instantiate(oneimage, trans);
one1.init(nameinit[i]);
one1.name = nameinit[i].Item1;
btn.Add(one1.GetComponent<Button>());
}
foreach (var item1 in btn)
{
item1.onClick.AddListener(() =>
{
name = item1.name;
field.text = name;
});
}
}
private void OnEnable()
{
base.show(im,Bg);
}
private void OnDisable()
{
base.hide(im,Bg);
}
}