UniRx 에셋 추가
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Diagnostics
|
||||
{
|
||||
public struct LogEntry
|
||||
{
|
||||
// requires
|
||||
public string LoggerName { get; private set; }
|
||||
public LogType LogType { get; private set; }
|
||||
public string Message { get; private set; }
|
||||
public DateTime Timestamp { get; private set; }
|
||||
|
||||
// options
|
||||
|
||||
/// <summary>[Optional]</summary>
|
||||
public UnityEngine.Object Context { get; private set; }
|
||||
/// <summary>[Optional]</summary>
|
||||
public Exception Exception { get; private set; }
|
||||
/// <summary>[Optional]</summary>
|
||||
public string StackTrace { get; private set; }
|
||||
/// <summary>[Optional]</summary>
|
||||
public object State { get; private set; }
|
||||
|
||||
public LogEntry(string loggerName, LogType logType, DateTime timestamp, string message, UnityEngine.Object context = null, Exception exception = null, string stackTrace = null, object state = null)
|
||||
: this()
|
||||
{
|
||||
this.LoggerName = loggerName;
|
||||
this.LogType = logType;
|
||||
this.Timestamp = timestamp;
|
||||
this.Message = message;
|
||||
this.Context = context;
|
||||
this.Exception = exception;
|
||||
this.StackTrace = stackTrace;
|
||||
this.State = state;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var plusEx = (Exception != null) ? (Environment.NewLine + Exception.ToString()) : "";
|
||||
return "[" + Timestamp.ToString() + "]"
|
||||
+ "[" + LoggerName + "]"
|
||||
+ "[" + LogType.ToString() + "]"
|
||||
+ Message
|
||||
+ plusEx;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53917e87e91c0e4449402e5d85a04765
|
||||
timeCreated: 1455373899
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UniRx.Diagnostics
|
||||
{
|
||||
public static partial class LogEntryExtensions
|
||||
{
|
||||
public static IDisposable LogToUnityDebug(this IObservable<LogEntry> source)
|
||||
{
|
||||
return source.Subscribe(new UnityDebugSink());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8706ef5a13e53ec46b4848a7eec5e826
|
||||
timeCreated: 1455373900
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Diagnostics
|
||||
{
|
||||
public partial class Logger
|
||||
{
|
||||
static bool isInitialized = false;
|
||||
static bool isDebugBuild = false;
|
||||
|
||||
public string Name { get; private set; }
|
||||
protected readonly Action<LogEntry> logPublisher;
|
||||
|
||||
public Logger(string loggerName)
|
||||
{
|
||||
this.Name = loggerName;
|
||||
this.logPublisher = ObservableLogger.RegisterLogger(this);
|
||||
}
|
||||
|
||||
/// <summary>Output LogType.Log but only enables isDebugBuild</summary>
|
||||
public virtual void Debug(object message, UnityEngine.Object context = null)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
isDebugBuild = UnityEngine.Debug.isDebugBuild;
|
||||
}
|
||||
|
||||
if (isDebugBuild)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (message != null) ? message.ToString() : "",
|
||||
logType: LogType.Log,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: context));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Output LogType.Log but only enables isDebugBuild</summary>
|
||||
public virtual void DebugFormat(string format, params object[] args)
|
||||
{
|
||||
if (!isInitialized)
|
||||
{
|
||||
isInitialized = true;
|
||||
isDebugBuild = UnityEngine.Debug.isDebugBuild;
|
||||
}
|
||||
|
||||
if (isDebugBuild)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (format != null) ? string.Format(format, args) : "",
|
||||
logType: LogType.Log,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: null));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Log(object message, UnityEngine.Object context = null)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (message != null) ? message.ToString() : "",
|
||||
logType: LogType.Log,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: context));
|
||||
}
|
||||
|
||||
public virtual void LogFormat(string format, params object[] args)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (format != null) ? string.Format(format, args) : "",
|
||||
logType: LogType.Log,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: null));
|
||||
}
|
||||
|
||||
public virtual void Warning(object message, UnityEngine.Object context = null)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (message != null) ? message.ToString() : "",
|
||||
logType: LogType.Warning,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: context));
|
||||
}
|
||||
|
||||
public virtual void WarningFormat(string format, params object[] args)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (format != null) ? string.Format(format, args) : "",
|
||||
logType: LogType.Warning,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: null));
|
||||
}
|
||||
|
||||
public virtual void Error(object message, UnityEngine.Object context = null)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (message != null) ? message.ToString() : "",
|
||||
logType: LogType.Error,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: context));
|
||||
}
|
||||
|
||||
public virtual void ErrorFormat(string format, params object[] args)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (format != null) ? string.Format(format, args) : "",
|
||||
logType: LogType.Error,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: null));
|
||||
}
|
||||
|
||||
public virtual void Exception(Exception exception, UnityEngine.Object context = null)
|
||||
{
|
||||
logPublisher(new LogEntry(
|
||||
message: (exception != null) ? exception.ToString() : "",
|
||||
exception: exception,
|
||||
logType: LogType.Exception,
|
||||
timestamp: DateTime.Now,
|
||||
loggerName: Name,
|
||||
context: context));
|
||||
}
|
||||
|
||||
/// <summary>Publish raw LogEntry.</summary>
|
||||
public virtual void Raw(LogEntry logEntry)
|
||||
{
|
||||
logPublisher(logEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0ecf366503cb0644bdd90934d24da62
|
||||
timeCreated: 1455373902
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace UniRx.Diagnostics
|
||||
{
|
||||
public static class ObservableDebugExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Debug helper of observbale stream. Works for only DEBUG symbol.
|
||||
/// </summary>
|
||||
public static IObservable<T> Debug<T>(this IObservable<T> source, string label = null)
|
||||
{
|
||||
#if DEBUG
|
||||
var l = (label == null) ? "" : "[" + label + "]";
|
||||
return source.Materialize()
|
||||
.Do(x => UnityEngine.Debug.Log(l + x.ToString()))
|
||||
.Dematerialize()
|
||||
.DoOnCancel(() => UnityEngine.Debug.Log(l + "OnCancel"))
|
||||
.DoOnSubscribe(() => UnityEngine.Debug.Log(l + "OnSubscribe"));
|
||||
|
||||
#else
|
||||
return source;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Debug helper of observbale stream. Works for only DEBUG symbol.
|
||||
/// </summary>
|
||||
public static IObservable<T> Debug<T>(this IObservable<T> source, UniRx.Diagnostics.Logger logger)
|
||||
{
|
||||
#if DEBUG
|
||||
return source.Materialize()
|
||||
.Do(x => logger.Debug(x.ToString()))
|
||||
.Dematerialize()
|
||||
.DoOnCancel(() => logger.Debug("OnCancel"))
|
||||
.DoOnSubscribe(() => logger.Debug("OnSubscribe"));
|
||||
|
||||
#else
|
||||
return source;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b43f948e095c3e749a0506709be90d68
|
||||
timeCreated: 1468662620
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Diagnostics
|
||||
{
|
||||
public class ObservableLogger : IObservable<LogEntry>
|
||||
{
|
||||
static readonly Subject<LogEntry> logPublisher = new Subject<LogEntry>();
|
||||
|
||||
public static readonly ObservableLogger Listener = new ObservableLogger();
|
||||
|
||||
private ObservableLogger()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static Action<LogEntry> RegisterLogger(Logger logger)
|
||||
{
|
||||
if (logger.Name == null) throw new ArgumentNullException("logger.Name is null");
|
||||
|
||||
return logPublisher.OnNext;
|
||||
}
|
||||
|
||||
public IDisposable Subscribe(IObserver<LogEntry> observer)
|
||||
{
|
||||
return logPublisher.Subscribe(observer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 063f79dc45f902c459f0955d27b445d7
|
||||
timeCreated: 1455373897
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniRx.Diagnostics
|
||||
{
|
||||
public class UnityDebugSink : IObserver<LogEntry>
|
||||
{
|
||||
public void OnCompleted()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public void OnError(Exception error)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public void OnNext(LogEntry value)
|
||||
{
|
||||
// avoid multithread exception.
|
||||
// (value.Context == null) can only be called from the main thread.
|
||||
var ctx = (System.Object)value.Context;
|
||||
|
||||
switch (value.LogType)
|
||||
{
|
||||
case LogType.Error:
|
||||
if (ctx == null)
|
||||
{
|
||||
Debug.LogError(value.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError(value.Message, value.Context);
|
||||
}
|
||||
break;
|
||||
case LogType.Exception:
|
||||
if (ctx == null)
|
||||
{
|
||||
Debug.LogException(value.Exception);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogException(value.Exception, value.Context);
|
||||
}
|
||||
break;
|
||||
case LogType.Log:
|
||||
if (ctx == null)
|
||||
{
|
||||
Debug.Log(value.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log(value.Message, value.Context);
|
||||
}
|
||||
break;
|
||||
case LogType.Warning:
|
||||
if (ctx == null)
|
||||
{
|
||||
Debug.LogWarning(value.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(value.Message, value.Context);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 882166c30c3bff841b1e12d62c392e02
|
||||
timeCreated: 1455373900
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user