Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Name"></param>
        public static void RemoveInstance(string Name)
        {
            if (m_Container != null && m_SingletonMap.ContainsKey(Name))
            {
                UnityEngine.Object.Destroy((UnityEngine.Object)(m_SingletonMap[Name]));
                m_SingletonMap.Remove(Name);

                DLoger.LogWarning("Singleton REMOVE! (" + Name + ")");
            }
        }
Пример #2
0
 /// <summary>
 /// 非泛型接口
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public static Object getInstance(System.Type type)
 {
     if (m_Container == null)
     {
         m_Container      = new GameObject();
         m_Container.name = m_Name;
         m_Container.AddComponent(typeof(SingleMono));
     }
     if (!m_SingletonMap.ContainsKey(type.Name))
     {
         Component t = m_Container.AddComponent(type);
         if (t != null)
         {
             m_SingletonMap.Add(type.Name, t);
         }
         else
         {
             DLoger.LogWarning("Singleton Type ERROR! (" + type.Name + ")");
         }
     }
     return(m_SingletonMap[type.Name]);
 }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static Object getInstance <T>() where T : MonoBehaviour
 {
     if (m_Container == null)
     {
         m_Container      = new GameObject();
         m_Container.name = m_Name;
         m_Container.AddComponent(typeof(SingleMono));
     }
     if (!m_SingletonMap.ContainsKey(typeof(T).Name))
     {
         T t = m_Container.AddComponent <T>();
         if (t != null)
         {
             m_SingletonMap.Add(typeof(T).Name, t);
         }
         else
         {
             DLoger.LogWarning("Singleton Type ERROR! (" + typeof(T).Name + ")");
         }
     }
     return(m_SingletonMap[typeof(T).Name]);
 }