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

60 行
1.5 KiB

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace MLAgents
{
[Serializable]
public class ResetParameters : Dictionary<string, float>, ISerializationCallbackReceiver
{
[Serializable]
public struct ResetParameter
{
public string key;
public float value;
}
public ResetParameters() {}
public ResetParameters(IDictionary<string, float> dict) : base(dict)
{
UpdateResetParameters();
}
private void UpdateResetParameters()
{
m_ResetParameters.Clear();
foreach (var pair in this)
{
m_ResetParameters.Add(new ResetParameter { key = pair.Key, value = pair.Value });
}
}
[FormerlySerializedAs("resetParameters")]
[SerializeField] private List<ResetParameter> m_ResetParameters = new List<ResetParameter>();
public void OnBeforeSerialize()
{
UpdateResetParameters();
}
public void OnAfterDeserialize()
{
Clear();
for (var i = 0; i < m_ResetParameters.Count; i++)
{
if (ContainsKey(m_ResetParameters[i].key))
{
Debug.LogError("The ResetParameters contains the same key twice");
}
else
{
Add(m_ResetParameters[i].key, m_ResetParameters[i].value);
}
}
}
}
}