RemotePlayerLogController.cs
2.62 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
using System;
using System.Collections.Generic;
using UnityEditor.DeploymentTargets;
using UnityEditor.TestTools.TestRunner.CommandLineTest;
using UnityEngine;
namespace UnityEditor.TestRunner.TestLaunchers
{
[Serializable]
internal class RemotePlayerLogController : ScriptableSingleton<RemotePlayerLogController>
{
private List<LogWriter> m_LogWriters;
private Dictionary<string, DeploymentTargetLogger> m_Loggers;
private string m_DeviceLogsDirectory;
public void SetBuildTarget(BuildTarget buildTarget)
{
m_Loggers = GetDeploymentTargetLoggers(buildTarget);
if (m_Loggers == null)
Debug.Log("Deployment target logger could not be created");
}
public void SetLogsDirectory(string dir)
{
m_DeviceLogsDirectory = dir;
}
public void StartLogWriters()
{
if (m_DeviceLogsDirectory == null || m_Loggers == null)
return;
m_LogWriters = new List<LogWriter>();
foreach (var logger in m_Loggers)
{
m_LogWriters.Add(new LogWriter(m_DeviceLogsDirectory, logger.Key, logger.Value));
logger.Value.Start();
}
}
public void StopLogWriters()
{
if (m_LogWriters == null)
return;
foreach (var logWriter in m_LogWriters)
{
logWriter.Stop();
}
}
private Dictionary<string, DeploymentTargetLogger> GetDeploymentTargetLoggers(BuildTarget buildTarget)
{
DeploymentTargetManager deploymentTargetManager;
try
{
deploymentTargetManager = DeploymentTargetManager.CreateInstance(EditorUserBuildSettings.activeBuildTargetGroup, buildTarget);
if (deploymentTargetManager == null)
return null;
}
catch (NotSupportedException ex)
{
Debug.Log(ex.Message);
Debug.Log("Deployment target logger not initialised");
return null;
}
var targets = deploymentTargetManager.GetKnownTargets();
var loggers = new Dictionary<string, DeploymentTargetLogger>();
foreach (var target in targets)
{
if (target.status != DeploymentTargetStatus.Ready) continue;
var logger = deploymentTargetManager.GetTargetLogger(target.id);
logger.Clear();
loggers.Add(target.id, logger);
}
return loggers;
}
}
}