using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class DAL : Singleton { private Dictionary m_map; public DAL() { m_map = new Dictionary(); } public Proxy Get(Type type) { Proxy proxy; if (!m_map.TryGetValue(type, out proxy)) { proxy = (DataProxy)Activator.CreateInstance(type, true); m_map.Add(type, proxy); proxy.OnRegister(); } return proxy; } public T Get() where T : DataProxy, new() { return Get(typeof(T)) as T; } public bool Remove(Type type) { Proxy proxy; if(m_map.TryGetValue(type, out proxy)) { proxy.OnRemove(); return m_map.Remove(type); } return false; } public bool Remove() where T : DataProxy { return Remove(typeof(T)); } public void Clear() { foreach (var item in m_map) item.Value.OnRemove(); m_map.Clear(); } }