2022-11-02 22:07:51 +00:00
|
|
|
using System;
|
2022-10-26 07:20:27 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
2022-11-02 22:07:51 +00:00
|
|
|
using XCharts.Runtime;
|
2022-10-26 07:20:27 +00:00
|
|
|
|
|
|
|
public class EnviromentUIControl : MonoBehaviour
|
|
|
|
{
|
|
|
|
public GameObject agentObj;
|
|
|
|
public TextMeshProUGUI remainTimeText;
|
2022-11-02 22:07:51 +00:00
|
|
|
public TextMeshProUGUI winLoseText;
|
2022-10-26 07:20:27 +00:00
|
|
|
private AgentWithGun agentScript;
|
2022-11-02 22:07:51 +00:00
|
|
|
public LineChart realTimeRewardChart;
|
|
|
|
public GameObject chartContainer;
|
|
|
|
private float overTime = 0f;
|
|
|
|
private int step = 0;
|
|
|
|
private bool resultActive = false;
|
2022-10-26 07:20:27 +00:00
|
|
|
|
|
|
|
// 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;
|
2022-11-02 22:07:51 +00:00
|
|
|
int finishedState = agentScript.finishedState;// 1 = win,2 = lose,0 = not dont
|
2022-10-26 07:20:27 +00:00
|
|
|
remainTimeText.text = "RemainTime:" + remainTime.ToString();
|
2022-11-02 22:07:51 +00:00
|
|
|
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");
|
2022-10-26 07:20:27 +00:00
|
|
|
}
|
|
|
|
}
|