using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Serialization; namespace MLAgents { [Serializable] public class ResetParameters : Dictionary, ISerializationCallbackReceiver { [Serializable] public struct ResetParameter { public string key; public float value; } public ResetParameters() {} public ResetParameters(IDictionary dict) : base(dict) { UpdateResetParameters(); } void UpdateResetParameters() { m_ResetParameters.Clear(); foreach (var pair in this) { m_ResetParameters.Add(new ResetParameter { key = pair.Key, value = pair.Value }); } } [FormerlySerializedAs("resetParameters")] [SerializeField] List m_ResetParameters = new List(); 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); } } } } }