コード例 #1
0
 /// <summary>
 /// Called when the script is being destroyed.
 /// </summary>
 private void OnDestroy()
 {
     Logger.Log?.Debug($"{this.name}: OnDestroy()");
     this.CloseDanmakuClient();
     this._danmakuClient          = null;
     BiliSaberController.instance = null; // This MonoBehaviour is being destroyed, so set the static instance property to null.
 }
コード例 #2
0
 private void Awake()
 {
     // For this particular MonoBehaviour, we only want one instance to exist at any time, so store a reference to it in a static property
     // and destroy any that are created while one already exists.
     if (BiliSaberController.instance != null)
     {
         Logger.Log?.Warn($"Instance of {this.GetType().Name} already exists, destroying.");
         GameObject.DestroyImmediate(this);
         return;
     }
     GameObject.DontDestroyOnLoad(this); // Don't destroy this object on scene changes
     BiliSaberController.instance = this;
     this.InitUi();
     Logger.Log?.Debug($"{this.name}: Awake()");
 }