using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Unity.VisualScripting { [IncludeInSettings(false)] public sealed class DictionaryAsset : LudiqScriptableObject, IDictionary { public object this[string key] { get { return dictionary[key]; } set { dictionary[key] = value; } } [Serialize] public Dictionary dictionary { get; private set; } = new Dictionary(); public int Count => dictionary.Count; public ICollection Keys => dictionary.Keys; public ICollection Values => dictionary.Values; bool ICollection>.IsReadOnly => ((ICollection>)dictionary).IsReadOnly; protected override void OnAfterDeserialize() { base.OnAfterDeserialize(); if (dictionary == null) { dictionary = new Dictionary(); } } public void Clear() { dictionary.Clear(); } public bool ContainsKey(string key) { return dictionary.ContainsKey(key); } public void Add(string key, object value) { dictionary.Add(key, value); } public void Merge(DictionaryAsset other, bool overwriteExisting = true) { foreach (var key in other.Keys) { if (overwriteExisting) { dictionary[key] = other[key]; } else if (!dictionary.ContainsKey(key)) { dictionary.Add(key, other[key]); } } } public bool Remove(string key) { return dictionary.Remove(key); } public bool TryGetValue(string key, out object value) { return dictionary.TryGetValue(key, out value); } public IEnumerator> GetEnumerator() { return dictionary.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)dictionary).GetEnumerator(); } void ICollection>.Add(KeyValuePair item) { ((ICollection>)dictionary).Add(item); } bool ICollection>.Contains(KeyValuePair item) { return ((ICollection>)dictionary).Contains(item); } void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { ((ICollection>)dictionary).CopyTo(array, arrayIndex); } bool ICollection>.Remove(KeyValuePair item) { return ((ICollection>)dictionary).Remove(item); } [ContextMenu("Show Data...")] protected override void ShowData() { base.ShowData(); } } }