first commit
This commit is contained in:
commit
aa44d3ad70
1585 changed files with 277994 additions and 0 deletions
95
Assets/Plugins/CodeAssist/Editor/NetMQInitializer.cs
Normal file
95
Assets/Plugins/CodeAssist/Editor/NetMQInitializer.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
|
||||
#nullable enable
|
||||
|
||||
|
||||
namespace Meryel.UnityCodeAssist.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public static class NetMQInitializer
|
||||
{
|
||||
public static NetMQPublisher? Publisher;
|
||||
|
||||
static NetMQInitializer()
|
||||
{
|
||||
EditorApplication.quitting += EditorApplication_quitting;
|
||||
AssemblyReloadEvents.beforeAssemblyReload += AssemblyReloadEvents_beforeAssemblyReload;
|
||||
AssemblyReloadEvents.afterAssemblyReload += AssemblyReloadEvents_afterAssemblyReload;
|
||||
|
||||
RunOnceOnUpdate(Initialize);
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
Serilog.Log.Debug("NetMQ initializing");
|
||||
|
||||
AsyncIO.ForceDotNet.Force();
|
||||
|
||||
Serilog.Log.Debug("NetMQ cleaning up (true)");
|
||||
NetMQ.NetMQConfig.Cleanup(true);
|
||||
|
||||
Serilog.Log.Debug("NetMQ constructing");
|
||||
Publisher = new NetMQPublisher();
|
||||
|
||||
RunOnShutdown(OnShutDown);
|
||||
Serilog.Log.Debug("NetMQ initialized");
|
||||
}
|
||||
|
||||
private static void OnShutDown()
|
||||
{
|
||||
Serilog.Log.Debug("NetMQ OnShutDown");
|
||||
Clear();
|
||||
}
|
||||
|
||||
private static void AssemblyReloadEvents_afterAssemblyReload()
|
||||
{
|
||||
Serilog.Log.Debug("NetMQ AssemblyReloadEvents_afterAssemblyReload");
|
||||
}
|
||||
|
||||
//private static void AssemblyReloadEvents_beforeAssemblyReload() => Clear();
|
||||
private static void AssemblyReloadEvents_beforeAssemblyReload()
|
||||
{
|
||||
Serilog.Log.Debug("NetMQ AssemblyReloadEvents_beforeAssemblyReload");
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
private static void EditorApplication_quitting()
|
||||
{
|
||||
Serilog.Log.Debug("NetMQ EditorApplication_quitting");
|
||||
|
||||
Publisher?.SendDisconnect();
|
||||
Clear();
|
||||
}
|
||||
|
||||
static void Clear() => Publisher?.Clear();
|
||||
|
||||
|
||||
private static void RunOnceOnUpdate(Action action)
|
||||
{
|
||||
void callback()
|
||||
{
|
||||
EditorApplication.update -= callback;
|
||||
action();
|
||||
}
|
||||
|
||||
EditorApplication.update += callback;
|
||||
}
|
||||
|
||||
private static void RunOnShutdown(Action action)
|
||||
{
|
||||
// Mono on OSX has all kinds of quirks on AppDomain shutdown
|
||||
//if (!VisualStudioEditor.IsWindows)
|
||||
//return;
|
||||
#if !UNITY_EDITOR_WIN
|
||||
return;
|
||||
#else
|
||||
AppDomain.CurrentDomain.DomainUnload += (_, __) => action();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue