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

76 行
2.8 KiB

using System;
using UnityEngine;
namespace Unity.MLAgents.SideChannels
{
/// <summary>
/// Side channel that supports modifying attributes specific to the Unity Engine.
/// </summary>
internal class EngineConfigurationChannel : SideChannel
{
internal enum ConfigurationType : int
{
ScreenResolution = 0,
QualityLevel = 1,
TimeScale = 2,
TargetFrameRate = 3,
CaptureFrameRate = 4
}
const string k_EngineConfigId = "e951342c-4f7e-11ea-b238-784f4387d1f7";
/// <summary>
/// Initializes the side channel. The constructor is internal because only one instance is
/// supported at a time, and is created by the Academy.
/// </summary>
internal EngineConfigurationChannel()
{
ChannelId = new Guid(k_EngineConfigId);
}
/// <inheritdoc/>
protected override void OnMessageReceived(IncomingMessage msg)
{
var messageType = (ConfigurationType)msg.ReadInt32();
switch (messageType)
{
case ConfigurationType.ScreenResolution:
var width = msg.ReadInt32();
var height = msg.ReadInt32();
Screen.SetResolution(width, height, false);
break;
case ConfigurationType.QualityLevel:
var qualityLevel = msg.ReadInt32();
QualitySettings.SetQualityLevel(qualityLevel, true);
break;
case ConfigurationType.TimeScale:
var timeScale = msg.ReadFloat32();
// There's an upper limit for the timeScale in the editor (but not in the player)
// Always ensure that timeScale >= 1 also,
#if UNITY_EDITOR
const float maxTimeScale = 100f;
#else
const float maxTimeScale = float.PositiveInfinity;
#endif
timeScale = Mathf.Clamp(timeScale, 1, maxTimeScale);
Time.timeScale = timeScale;
break;
case ConfigurationType.TargetFrameRate:
var targetFrameRate = msg.ReadInt32();
Application.targetFrameRate = targetFrameRate;
break;
case ConfigurationType.CaptureFrameRate:
var captureFrameRate = msg.ReadInt32();
Time.captureFramerate = captureFrameRate;
break;
default:
Debug.LogWarning(
"Unknown engine configuration received from Python. Make sure" +
" your Unity and Python versions are compatible.");
break;
}
}
}
}