Advertisement
zORg_alex

Assembly Reload safe initialization

Apr 20th, 2024
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | Source Code | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. public static class MonobehaviourExtensions
  5. {
  6.     /// <summary>
  7.     /// Use <code>
  8.     /// private void Start() => Initialize();
  9.     /// private void OnEnable() => this.OnAssemblyReload(Initialize);</code>
  10.     /// </summary>
  11.     /// <param name="mb"></param>
  12.     /// <param name="action"></param>
  13.     public static void OnAssemblyReload(this MonoBehaviour mb, Action action)
  14.     {
  15. #if UNITY_EDITOR
  16.         UnityEditor.AssemblyReloadEvents.afterAssemblyReload += Handler;
  17. #endif
  18.         void Handler() => action();
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement