-
Notifications
You must be signed in to change notification settings - Fork 363
/
Copy pathUISimulationController.cs
88 lines (77 loc) · 1.94 KB
/
UISimulationController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/// Author: Samuel Arzt
/// Date: March 2017
#region Includes
using UnityEngine.UI;
using UnityEngine;
using System;
#endregion
/// <summary>
/// Class for controlling the various ui elements of the simulation
/// </summary>
public class UISimulationController : MonoBehaviour
{
#region Members
private CarController target;
/// <summary>
/// The Car to fill the GUI data with.
/// </summary>
public CarController Target
{
get { return target; }
set
{
if (target != value)
{
target = value;
if (target != null)
NeuralNetPanel.Display(target.Agent.FNN);
}
}
}
// GUI element references to be set in Unity Editor.
[SerializeField]
private Text[] InputTexts;
[SerializeField]
private Text Evaluation;
[SerializeField]
private Text GenerationCount;
[SerializeField]
private UINeuralNetworkPanel NeuralNetPanel;
#endregion
#region Constructors
void Awake()
{
}
#endregion
#region Methods
void Update()
{
if (Target != null)
{
//Display controls
if (Target.CurrentControlInputs != null)
{
for (int i = 0; i < InputTexts.Length; i++)
InputTexts[i].text = Target.CurrentControlInputs[i].ToString();
}
//Display evaluation and generation count
Evaluation.text = Target.Agent.Genotype.Evaluation.ToString();
GenerationCount.text = EvolutionManager.Instance.GenerationCount.ToString();
}
}
/// <summary>
/// Starts to display the gui elements.
/// </summary>
public void Show()
{
gameObject.SetActive(true);
}
/// <summary>
/// Stops displaying the gui elements.
/// </summary>
public void Hide()
{
gameObject.SetActive(false);
}
#endregion
}