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

69 行
2.3 KiB

using System.Linq;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
namespace Unity.MLAgents.Editor
{
internal class MLAgentsSettingsBuildProvider : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
private MLAgentsSettings m_SettingsAddedToPreloadedAssets;
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
var wasDirty = IsPlayerSettingsDirty();
m_SettingsAddedToPreloadedAssets = null;
var preloadedAssets = PlayerSettings.GetPreloadedAssets().ToList();
if (!preloadedAssets.Contains(MLAgentsSettingsManager.Settings))
{
m_SettingsAddedToPreloadedAssets = MLAgentsSettingsManager.Settings;
preloadedAssets.Add(m_SettingsAddedToPreloadedAssets);
PlayerSettings.SetPreloadedAssets(preloadedAssets.ToArray());
}
if (!wasDirty)
ClearPlayerSettingsDirtyFlag();
}
public void OnPostprocessBuild(BuildReport report)
{
if (m_SettingsAddedToPreloadedAssets == null)
return;
var wasDirty = IsPlayerSettingsDirty();
var preloadedAssets = PlayerSettings.GetPreloadedAssets().ToList();
if (preloadedAssets.Contains(m_SettingsAddedToPreloadedAssets))
{
preloadedAssets.Remove(m_SettingsAddedToPreloadedAssets);
PlayerSettings.SetPreloadedAssets(preloadedAssets.ToArray());
}
m_SettingsAddedToPreloadedAssets = null;
if (!wasDirty)
ClearPlayerSettingsDirtyFlag();
}
private static bool IsPlayerSettingsDirty()
{
var settings = Resources.FindObjectsOfTypeAll<PlayerSettings>();
if (settings != null && settings.Length > 0)
return EditorUtility.IsDirty(settings[0]);
return false;
}
private static void ClearPlayerSettingsDirtyFlag()
{
var settings = Resources.FindObjectsOfTypeAll<PlayerSettings>();
if (settings != null && settings.Length > 0)
EditorUtility.ClearDirty(settings[0]);
}
}
}