Advertisement
whiteflare

Untitled

Jun 19th, 2022
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. #if UNITY_EDITOR
  2.  
  3. using UnityEditor;
  4. using UnityEngine;
  5.  
  6. namespace WF.Utillty.UtilSerializeTest
  7. {
  8.     public class SampleUtilWindow : EditorWindow
  9.     {
  10.         public SubUtil sub;
  11.  
  12.         private void OnEnable()
  13.         {
  14.             Debug.LogFormat("OnEnable: sub = {0}", sub != null ? "" + sub.GetInstanceID() : "null");
  15.             if (sub == null)
  16.             {
  17.                 sub = CreateInstance<SubUtil>();
  18.             }
  19.         }
  20.  
  21.         private void OnDisable()
  22.         {
  23.             sub = null; // この1行を実行すると正常、コメントアウトすると異常
  24.         }
  25.  
  26.         private void OnGUI()
  27.         {
  28.             if (sub != null)
  29.             {
  30.                 sub.OnGUI(); // OnDisableでnullを代入しないと実行されない
  31.             }
  32.         }
  33.  
  34.         [MenuItem("Tools/whiteflare/Sandbox/Sample Utility")]
  35.         public static void ShowWindow()
  36.         {
  37.             GetWindow<SampleUtilWindow>("Sample Utility");
  38.         }
  39.     }
  40.  
  41.     public class SubUtil : ScriptableObject
  42.     {
  43.         private void OnEnable()
  44.         {
  45.             Debug.LogFormat("SubUtil.OnEnable: {0}", GetInstanceID());
  46.         }
  47.  
  48.         private void OnDisable()
  49.         {
  50.             Debug.LogFormat("SubUtil.OnDisable: {0}", GetInstanceID());
  51.         }
  52.  
  53.         public void OnGUI()
  54.         {
  55.             GUILayout.Label("SubUtil.OnGUI: " + GetInstanceID());
  56.         }
  57.     }
  58. }
  59.  
  60. #endif
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement