示例#1
0
        public static IEnumerable <UnityProcessInfo> GetAttachableProcesses(string targetName)
        {
            string processName;

            if (!targetNameToProcessName.TryGetValue(targetName.ToLower(), out processName))
            {
                return(null);
            }

            UnityProcessDiscovery.GetProcessOptions options = UnityProcessDiscovery.GetProcessOptions.All;

            if (processName == "Unity Editor")
            {
                options = UnityProcessDiscovery.GetProcessOptions.Editor;
            }
            else
            {
                options = UnityProcessDiscovery.GetProcessOptions.Players;
            }

            var processes = UnityProcessDiscovery.GetAttachableProcesses(options);

            processes.ForEach(p => Log.Write("Found Unity process: " + p.Name + " (" + p.Id + ")"));

            return(processes.Where(p => p.Name.Contains(processName)));
        }
        public override Task <DebugResult> Attach(dynamic args)
        {
            string name = getString(args, "name");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes == null)
            {
                return(Task.FromResult(new DebugResult(8001, "Unknown target name '{_name}'. Did you mean 'Unity Editor'?", new { _name = name })));
            }

            if (processes.Length == 0)
            {
                return(Task.FromResult(new DebugResult(8001, "Could not find target name '{_name}'. Is it running?", new { _name = name })));
            }

            if (processes.Length > 1)
            {
                return(Task.FromResult(new DebugResult(8002, "Multiple targets with name '{_name}' running. Unable to connect.", new { _name = name })));
            }

            var process = processes [0];

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Debugger.Connect(attachInfo.Address, attachInfo.Port);
            return(Task.FromResult(CreateDebugResult("UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + ")\n")));
        }
        public static IEnumerable <UnityProcessInfo> GetAttachableProcesses(string targetName)
        {
            var match     = Regex.Match(targetName, "\\(([0-9]+)\\)");
            var processId = -1;

            if (match.Success)
            {
                processId  = Convert.ToInt32(match.Groups[1].Value);
                targetName = targetName.Substring(0, targetName.IndexOf("(") - 1);
            }

            UnityProcessDiscovery.GetProcessOptions options = UnityProcessDiscovery.GetProcessOptions.All;

            if (!targetNameToProcessName.TryGetValue(targetName.ToLower(), out var processName))
            {
                processName = targetName;
            }
            else
            {
                options = processName == "Unity Editor"
                    ? UnityProcessDiscovery.GetProcessOptions.Editor
                    : UnityProcessDiscovery.GetProcessOptions.Players;
            }

            var processes = UnityProcessDiscovery.GetAttachableProcesses(options);

            processes.ForEach(p => Log.Write("Found Unity process: " + p.Name + " (" + p.Id + ")"));

            return(processId == -1
                ? processes.Where(p => p.Name.Contains(processName))
                : processes.Where(p => p.Name.Contains(processName) && p.Id == processId));
        }
示例#4
0
        public override void Attach(Response response, dynamic args)
        {
            string name = getString(args, "name");

            SetExceptionBreakpoints(args.__exceptionOptions);

            SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes.Length == 0)
            {
                SendErrorResponse(response, 8001, "Could not find target name '{_name}'. Is it running?", new { _name = name });
                return;
            }

            UnityProcessInfo process;

            if (processes.Length == 1)
            {
                process = processes[0];
            }
            else
            {
                if (name.Contains("Editor"))
                {
                    string pathToEditorInstanceJson = getString(args, "path");
                    var    jObject   = JObject.Parse(File.ReadAllText(pathToEditorInstanceJson.TrimStart('/')));
                    var    processId = jObject["process_id"].ToObject <int>();
                    process = processes.First(p => p.Id == processId);
                }
                else
                {
                    SendErrorResponse(response, 8002, "Multiple targets with name '{_name}' running. Unable to connect.\n" +
                                      "Use \"Unity Attach Debugger\" from the command palette (View > Command Palette...) to specify which process to attach to.", new { _name = name });

                    SendOutput("stdout", "UnityDebug: Multiple targets with name '" + name + "' running. Unable to connect.\n" +
                               "Use \"Unity Attach Debugger\" from the command palette (View > Command Palette...) to specify which process to attach to.");

                    foreach (var p in processes)
                    {
                        SendOutput("stdout", "UnityDebug: Found Unity process '" + p.Name + "' (" + p.Id + ")\n");
                    }

                    return;
                }
            }

            SendOutput("stdout", "UnityDebug: Process ID" + process.Id);

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Connect(attachInfo.Address, attachInfo.Port);

            SendOutput("stdout", "UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + "):" + attachInfo.Port + "\n");
            SendResponse(response);
        }
        public static string GetUnityProcesses()
        {
            var options = UnityProcessDiscovery.GetProcessOptions.All;


            var processes = UnityProcessDiscovery.GetAttachableProcesses(options);

            return(string.Join("\n", processes.Select(x => x.Name)));
        }
        public override void Attach(Response response, dynamic args)
        {
            Log.Write($"UnityDebug: Attach: {response} ; {args}");
            string name = GetString(args, "name");

            SetExceptionBreakpoints(args.__exceptionOptions);

            Log.Write($"UnityDebug: Searching for Unity process '{name}'");
            SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes.Length == 0)
            {
                Log.Write($"Could not find target name '{name}'.");
                SetErrorResponse(response, 8001, "Could not find target name '{_name}'. Is it running?", new { _name = name });
                return;
            }

            UnityProcessInfo process;

            if (processes.Length == 1)
            {
                process = processes[0];
            }
            else
            {
                if (!name.Contains("Editor"))
                {
                    TooManyInstances(response, name, processes);
                    return;
                }

                string pathToEditorInstanceJson = GetString(args, "path");
                pathToEditorInstanceJson = CleanPath(pathToEditorInstanceJson);
                if (!File.Exists(pathToEditorInstanceJson))
                {
                    TooManyInstances(response, name, processes);
                    return;
                }

                var jObject   = JObject.Parse(File.ReadAllText(pathToEditorInstanceJson));
                var processId = jObject["process_id"].ToObject <int>();
                process = processes.First(p => p.Id == processId);
            }

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Connect(attachInfo.Address, attachInfo.Port);

            Log.Write($"UnityDebug: Attached to Unity process '{process.Name}' ({process.Id})");
            SendOutput("stdout", "UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + ")\n");
            SetResponse(response);
        }
