Esempio n. 1
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="target"></param>
            /// <returns>Returns true if the validation was a success.</returns>
            public bool OnAwake(IManagedSingleton target)
            {
                if (object.ReferenceEquals(target, null))
                {
                    throw new System.ArgumentNullException("target");
                }
                _target = target;

                //first test if we have the appropriate configuration
                if (_target.component.GetComponents <IManagedSingleton>().Count() > 1 && !_target.component.HasComponent <SingletonManager>())
                {
                    Debug.LogWarning("Gameobject with multiple Singletons exists without a SingletonManager attached, adding a SingletonManager with default destroy settings.", target.component);
                    _target.component.AddComponent <SingletonManager>();
                }

                //now set up singleton reference
                if (_target.component.IsActiveAndEnabled())
                {
                    this.EnforceThisAsSingleton();
                    _target.ComponentDestroyed += this.OnComponentDestroyed;
                    SceneManager.sceneLoaded   += this.OnLevelWasLoaded;
                    return(true);
                }
                else
                {
                    //remove self if it were added
                    this.RemoveThisAsSingleton();
                    return(false);
                }
            }
Esempio n. 2
0
 public static bool HasInstance(System.Type tp, out IManagedSingleton instance)
 {
     return(_singletonRefs.TryGetValue(tp, out instance));
 }