• MonoSingleton.cs

    namespace QFramework.Example
    {
      using System.Collections;
      using UnityEngine;
    
      class Class2MonoSingleton : QMonoSingleton<Class2MonoSingleton>
      {
          public override void OnSingletonInit()
          {
              Debug.Log(this.name + ":" + "OnSingletonInit");
          }
    
          private void Awake()
          {
              Debug.Log(this.name + ":" + "Awake");
          }
    
          private void Start()
          {
              Debug.Log(this.name + ":" + "Start");
          }
    
          protected override void OnDestroy()
          {
              base.OnDestroy();
    
              Debug.Log(this.name + ":" + "OnDestroy");
          }
      }
    
      public class MonoSingleton : MonoBehaviour
      {
          private IEnumerator Start()
          {
              var instance = Class2MonoSingleton.Instance;
    
              yield return new WaitForSeconds(3.0f);
    
              instance.Dispose();
          }
      }
    }

    结果:

     


    三秒之后,单例GameObject消失,并且触发了OnDestroy事件。

    转载请注明地址:凉鞋的笔记:liangxiegame.com

     

更多内容

相关文章:

  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
  • 2021-07-28
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2022-12-23
  • 2021-04-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
相关资源
相似解决方案