示例#7
0
        public override void Attach(Response response, dynamic args)
        {
            Log.Write($"UnityDebug: Attach: {response} ; {args}");
            string name = GetString(args, "name");

            SetExceptionBreakpoints(args.__exceptionOptions);

            Log.Write($"UnityDebug: Searching for Unity process '{name}'");
            SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");

            int id;

            if (name.Contains("Editor"))
            {
                string pathToEditorInstanceJson = GetString(args, "path");
                pathToEditorInstanceJson = CleanPath(pathToEditorInstanceJson);
                if (File.Exists(pathToEditorInstanceJson))
                {
                    var jObject = JObject.Parse(File.ReadAllText(pathToEditorInstanceJson.TrimStart('/')));
                    id = jObject["process_id"].ToObject <int>();
                }
                else
                {
                    var player = FindProcess(name);
                    if (player == null)
                    {
                        return;
                    }

                    name = player.Name;
                    id   = player.Id;
                }
            }
            else
            {
                var player = FindProcess(name);
                if (player == null)
                {
                    return;
                }

                name = player.Name;
                id   = player.Id;
            }

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(id, ref unityDebugConnector);

            Connect(attachInfo.Address, attachInfo.Port);

            Log.Write($"UnityDebug: Attached to Unity process '{name}' ({id})");
            SendOutput("stdout", "UnityDebug: Attached to Unity process '" + name + "' (" + id + ")\n");
            SendResponse(response);
        }
        public static IEnumerable <UnityProcessInfo> GetAttachableProcesses(string targetName)
        {
            string processName;

            if (!targetNameToProcessName.TryGetValue(targetName.ToLower(), out processName))
            {
                return(null);
            }

            var processes = UnityProcessDiscovery.GetAttachableProcesses();

            processes.ForEach(p => Log.Write("Found Unity process: " + p.Name + " (" + p.Id + ")"));

            return(processes.Where(p => p.Name.Contains(processName)));
        }
        public override void Attach(Response response, dynamic args)
        {
            string name = getString(args, "name");

            SendOutput("stdout", "UnityDebug: Searching for Unity process '" + name + "'");

            var processes = UnityAttach.GetAttachableProcesses(name).ToArray();

            if (processes == null)
            {
                SendErrorResponse(response, 8001, "Unknown target name '{_name}'. Did you mean 'Unity Editor'?", new { _name = name });
                return;
            }

            if (processes.Length == 0)
            {
                SendErrorResponse(response, 8001, "Could not find target name '{_name}'. Is it running?", new { _name = name });
                return;
            }

            if (processes.Length > 1)
            {
                SendErrorResponse(response, 8002, "Multiple targets with name '{_name}' running. Unable to connect.", new { _name = name });

                SendOutput("stdout", "UnityDebug: Multiple targets with name '" + name + "' running. Unable to connect");

                foreach (var p in processes)
                {
                    SendOutput("stdout", "UnityDebug: Found Unity process '" + p.Name + "' (" + p.Id + ")\n");
                }

                return;
            }

            var process = processes [0];

            var attachInfo = UnityProcessDiscovery.GetUnityAttachInfo(process.Id, ref unityDebugConnector);

            Debugger.Connect(attachInfo.Address, attachInfo.Port);

            SendOutput("stdout", "UnityDebug: Attached to Unity process '" + process.Name + "' (" + process.Id + ")\n");
            SendResponse(response);
        }
        public static IEnumerable <UnityProcessInfo> GetAttachableProcesses(string targetName)
        {
            var match     = Regex.Match(targetName, "\\(([0-9]+)\\)");
            var processId = -1;

            if (match.Success)
            {
                processId  = Convert.ToInt32(match.Groups[1].Value);
                targetName = targetName.Substring(0, targetName.IndexOf("(") - 1);
            }

            UnityProcessDiscovery.GetProcessOptions options = UnityProcessDiscovery.GetProcessOptions.All;

            if (!targetNameToProcessName.TryGetValue(targetName.ToLower(), out var processName))
            {
                processName = targetName;
            }
            else
            {
                options = processName == "Unity Editor"
                    ? UnityProcessDiscovery.GetProcessOptions.Editor
                    : UnityProcessDiscovery.GetProcessOptions.Players;
            }

            Log.Write($"Trying to find all {options}");
            var processes = UnityProcessDiscovery.GetAttachableProcesses(options);

            processes.ForEach(p => Log.Write("Found Unity process: " + p.Name + " (" + p.Id + ")"));

            var resProcesses = processId == -1
                ? processes.Where(p => p.Name.Contains(processName)).ToArray()
                : processes.Where(p => p.Name.Contains(processName) && p.Id == processId).ToArray();

            if (resProcesses.Length == 0)
            {
                Log.Write($"Could not find the correct process name: {targetName}");
                Log.Write("These are the one that could be found: ");
                processes = UnityProcessDiscovery.GetAttachableProcesses();
                processes.ForEach(process => Log.Write($"{process.Name} : {process.Id}"));
            }

            return(resProcesses);
        }
示例#11
0
        static string GetUnityProcesses()
        {
            var processes = UnityProcessDiscovery.GetAttachableProcesses();

            return(string.Join("\n", processes.Select(x => $"{x.Name} ({x.Id})" + $" {x.ProjectName}")));
        }
示例#12
0
        public static async Task <string> GetUnityProcesses()
        {
            var processes = await UnityProcessDiscovery.GetAttachableProcesses();

            return(string.Join("\n", processes.Select(x => x.Name + $" ({x.Id})")));
        }