Aimbot-ParallelEnv/Assets/EnviromentUIControl.cs

72 lines
2.0 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using XCharts.Runtime;
public class EnviromentUIControl : MonoBehaviour
{
public GameObject agentObj;
public TextMeshProUGUI remainTimeText;
public TextMeshProUGUI winLoseText;
private AgentWithGun agentScript;
public LineChart realTimeRewardChart;
public GameObject chartContainer;
private float overTime = 0f;
private int step = 0;
private bool resultActive = false;
// Start is called before the first frame update
void Start()
{
agentScript = agentObj.GetComponent<AgentWithGun>();
}
// Update is called once per frame
void Update()
{
int remainTime = agentScript.remainTime;
int finishedState = agentScript.finishedState;// 1 = win,2 = lose,0 = not dont
remainTimeText.text = "RemainTime:" + remainTime.ToString();
if (finishedState == 1)
{
//Win
Debug.Log("win");
winLoseText.text = "Win";
winLoseText.color = Color.green;
overTime = Time.time;
resultActive = true;
}
else if (finishedState == 2)
{
//lose
Debug.Log("lose");
winLoseText.text = "Lose";
winLoseText.color = Color.red;
overTime = Time.time;
resultActive = true;
}
else if (finishedState == 0 && resultActive && Time.time - overTime >= 1)
{
Debug.Log("clear");
winLoseText.text = "";
winLoseText.color = Color.white;
resultActive = false;
}
}
public void updateChart(float reward)
{
step += 1;
realTimeRewardChart.AddXAxisData(Convert.ToString(step));
realTimeRewardChart.AddData(0, reward);
}
public void initChart()
{
realTimeRewardChart.RemoveData();
realTimeRewardChart.AddSerie<Line>("Rewards");
}
}