Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- public static class MonobehaviourExtensions
- {
- /// <summary>
- /// Use <code>
- /// private void Start() => Initialize();
- /// private void OnEnable() => this.OnAssemblyReload(Initialize);</code>
- /// </summary>
- /// <param name="mb"></param>
- /// <param name="action"></param>
- public static void OnAssemblyReload(this MonoBehaviour mb, Action action)
- {
- #if UNITY_EDITOR
- UnityEditor.AssemblyReloadEvents.afterAssemblyReload += Handler;
- #endif
- void Handler() => action();
- }
- }
Advertisement
Comments
-
- Visual Studio snippet:
- <?xml version="1.0" encoding="utf-8"?>
- <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
- <CodeSnippet Format="1.0.0">
- <Header>
- <Title>Initialize OnAssemblyReload</Title>
- <Shortcut>onassemblyreload</Shortcut>
- </Header>
- <Snippet>
- <Code Language="csharp" Delimiter="$">
- <![CDATA[private void Start() => Initialize();
- private void OnEnable() => this.OnAssemblyReload(Initialize);
- private void Initialize()
- {
- $selected$$end$
- }$end$]]></Code>
- </Snippet>
- </CodeSnippet>
- </CodeSnippets>
Add Comment
Please, Sign In to add comment
Advertisement