您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
63 行
1.8 KiB
63 行
1.8 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace MLAgents
|
|
{
|
|
|
|
/// <summary>
|
|
/// Behavioral Cloning Helper script. Attach to teacher agent to enable
|
|
/// resetting the experience buffer, as well as toggling session recording.
|
|
/// </summary>
|
|
public class BCTeacherHelper : MonoBehaviour
|
|
{
|
|
|
|
bool recordExperiences;
|
|
bool resetBuffer;
|
|
Agent myAgent;
|
|
float bufferResetTime;
|
|
|
|
public KeyCode recordKey = KeyCode.R;
|
|
public KeyCode resetKey = KeyCode.C;
|
|
|
|
// Use this for initialization
|
|
void Start()
|
|
{
|
|
recordExperiences = true;
|
|
resetBuffer = false;
|
|
myAgent = GetComponent<Agent>();
|
|
bufferResetTime = Time.time;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(recordKey))
|
|
{
|
|
recordExperiences = !recordExperiences;
|
|
}
|
|
|
|
if (Input.GetKeyDown(resetKey))
|
|
{
|
|
resetBuffer = true;
|
|
bufferResetTime = Time.time;
|
|
}
|
|
else
|
|
{
|
|
resetBuffer = false;
|
|
}
|
|
|
|
Monitor.Log("Recording experiences " + recordKey, recordExperiences.ToString());
|
|
float timeSinceBufferReset = Time.time - bufferResetTime;
|
|
Monitor.Log("Seconds since buffer reset " + resetKey,
|
|
Mathf.FloorToInt(timeSinceBufferReset).ToString());
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
// Convert both bools into single comma separated string. Python makes
|
|
// assumption that this structure is preserved.
|
|
myAgent.SetTextObs(recordExperiences + "," + resetBuffer);
|
|
}
|
|
}
|
|
}
|