protected static void Set(T value, SingletonTypes sType) { if (null == value) { if (_me && _me.gameObject) { Destroy(_me.gameObject); } _me = null; } else { _me = value; } //MyDebug.Log("Getting Persitatn info"); PersitantInfo mePi = IsPersitant(); if (mePi.isDontDestroy && !mePi.changeHierarchy) { SetPersitant(_me.gameObject, true); } if (mePi.changeHierarchy) { SetParentHer(_me.gameObject); } }
protected static T Get(SingletonTypes sType) { if (applicationIsQuitting) { MyDebug.Warning("[Singleton] Me of '" + typeof(T) + "' already destroyed on application quit." + " Won't create again - returning null."); return(null); } lock (locked) { type = typeof(T); if (null == _me) { T t; switch (sType) { case SingletonTypes.AutoCraete: t = FindSingleton(); if (null != t) { _me = t; } else { AutoCreateMe(); } break; case SingletonTypes.AutoCreateWithPrefab: t = FindSingleton(); if (null != t) { _me = t; } else { AutoCreateFromPrefab(); } break; case SingletonTypes.Precreated: throw new System.NullReferenceException("[Singleton] " + type.ToString() + " not present in scene"); break; } PersitantInfo mePi = IsPersitant(); if (mePi.isDontDestroy && !mePi.changeHierarchy) { SetPersitant(_me.gameObject, true); } if (mePi.changeHierarchy) { SetParentHer(_me.gameObject); } } } return(_me); }
static PersitantInfo IsPersitant() { PersitantInfo pi = new PersitantInfo(); PersistentSignleton attribute = (PersistentSignleton)GetParticularAttribute <PersistentSignleton>(_me); if (null != attribute) { //MyDebug.Log("DD: {0}, CH: {1}", attribute.isPersistent, attribute.isChangeHierarchy); pi.isDontDestroy = attribute.isPersistent; pi.changeHierarchy = attribute.isChangeHierarchy; } else { //MyDebug.Log("Attribute null"); } return(pi); }