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

65 行
2.2 KiB

using System.Collections.Generic;
namespace MLAgents
{
public class RawBytesChannel : SideChannel
{
private List<byte[]> m_MessagesReceived = new List<byte[]>();
private int m_ChannelId;
/// <summary>
/// RawBytesChannel provides a way to exchange raw byte arrays between Unity and Python.
/// </summary>
/// <param name="channelId"> The identifier for the RawBytesChannel. Must be
/// the same on Python and Unity.</param>
public RawBytesChannel(int channelId = 0)
{
m_ChannelId = channelId;
}
public override int ChannelType()
{
return (int)SideChannelType.RawBytesChannelStart + m_ChannelId;
}
public override void OnMessageReceived(byte[] data)
{
m_MessagesReceived.Add(data);
}
/// <summary>
/// Sends the byte array message to the Python side channel. The message will be sent
/// alongside the simulation step.
/// </summary>
/// <param name="data"> The byte array of data to send to Python.</param>
public void SendRawBytes(byte[] data)
{
QueueMessageToSend(data);
}
/// <summary>
/// Gets the messages that were sent by python since the last call to
/// GetAndClearReceivedMessages.
/// </summary>
/// <returns> a list of byte array messages that Python has sent.</returns>
public IList<byte[]> GetAndClearReceivedMessages()
{
var result = new List<byte[]>();
result.AddRange(m_MessagesReceived);
m_MessagesReceived.Clear();
return result;
}
/// <summary>
/// Gets the messages that were sent by python since the last call to
/// GetAndClearReceivedMessages. Note that the messages received will not
/// be cleared with a call to GetReceivedMessages.
/// </summary>
/// <returns> a list of byte array messages that Python has sent.</returns>
public IList<byte[]> GetReceivedMessages()
{
var result = new List<byte[]>();
result.AddRange(m_MessagesReceived);
return result;
}
}
}