2022-11-28 22:54:08 +00:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
using XCharts.Runtime;
|
|
|
|
|
|
|
|
public class WorldUIController : MonoBehaviour
|
|
|
|
{
|
2023-06-30 09:30:12 +00:00
|
|
|
public LineChart winChart;
|
2022-11-28 22:54:08 +00:00
|
|
|
public int[] totalGames;
|
|
|
|
public int[] winGames;
|
|
|
|
|
|
|
|
private int maxXAxis = 0;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
// Start is called before the first frame update
|
2023-06-30 09:30:12 +00:00
|
|
|
private void Start()
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
2023-04-09 14:35:38 +00:00
|
|
|
totalGames = new int[(int)SceneBlockContainer.Targets.Num];
|
|
|
|
winGames = new int[(int)SceneBlockContainer.Targets.Num];
|
|
|
|
Array.Clear(totalGames, 0, (int)SceneBlockContainer.Targets.Num);
|
|
|
|
Array.Clear(winGames, 0, (int)SceneBlockContainer.Targets.Num);
|
2022-11-28 22:54:08 +00:00
|
|
|
//WinChart.Init();
|
2023-06-30 09:30:12 +00:00
|
|
|
winChart.RemoveData();
|
2023-04-09 14:35:38 +00:00
|
|
|
for (int i = 0; i < (int)SceneBlockContainer.Targets.Num; i++)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
2023-04-09 14:35:38 +00:00
|
|
|
string lineName = Enum.GetName(typeof(SceneBlockContainer.Targets), i);
|
2023-06-30 09:30:12 +00:00
|
|
|
winChart.AddSerie<Line>(lineName);
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 09:30:12 +00:00
|
|
|
public void UpdateChart(int targetType, int endType)
|
2022-11-28 22:54:08 +00:00
|
|
|
{
|
|
|
|
float winRatio = 0f;
|
|
|
|
switch (endType)
|
|
|
|
{
|
|
|
|
case (int)TargetController.EndType.Win:
|
|
|
|
//Win
|
|
|
|
totalGames[targetType] += 1;
|
|
|
|
winGames[targetType] += 1;
|
|
|
|
winRatio = (float)winGames[targetType] / totalGames[targetType];
|
2023-06-30 09:30:12 +00:00
|
|
|
winChart.AddData(targetType, winRatio);
|
2022-11-28 22:54:08 +00:00
|
|
|
if (totalGames[targetType] > maxXAxis)
|
|
|
|
{
|
|
|
|
maxXAxis = totalGames[targetType];
|
2023-06-30 09:30:12 +00:00
|
|
|
winChart.AddXAxisData(Convert.ToString(maxXAxis));
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
case (int)TargetController.EndType.Lose:
|
|
|
|
//lose
|
|
|
|
totalGames[targetType] += 1;
|
|
|
|
winRatio = (float)winGames[targetType] / totalGames[targetType];
|
2023-06-30 09:30:12 +00:00
|
|
|
winChart.AddData(targetType, winRatio);
|
2022-11-28 22:54:08 +00:00
|
|
|
if (totalGames[targetType] > maxXAxis)
|
|
|
|
{
|
|
|
|
maxXAxis = totalGames[targetType];
|
2023-06-30 09:30:12 +00:00
|
|
|
winChart.AddXAxisData(Convert.ToString(maxXAxis));
|
2022-11-28 22:54:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2023-06-30 09:30:12 +00:00
|
|
|
|
2022-11-28 22:54:08 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 09:30:12 +00:00
|
|
|
}
|