using System; using System.Collections.Generic; using System.Collections.ObjectModel; using UnityEngine; namespace SK.Framework { [Serializable] public class Variables { [SerializeField] private List variables; public ReadOnlyCollection VariableCollection { get { return variables.AsReadOnly(); } } public Variable this[int index] { get { return variables[index]; } } public object Get(string name) { if(null == variables || variables.Count <= 0) { return null; } var variable = variables.Find(v => v.Name.Equals(name)); return variable?.GetValue(); } public void Set(string name, object value) { if(null == variables || variables.Count <= 0) { return; } var variable = variables.Find(v => v.Name.Equals(name)); variable?.SetValue(value); } public T Get(string name) { if (null == variables || variables.Count <= 0) { return default; } var variable = variables.Find(v => v.Name.Equals(name)); return variable == null ? default : variable.GetValue(); } public void Set(string name, T value) { if(null == variables || variables.Count <= 0) { return; } var variable = variables.Find(v => v.Name.Equals(name)); variable?.SetValue(value); } public static implicit operator List(Variables array) { return array.variables; } public static implicit operator Variables(List variables) { return new Variables() { variables = variables }; } } }