You've already forked com.unity.ide.cursor
mirror of
https://github.com/boxqkrtm/com.unity.ide.cursor.git
synced 2026-05-16 15:30:08 +00:00
com.unity.ide.visualstudio@2.0.0
## [2.0.0] - 2019-11-06 - Improved Visual Studio and Visual Studio for Mac automatic discovery - Added support for the VSTU messaging system (start/stop features from Visual Studio) - Added support for solution roundtrip (preserves references to external projects and solution properties) - Added support for VSTU Analyzers (requires Visual Studio 2019 16.3, Visual Studio for Mac 8.3) - Added a warning when using legacy pdb symbol files. - Fixed issues while Opening Visual Studio on Windows - Fixed issues while Opening Visual Studio on Mac ## [1.1.1] - 2019-05-29 Fix Bridge assembly loading with non VS2017 editors ## [1.1.0] - 2019-05-27 Move internal extension handling to package.
This commit is contained in:
174
Editor/VisualStudioIntegration.cs
Normal file
174
Editor/VisualStudioIntegration.cs
Normal file
@@ -0,0 +1,174 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using Microsoft.Unity.VisualStudio.Editor.Messaging;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using MessageType = Microsoft.Unity.VisualStudio.Editor.Messaging.MessageType;
|
||||
|
||||
namespace Microsoft.Unity.VisualStudio.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
internal class VisualStudioIntegration
|
||||
{
|
||||
private static Messager _messager;
|
||||
|
||||
private static readonly Queue<Message> Incoming = new Queue<Message>();
|
||||
private static readonly object IncomingLock = new object();
|
||||
|
||||
public static Application.LogCallback LogCallback = delegate { };
|
||||
|
||||
static VisualStudioIntegration()
|
||||
{
|
||||
RunOnceOnUpdate(() =>
|
||||
{
|
||||
_messager = Messager.BindTo(MessagingPort());
|
||||
_messager.ReceiveMessage += ReceiveMessage;
|
||||
|
||||
RunOnShutdown(Shutdown);
|
||||
});
|
||||
|
||||
EditorApplication.update += OnUpdate;
|
||||
}
|
||||
|
||||
private static void RunOnceOnUpdate(Action action)
|
||||
{
|
||||
var callback = null as EditorApplication.CallbackFunction;
|
||||
|
||||
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;
|
||||
|
||||
AppDomain.CurrentDomain.DomainUnload += (_, __) => action();
|
||||
}
|
||||
|
||||
private static int DebuggingPort()
|
||||
{
|
||||
return 56000 + (System.Diagnostics.Process.GetCurrentProcess().Id % 1000);
|
||||
}
|
||||
|
||||
private static int MessagingPort()
|
||||
{
|
||||
return DebuggingPort() + 2;
|
||||
}
|
||||
|
||||
private static void ReceiveMessage(object sender, MessageEventArgs args)
|
||||
{
|
||||
OnMessage(args.Message);
|
||||
}
|
||||
|
||||
private static void OnUpdate()
|
||||
{
|
||||
lock (IncomingLock)
|
||||
{
|
||||
while (Incoming.Count > 0)
|
||||
{
|
||||
ProcessIncoming(Incoming.Dequeue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddMessage(Message message)
|
||||
{
|
||||
lock (IncomingLock)
|
||||
{
|
||||
Incoming.Enqueue(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessIncoming(Message message)
|
||||
{
|
||||
switch (message.Type)
|
||||
{
|
||||
case MessageType.Ping:
|
||||
Answer(message, MessageType.Pong);
|
||||
break;
|
||||
case MessageType.Play:
|
||||
Shutdown();
|
||||
EditorApplication.isPlaying = true;
|
||||
break;
|
||||
case MessageType.Stop:
|
||||
EditorApplication.isPlaying = false;
|
||||
break;
|
||||
case MessageType.Pause:
|
||||
EditorApplication.isPaused = true;
|
||||
break;
|
||||
case MessageType.Unpause:
|
||||
EditorApplication.isPaused = false;
|
||||
break;
|
||||
case MessageType.Build:
|
||||
// Not used anymore
|
||||
break;
|
||||
case MessageType.Refresh:
|
||||
Refresh();
|
||||
break;
|
||||
case MessageType.Version:
|
||||
Answer(message, MessageType.Version, PackageVersion());
|
||||
break;
|
||||
case MessageType.UpdatePackage:
|
||||
// Not used anymore
|
||||
break;
|
||||
case MessageType.ProjectPath:
|
||||
Answer(message, MessageType.ProjectPath, Path.GetFullPath(Path.Combine(Application.dataPath, "..")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static string PackageVersion()
|
||||
{
|
||||
var package = UnityEditor.PackageManager.PackageInfo.FindForAssembly(typeof(VisualStudioIntegration).Assembly);
|
||||
return package.version;
|
||||
}
|
||||
|
||||
private static void Refresh()
|
||||
{
|
||||
RunOnceOnUpdate(AssetDatabase.Refresh);
|
||||
}
|
||||
|
||||
private static void OnMessage(Message message)
|
||||
{
|
||||
AddMessage(message);
|
||||
}
|
||||
|
||||
private static void Answer(Message message, MessageType answerType, string answerValue = "")
|
||||
{
|
||||
var targetEndPoint = message.Origin;
|
||||
|
||||
Answer(
|
||||
targetEndPoint,
|
||||
answerType,
|
||||
answerValue);
|
||||
}
|
||||
|
||||
private static void Answer(IPEndPoint targetEndPoint, MessageType answerType, string answerValue)
|
||||
{
|
||||
_messager?.SendMessage(targetEndPoint, answerType, answerValue);
|
||||
}
|
||||
|
||||
private static void Shutdown()
|
||||
{
|
||||
if (_messager == null)
|
||||
return;
|
||||
|
||||
_messager.ReceiveMessage -= ReceiveMessage;
|
||||
_messager.Dispose();
|
||||
_messager = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user