protected virtual void OnDestroy()
 {
     if (SingletonBehaviour.Instance == this)
     {
         SingletonBehaviour.Instance = null;
     }
 }
Пример #2
0
 void Awake()
 {
     if (_instance != null)
     {
         Debug.LogError("More than one instance of a singleton detected");
         return;
     }
     _instance = this;
 }
Пример #3
0
    protected void SetInstance()
    {
        if (SingletonBehaviour.Instance != null && SingletonBehaviour.Instance != this)
        {
            this.DestroyThisBehaviour();
            return;
        }

        SingletonBehaviour.Instance = this;
    }
Пример #4
0
 /// <summary>
 /// 移除所有消息处理
 /// </summary>
 public void RemoveAllMessageHands()
 {
     if (!SingletonBehaviour.isValid <Client>())
     {
         return;
     }
     foreach (var item in _handlers)
     {
         Client.Instance.RemoveMessageParse(item.Key, this.UnpackMessage);
     }
 }
Пример #5
0
 // Call this to upgrade a singleton to a persistent singleton.
 // This is most often done in Awake().
 // This will kill an instance that tries to be a persistent singleton but isn't the current instance.
 public static void DontDestroyElseKill(SingletonBehaviour <T> mb)
 {
     if (mb == instance)
     {
         MonoBehaviour.DontDestroyOnLoad(instance.gameObject);
     }
     else
     {
         MonoBehaviour.Destroy(mb);
     }
 }
Пример #6
0
 void Awake()
 {
     if (s_instance == null)
     {
         s_instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else if (s_instance != this)
     {
         Destroy(gameObject);
     }
 }
 private void Awake()
 {
     if (baseInstance == null)
     {
         baseInstance = this;
         instance     = this as T;
     }
     else
     {
         Destroy(this);
         return;
     }
 }
Пример #8
0
 // Call this to upgrade a singleton to a persistent singleton.
 // This is most often done in Awake().
 // This will kill an instance that tries to be a persistent singleton but isn't the current instance.
 public static bool DontDestroyElseKill(SingletonBehaviour <T> mb)
 {
     if (mb == instance)
     {
         MonoBehaviour.DontDestroyOnLoad(instance.gameObject);
         return(true);
     }
     else
     {
         MonoBehaviour.Destroy(mb.gameObject);
         return(false);
     }
 }
Пример #9
0
    // Use this for initialization
    protected virtual void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        // Sets this to not be destroyed when reloading scene
        DontDestroyOnLoad(gameObject);
    }
Пример #10
0
        private void OnDownloading(string error, string url, float progress)
        {
            if (!string.IsNullOrEmpty(error))
            {
                Debug.LogError(error);
                this.MoveNext();
                return;
            }

            Debug.LogFormat("Downloading {0} percent {1}", url, progress * 100);

            if (progress >= 1)
            {
                SingletonBehaviour.GetInstance <ZipResource>().AddTask(new ZipResource.LoadTask(_tempUrl, _bundleUrl, (IFileItem item) =>
                {
                    this.MoveNext();
                }));
            }
        }
 protected virtual void Awake()
 {
     SingletonBehaviour.Instance = this;
 }