163 lines
4.7 KiB
C#
163 lines
4.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
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;
|
||
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;
|
||
|
||
public override void Init()
|
||
{
|
||
base.Init();
|
||
btn_Close.onClick.AddListener(ClickClose);
|
||
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;
|
||
}
|
||
|
||
public override void Dispose()
|
||
{
|
||
base.Dispose();
|
||
btn_Close.onClick.RemoveListener(ClickClose);
|
||
btn_Stop.onClick.RemoveListener(ClickStop);
|
||
}
|
||
|
||
public override void Open()
|
||
{
|
||
base.Open();
|
||
InitItem();
|
||
}
|
||
|
||
private void ClickClose()
|
||
{
|
||
var openPanel = UIManager.Instance.GetPanel<HomePanel>(PanelType.Home);
|
||
openPanel.SetCultureFinish();
|
||
UIManager.Instance.OpenPanel(PanelType.Home);
|
||
Close();
|
||
}
|
||
|
||
void InitItem()
|
||
{
|
||
List<SummaryInfo> cache = new List<SummaryInfo>(GlobalManager.Instance.list);
|
||
|
||
foreach (var summaryInfo in cache)
|
||
{
|
||
var cultrueDataInfo = ExcelManager.Instance.GetCultureRandomInfo;
|
||
summaryInfo.culture = cultrueDataInfo.cultureName;
|
||
}
|
||
|
||
// 排个序
|
||
var list = cache.OrderBy(t => t.id).ToList();
|
||
|
||
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);
|
||
|
||
foreach (var summaryInfo in cache)
|
||
{
|
||
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)
|
||
{
|
||
item.SetActive(false);
|
||
SetItem(summaryInfo.id.ToString(), summaryInfo.team);
|
||
sb.AppendLine($"选手ID:{summaryInfo.id}");
|
||
sb.AppendLine($"选手文化元素:{summaryInfo.team}");
|
||
sb.AppendLine($"\n");
|
||
}
|
||
|
||
GlobalManager.Instance.list = list;
|
||
|
||
FileManager.Instance.SavePlayerTeamData(sb.ToString());
|
||
}
|
||
|
||
private void SetItem(string id, string culture)
|
||
{
|
||
var i = int.Parse(id);
|
||
if (cultures.TryGetValue(i, out var data))
|
||
{
|
||
data.SetCultureName(culture);
|
||
}
|
||
}
|
||
}
|
||
} |