-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathUnityLogWriter.cs
More file actions
43 lines (38 loc) · 1.32 KB
/
UnityLogWriter.cs
File metadata and controls
43 lines (38 loc) · 1.32 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
using ChainSafe.Gaming.Unity;
using ChainSafe.Gaming.Web3.Environment;
using UnityEngine;
namespace ChainSafe.Gaming.Web3.Unity
{
/// <summary>
/// This class is used so that all logs are written to Unity so that user can see the outputs of Console.WriteLine
/// inside the Unity Editor.
/// </summary>
public class UnityLogWriter : ILogWriter
{
private readonly IMainThreadRunner mainThreadRunner;
public UnityLogWriter(IMainThreadRunner mainThreadRunner)
{
this.mainThreadRunner = mainThreadRunner;
}
/// <summary>
/// Logs the message to Unity's console as a regular Debug Log message.
/// </summary>
/// <param name="message">message to show.</param>
public void Log(string message)
{
mainThreadRunner.Enqueue(() => Debug.Log(FormatMessage(message)));
}
/// <summary>
/// Logs the message to Unity's console as a Debug.LogError message.
/// </summary>
/// <param name="message">message to show.</param>
public void LogError(string message)
{
mainThreadRunner.Enqueue(() => Debug.LogError(FormatMessage(message)));
}
private static string FormatMessage(string message)
{
return $"[Web3] {message}";
}
}
}