123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class DAL : Singleton<DAL>
- {
- private Dictionary<Type, Proxy> m_map;
- public DAL()
- {
- m_map = new Dictionary<Type, Proxy>();
- }
- 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<T>() 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<T>() where T : DataProxy
- {
- return Remove(typeof(T));
- }
- public void Clear()
- {
- foreach (var item in m_map)
- item.Value.OnRemove();
- m_map.Clear();
- }
- }
|