Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

52 行
1.5 KiB

using System;
using UnityEngine;
namespace MLAgents
{
/// <summary>
/// A component that when attached to an Agent will automatically request decisions from it
/// at regular intervals.
/// </summary>
[AddComponentMenu("ML Agents/Decision Requester", (int)MenuGroup.Default)]
public class DecisionRequester : MonoBehaviour
{
[Range(1, 20)]
[Tooltip("The agent will automatically request a decision every X Academy steps.")]
public int DecisionPeriod = 5;
[Tooltip("Whether or not AgentAction will be called on Academy steps that decisions aren't requested. Has no effect if DecisionPeriod is 1.")]
public bool RepeatAction = true;
[Tooltip("Whether or not Agent decisions should start at a random offset.")]
public bool offsetStep;
Agent m_Agent;
int m_Offset;
public void Awake()
{
m_Offset = offsetStep ? gameObject.GetInstanceID() : 0;
m_Agent = gameObject.GetComponent<Agent>();
Academy.Instance.AgentSetStatus += MakeRequests;
}
void OnDestroy()
{
if (Academy.IsInitialized)
{
Academy.Instance.AgentSetStatus -= MakeRequests;
}
}
void MakeRequests(int count)
{
if ((count + m_Offset) % DecisionPeriod == 0)
{
m_Agent?.RequestDecision();
}
if (RepeatAction)
{
m_Agent?.RequestAction();
}
}
}
}