2023-12-20 15:56:37 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2023-12-12 10:29:10 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
namespace Script.UI
|
|
|
|
|
{
|
|
|
|
|
public class CulturePanel : PanelBase
|
|
|
|
|
{
|
|
|
|
|
public GameObject item;
|
|
|
|
|
public Button btn_Close;
|
2023-12-20 15:56:37 +08:00
|
|
|
|
public Button btn_Stop;
|
|
|
|
|
|
|
|
|
|
class CulturePanelData
|
|
|
|
|
{
|
|
|
|
|
private GameObject go;
|
|
|
|
|
private Text txt_ID;
|
|
|
|
|
private Text txt_Culture;
|
|
|
|
|
|
|
|
|
|
public CulturePanelData(GameObject go, string idStr, string cultureNameStr = "")
|
|
|
|
|
{
|
|
|
|
|
txt_ID = go.transform.GetChild(0).GetComponent<Text>();
|
|
|
|
|
txt_Culture = go.transform.GetChild(1).GetComponent<Text>();
|
|
|
|
|
txt_ID.text = idStr;
|
|
|
|
|
txt_Culture.text = cultureNameStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetCultureName(string cultureName)
|
|
|
|
|
{
|
|
|
|
|
this.txt_Culture.text = cultureName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Dictionary<int, CulturePanelData> cultures = new Dictionary<int, CulturePanelData>();
|
|
|
|
|
private bool isRolling;
|
2023-12-12 10:29:10 +08:00
|
|
|
|
|
|
|
|
|
public override void Init()
|
|
|
|
|
{
|
|
|
|
|
base.Init();
|
|
|
|
|
btn_Close.onClick.AddListener(ClickClose);
|
2023-12-20 15:56:37 +08:00
|
|
|
|
btn_Stop.onClick.AddListener(ClickStop);
|
|
|
|
|
|
|
|
|
|
btn_Close.gameObject.SetActive(false);
|
|
|
|
|
btn_Stop.gameObject.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClickStop()
|
|
|
|
|
{
|
|
|
|
|
btn_Close.gameObject.SetActive(true);
|
|
|
|
|
btn_Stop.gameObject.SetActive(false);
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
isRolling = false;
|
2023-12-12 10:29:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Dispose()
|
|
|
|
|
{
|
|
|
|
|
base.Dispose();
|
|
|
|
|
btn_Close.onClick.RemoveListener(ClickClose);
|
2023-12-20 15:56:37 +08:00
|
|
|
|
btn_Stop.onClick.RemoveListener(ClickStop);
|
2023-12-12 10:29:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
InitItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClickClose()
|
|
|
|
|
{
|
2023-12-20 15:56:37 +08:00
|
|
|
|
var openPanel = UIManager.Instance.GetPanel<HomePanel>(PanelType.Home);
|
|
|
|
|
openPanel.SetCultureFinish();
|
2023-12-12 10:29:10 +08:00
|
|
|
|
UIManager.Instance.OpenPanel(PanelType.Home);
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InitItem()
|
|
|
|
|
{
|
|
|
|
|
List<SummaryInfo> cache = new List<SummaryInfo>(GlobalManager.Instance.list);
|
|
|
|
|
|
|
|
|
|
foreach (var summaryInfo in cache)
|
|
|
|
|
{
|
2023-12-20 15:56:37 +08:00
|
|
|
|
var cultrueDataInfo = ExcelManager.Instance.GetCultureRandomInfo;
|
2023-12-12 10:29:10 +08:00
|
|
|
|
summaryInfo.culture = cultrueDataInfo.cultureName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 排个序
|
|
|
|
|
var list = cache.OrderBy(t => t.id).ToList();
|
|
|
|
|
|
2023-12-20 15:56:37 +08:00
|
|
|
|
foreach (var summaryInfo in list)
|
|
|
|
|
{
|
|
|
|
|
item.SetActive(false);
|
|
|
|
|
GenItem(summaryInfo.id.ToString(), summaryInfo.team);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isRolling = true;
|
|
|
|
|
StartCoroutine(RandomRoll());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GenItem(string id, string culture)
|
|
|
|
|
{
|
|
|
|
|
var go = GameObject.Instantiate(item, item.transform.parent);
|
|
|
|
|
go.name = id;
|
|
|
|
|
go.SetActive(true);
|
|
|
|
|
cultures.Add(int.Parse(id), new CulturePanelData(go, id, culture));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator RandomRoll()
|
|
|
|
|
{
|
|
|
|
|
while (isRolling)
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(0.02f);
|
|
|
|
|
var info = ExcelManager.Instance.GetCultureRandomInfo;
|
|
|
|
|
foreach (var culturePanelData in cultures.Values)
|
|
|
|
|
{
|
|
|
|
|
culturePanelData.SetCultureName(info.cultureName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShowResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ShowResult()
|
|
|
|
|
{
|
|
|
|
|
List<SummaryInfo> cache = new List<SummaryInfo>(GlobalManager.Instance.list);
|
2023-12-12 10:29:10 +08:00
|
|
|
|
|
|
|
|
|
foreach (var summaryInfo in cache)
|
2023-12-20 15:56:37 +08:00
|
|
|
|
{
|
|
|
|
|
var teamDataDataInfo = ExcelManager.Instance.GetTeamRandomInfo;
|
|
|
|
|
summaryInfo.team = teamDataDataInfo.teamName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 排个序
|
|
|
|
|
var list = cache.OrderBy(t => t.id).ToList();
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
foreach (var summaryInfo in list)
|
2023-12-12 10:29:10 +08:00
|
|
|
|
{
|
|
|
|
|
item.SetActive(false);
|
2023-12-20 15:56:37 +08:00
|
|
|
|
SetItem(summaryInfo.id.ToString(), summaryInfo.team);
|
2023-12-12 10:29:10 +08:00
|
|
|
|
sb.AppendLine($"选手ID:{summaryInfo.id}");
|
2023-12-20 15:56:37 +08:00
|
|
|
|
sb.AppendLine($"选手文化元素:{summaryInfo.team}");
|
2023-12-12 10:29:10 +08:00
|
|
|
|
sb.AppendLine($"\n");
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 15:56:37 +08:00
|
|
|
|
GlobalManager.Instance.list = list;
|
|
|
|
|
|
2023-12-12 10:29:10 +08:00
|
|
|
|
FileManager.Instance.SavePlayerTeamData(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 15:56:37 +08:00
|
|
|
|
private void SetItem(string id, string culture)
|
2023-12-12 10:29:10 +08:00
|
|
|
|
{
|
2023-12-20 15:56:37 +08:00
|
|
|
|
var i = int.Parse(id);
|
|
|
|
|
if (cultures.TryGetValue(i, out var data))
|
|
|
|
|
{
|
|
|
|
|
data.SetCultureName(culture);
|
|
|
|
|
}
|
2023-12-12 10:29:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|