Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if UNITY_EDITOR
- using UnityEditor;
- using UnityEngine;
- namespace WF.Utillty.UtilSerializeTest
- {
- public class SampleUtilWindow : EditorWindow
- {
- public SubUtil sub;
- private void OnEnable()
- {
- Debug.LogFormat("OnEnable: sub = {0}", sub != null ? "" + sub.GetInstanceID() : "null");
- if (sub == null)
- {
- sub = CreateInstance<SubUtil>();
- }
- }
- private void OnDisable()
- {
- sub = null; // この1行を実行すると正常、コメントアウトすると異常
- }
- private void OnGUI()
- {
- if (sub != null)
- {
- sub.OnGUI(); // OnDisableでnullを代入しないと実行されない
- }
- }
- [MenuItem("Tools/whiteflare/Sandbox/Sample Utility")]
- public static void ShowWindow()
- {
- GetWindow<SampleUtilWindow>("Sample Utility");
- }
- }
- public class SubUtil : ScriptableObject
- {
- private void OnEnable()
- {
- Debug.LogFormat("SubUtil.OnEnable: {0}", GetInstanceID());
- }
- private void OnDisable()
- {
- Debug.LogFormat("SubUtil.OnDisable: {0}", GetInstanceID());
- }
- public void OnGUI()
- {
- GUILayout.Label("SubUtil.OnGUI: " + GetInstanceID());
- }
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement