|
|
|
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.SceneManagement; |
|
|
|
using MLAgents; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
|
|
|
Agent m_Agent; |
|
|
|
|
|
|
|
|
|
|
|
ResetAgent(); |
|
|
|
m_Position = 10; |
|
|
|
transform.position = new Vector3(m_Position - 10f, 0f, 0f); |
|
|
|
smallGoal.transform.position = new Vector3(k_SmallGoalPosition - 10f, 0f, 0f); |
|
|
|
largeGoal.transform.position = new Vector3(k_LargeGoalPosition - 10f, 0f, 0f); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public void ResetAgent() |
|
|
|
{ |
|
|
|
m_Position = 10; |
|
|
|
smallGoal.transform.position = new Vector3(k_SmallGoalPosition - 10f, 0f, 0f); |
|
|
|
largeGoal.transform.position = new Vector3(k_LargeGoalPosition - 10f, 0f, 0f); |
|
|
|
{ |
|
|
|
// This is a very inefficient way to reset the scene. Used here for testing.
|
|
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().name); |
|
|
|
m_Agent = null; // LoadScene only takes effect at the next Update.
|
|
|
|
// We set the Agent to null to avoid using the Agent before the reload
|
|
|
|
} |
|
|
|
|
|
|
|
public void FixedUpdate() |
|
|
|
|
|
|
|
|
|
|
void WaitTimeInference() |
|
|
|
{ |
|
|
|
if (m_Agent == null) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
m_Agent.RequestDecision(); |
|
|
|
m_Agent?.RequestDecision(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
ApplyAction(m_Agent.GetAction()); |
|
|
|
|
|
|
|
m_TimeSinceDecision = 0f; |
|
|
|
m_Agent.RequestDecision(); |
|
|
|
m_Agent?.RequestDecision(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|