using System.Collections.Generic; namespace Rokid.UXR { /// /// Data Cache /// public class DataCache : Singleton { Dictionary data = new Dictionary(); /// /// Add Data /// /// /// /// public void Add(string key, object value, bool cover = false) { if (data.ContainsKey(key) && cover == false) { RKLog.KeyInfo($"====DataCache=== Add Key Repetition {key}: {value}"); return; } else if (data.ContainsKey(key) && cover == true) { data[key] = value; } else { data.Add(key, value); } } /// /// Add Data /// /// /// public void Add(object value, bool cover = false) { string key = value.GetType().FullName; Add(key, value, cover); } /// /// Update Data /// /// /// public void UpdateData(string key, object value) { if (data.ContainsKey(key)) { data[key] = value; } else { RKLog.KeyInfo($"====DataCache=== UpdateData Key Repetition {key}: {value}"); } } /// /// Get Value /// /// /// /// public T Get(string key) { object obj = null; if (data.TryGetValue(key, out obj)) { return (T)obj; } else { RKLog.KeyInfo($"====DataCache=== Get Key Not Exist {key}"); } return default; } /// /// Get Value /// /// Data Object /// Data Key /// public T Get() { string key = typeof(T).FullName; return Get(key); } /// /// Get All Keys /// /// public List Keys() { return new List(data.Keys); } /// /// Clear Data /// public void Clear() { data.Clear(); } } }