116 lines
4.2 KiB
C#
116 lines
4.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using System;
|
|
|
|
public class stepPanel : UIController
|
|
{
|
|
public List<SourceData> datas;
|
|
//public Dictionary<string, string> dataTest = new Dictionary<string, string>();
|
|
[SerializeField] Button btn;
|
|
[SerializeField] List<Button> BtnList = new List<Button>();
|
|
[SerializeField] Transform trans;
|
|
[SerializeField] StepSecondary stepSecondary;
|
|
[SerializeField] StepSecondary stepSecondary2;
|
|
[SerializeField] Transform tran;
|
|
[SerializeField] bool isok = false;
|
|
[SerializeField] Dictionary<int, Button> buttons = new Dictionary<int, Button>();
|
|
int score;
|
|
[SerializeField] int sum;
|
|
[SerializeField] TextMeshProUGUI textMeshPro;
|
|
[SerializeField] List<string> SpritePath;
|
|
[SerializeField] bool completion = false;//是否需要补全图片加载路径
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
try
|
|
{
|
|
init();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.Log(ex.Message);
|
|
throw;
|
|
}
|
|
}
|
|
void init()
|
|
{
|
|
textMeshPro.text = "分数:" + UIManager.ins.TempScore.ToString();
|
|
for (int i = 0; i < datas.Count; i++)
|
|
{
|
|
BtnList.Add(Instantiate(btn, trans));
|
|
}
|
|
for (int i = 0; i < BtnList.Count; i++)
|
|
{
|
|
BtnList[i].GetComponentInChildren<TextMeshProUGUI>().text = datas[i].StepName;
|
|
BtnList[i].name = i.ToString();
|
|
}
|
|
foreach (var item in BtnList)
|
|
{
|
|
item.onClick.AddListener(() =>
|
|
{
|
|
if (stepSecondary2 == null)
|
|
{
|
|
stepSecondary2 = Instantiate(stepSecondary, tran);
|
|
if (SpritePath.Count != 0)
|
|
{
|
|
stepSecondary2.init(datas[int.Parse(item.name)].StepStr, SpritePath[int.Parse(item.name)], completion);
|
|
}
|
|
else
|
|
{
|
|
stepSecondary2.init(datas[int.Parse(item.name)].StepStr, "https://img-blog.csdnimg.cn/20201110182621125.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzUxMTg3MQ==,size_16,color_FFFFFF,t_70#pic_center", false);
|
|
}
|
|
stepSecondary2.id = int.Parse(item.name);
|
|
}
|
|
else
|
|
{
|
|
stepSecondary2.gameObject.SetActive(true);
|
|
if (SpritePath.Count != 0)
|
|
{
|
|
stepSecondary2.init(datas[int.Parse(item.name)].StepStr, SpritePath[int.Parse(item.name)], completion);
|
|
}
|
|
else
|
|
{
|
|
stepSecondary2.init(datas[int.Parse(item.name)].StepStr, "https://img-blog.csdnimg.cn/20201110182621125.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzUxMTg3MQ==,size_16,color_FFFFFF,t_70#pic_center", false);
|
|
}
|
|
stepSecondary2.id = int.Parse(item.name);
|
|
}
|
|
});
|
|
}
|
|
sum = BtnList.Count;
|
|
score = UIManager.ins.score / sum;
|
|
}
|
|
private void Update()
|
|
{
|
|
if (stepSecondary2)
|
|
{
|
|
isok = stepSecondary2.isok;
|
|
if (isok)
|
|
{
|
|
isok = false;
|
|
stepSecondary2.show();
|
|
if (!buttons.ContainsKey(stepSecondary2.id))
|
|
{
|
|
buttons.Add(stepSecondary2.id, BtnList[stepSecondary2.id]);
|
|
UIManager.ins.TempScore += score;
|
|
}
|
|
Debug.Log(buttons.Count);
|
|
stepSecondary2.gameObject.SetActive(false);
|
|
if (UIManager.ins.TempScore.Equals(UIManager.ins.score) && buttons.Count.Equals(BtnList.Count))
|
|
{
|
|
UIManager.ins.end();
|
|
}
|
|
textMeshPro.text = "分数:" + UIManager.ins.TempScore.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
public struct SourceData
|
|
{
|
|
public string StepName;
|
|
public string StepStr;
|
|
}
|