This repository was archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (83 loc) · 2.15 KB
/
Copy pathProgram.cs
File metadata and controls
100 lines (83 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using Mono.Debugging.Client;
using MonoDevelop.Debugger.Soft.Unity;
using VSCodeDebug;
namespace UnityDebug
{
public class Program
{
class Logger : MonoDevelop.Debugger.Soft.Unity.Log.ILogger
{
public void Info(string message)
{
Log.Write (message);
}
public void Warning(string message, Exception e)
{
Log.Write (message);
}
public void Error(string message, Exception e)
{
Log.Write (message);
}
}
class CustomLogger : ICustomLogger
{
public void LogAndShowException(string message, Exception ex)
{
LogError(message, ex);
}
public void LogError(string message, Exception ex)
{
Log.LogError(message, ex);
}
public void LogMessage(string messageFormat, params object[] args)
{
Log.Write(string.Format(messageFormat, args));
}
public string GetNewDebuggerLogFilename()
{
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location) + "-another-log.txt");
}
}
static void Main(string[] argv)
{
if(argv.Length > 0 && argv[0] == "list")
{
Console.Write(GetUnityProcesses());
return;
}
// while (!Debugger.IsAttached)
// {
// System.Threading.Thread.Sleep(100);
// }
Log.Write ("UnityDebug");
MonoDevelop.Debugger.Soft.Unity.Log.AddLogger (new Logger());
try
{
RunSession(Console.OpenStandardInput(), Console.OpenStandardOutput());
}
catch(Exception e)
{
Log.Write ("Exception: " + e);
}
}
static void RunSession(Stream inputStream, Stream outputStream)
{
Log.Write("Running session");
DebugSession debugSession = new UnityDebugSession();
DebuggerLoggingService.CustomLogger = new CustomLogger();
debugSession.Start(inputStream, outputStream).Wait();
Log.Write("Session Terminated");
}
static string GetUnityProcesses()
{
var processes = UnityProcessDiscovery.GetAttachableProcesses();
return string.Join("\n", processes.Select(x => $"{x.Name} ({x.Id})" + $" {x.ProjectName}"));
}
}
}