diff --git a/Assets/Toolkit/Toolkit/Scripts.meta b/Assets/Toolkit/Toolkit/Runtime.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts.meta
rename to Assets/Toolkit/Toolkit/Runtime.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/AotHelper.cs b/Assets/Toolkit/Toolkit/Runtime/AotHelper.cs
similarity index 60%
rename from Assets/Toolkit/Toolkit/Scripts/AotHelper.cs
rename to Assets/Toolkit/Toolkit/Runtime/AotHelper.cs
index 7c64045..c350e77 100644
--- a/Assets/Toolkit/Toolkit/Scripts/AotHelper.cs
+++ b/Assets/Toolkit/Toolkit/Runtime/AotHelper.cs
@@ -1,18 +1,19 @@
using System;
+using System.Reflection;
namespace Ca2d.Toolkit
{
public static class AotHelper
{
- private static DateTime alwayasFalseSource = DateTime.UtcNow;
+ private static readonly DateTime AlwaysFalseSource = DateTime.UtcNow;
///
/// Utility to provide a must be false option for Ahead-of-time compiler.
///
/// False
- public static bool AlwaysFalseProvider()
+ public static bool False()
{
- return alwayasFalseSource.Year < 0;
+ return AlwaysFalseSource.Year < 0;
}
///
@@ -20,7 +21,12 @@ namespace Ca2d.Toolkit
///
public static void Ensure(Action call)
{
- if (AlwaysFalseProvider()) call?.Invoke();
+ if (False()) call?.Invoke();
+ }
+
+ public static void Ensure()
+ {
+ if (False()) typeof(T).GetTypeInfo();
}
}
}
\ No newline at end of file
diff --git a/Assets/Toolkit/Toolkit/Scripts/AotHelper.cs.meta b/Assets/Toolkit/Toolkit/Runtime/AotHelper.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/AotHelper.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/AotHelper.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/AsDisposable.cs b/Assets/Toolkit/Toolkit/Runtime/AsDisposable.cs
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/AsDisposable.cs
rename to Assets/Toolkit/Toolkit/Runtime/AsDisposable.cs
diff --git a/Assets/Toolkit/Toolkit/Scripts/AsDisposable.cs.meta b/Assets/Toolkit/Toolkit/Runtime/AsDisposable.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/AsDisposable.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/AsDisposable.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/Boxing.cs b/Assets/Toolkit/Toolkit/Runtime/Boxing.cs
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/Boxing.cs
rename to Assets/Toolkit/Toolkit/Runtime/Boxing.cs
diff --git a/Assets/Toolkit/Toolkit/Scripts/Boxing.cs.meta b/Assets/Toolkit/Toolkit/Runtime/Boxing.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/Boxing.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/Boxing.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Ca2d.Toolkit.asmdef b/Assets/Toolkit/Toolkit/Runtime/Ca2d.Toolkit.asmdef
similarity index 100%
rename from Assets/Toolkit/Toolkit/Ca2d.Toolkit.asmdef
rename to Assets/Toolkit/Toolkit/Runtime/Ca2d.Toolkit.asmdef
diff --git a/Assets/Toolkit/Toolkit/Ca2d.Toolkit.asmdef.meta b/Assets/Toolkit/Toolkit/Runtime/Ca2d.Toolkit.asmdef.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Ca2d.Toolkit.asmdef.meta
rename to Assets/Toolkit/Toolkit/Runtime/Ca2d.Toolkit.asmdef.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/Guard.cs b/Assets/Toolkit/Toolkit/Runtime/Guard.cs
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/Guard.cs
rename to Assets/Toolkit/Toolkit/Runtime/Guard.cs
diff --git a/Assets/Toolkit/Toolkit/Scripts/Guard.cs.meta b/Assets/Toolkit/Toolkit/Runtime/Guard.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/Guard.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/Guard.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/LoseRequirementException.cs b/Assets/Toolkit/Toolkit/Runtime/LoseRequirementException.cs
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/LoseRequirementException.cs
rename to Assets/Toolkit/Toolkit/Runtime/LoseRequirementException.cs
diff --git a/Assets/Toolkit/Toolkit/Scripts/LoseRequirementException.cs.meta b/Assets/Toolkit/Toolkit/Runtime/LoseRequirementException.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/LoseRequirementException.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/LoseRequirementException.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/Option.cs b/Assets/Toolkit/Toolkit/Runtime/Option.cs
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/Option.cs
rename to Assets/Toolkit/Toolkit/Runtime/Option.cs
diff --git a/Assets/Toolkit/Toolkit/Scripts/Option.cs.meta b/Assets/Toolkit/Toolkit/Runtime/Option.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/Option.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/Option.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/ResLock.cs b/Assets/Toolkit/Toolkit/Runtime/ResLock.cs
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/ResLock.cs
rename to Assets/Toolkit/Toolkit/Runtime/ResLock.cs
diff --git a/Assets/Toolkit/Toolkit/Scripts/ResLock.cs.meta b/Assets/Toolkit/Toolkit/Runtime/ResLock.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/ResLock.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/ResLock.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/StringBuilderPool.cs b/Assets/Toolkit/Toolkit/Runtime/StringBuilderPool.cs
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/StringBuilderPool.cs
rename to Assets/Toolkit/Toolkit/Runtime/StringBuilderPool.cs
diff --git a/Assets/Toolkit/Toolkit/Scripts/StringBuilderPool.cs.meta b/Assets/Toolkit/Toolkit/Runtime/StringBuilderPool.cs.meta
similarity index 100%
rename from Assets/Toolkit/Toolkit/Scripts/StringBuilderPool.cs.meta
rename to Assets/Toolkit/Toolkit/Runtime/StringBuilderPool.cs.meta
diff --git a/Assets/Toolkit/Toolkit/Scripts/ILoggHandler.cs b/Assets/Toolkit/Toolkit/Scripts/ILoggHandler.cs
deleted file mode 100644
index 51ae23d..0000000
--- a/Assets/Toolkit/Toolkit/Scripts/ILoggHandler.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-#if ENABLE_LOGG
-using UnityEngine;
-
-namespace Ca2d.Toolkit
-{
- public enum LoggType
- {
- ///
- /// LogType used for Errors.
- ///
- Error,
- ///
- /// LogType used for Asserts. (These could also indicate an error inside Unity itself.)
- ///
- Assert,
- ///
- /// LogType used for Warnings.
- ///
- Warning,
- ///
- /// LogType used for regular log messages.
- ///
- Log,
- ///
- /// LogType used for Exceptions.
- ///
- Exception,
- ///
- /// LogType used for Developers on testing.
- ///
- Debug
- }
-
- public interface ILoggHandler : ILogHandler
- {
- public ILogHandler InnerLogHandler { get; }
-
- public void LoggFormat(LoggType logType, Object context, string format, params object[] args);
-
- public void SetLabel(string label);
-
- public void ClearLabel();
- }
-}
-#endif
\ No newline at end of file
diff --git a/Assets/Toolkit/Toolkit/Scripts/ILoggHandler.cs.meta b/Assets/Toolkit/Toolkit/Scripts/ILoggHandler.cs.meta
deleted file mode 100644
index a957eab..0000000
--- a/Assets/Toolkit/Toolkit/Scripts/ILoggHandler.cs.meta
+++ /dev/null
@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: bfec301646cc46339921f4c1c9170412
-timeCreated: 1715271270
\ No newline at end of file
diff --git a/Assets/Toolkit/Toolkit/Scripts/Logg.cs b/Assets/Toolkit/Toolkit/Scripts/Logg.cs
deleted file mode 100644
index 9d53772..0000000
--- a/Assets/Toolkit/Toolkit/Scripts/Logg.cs
+++ /dev/null
@@ -1,284 +0,0 @@
-#if ENABLE_LOGG
-using System;
-using System.Diagnostics;
-using System.Text;
-using UnityEditor;
-using UnityEngine;
-using Object = UnityEngine.Object;
-
-namespace Ca2d.Toolkit
-{
- ///
- /// Alternatives to the default Unity Logger.
- ///
- public struct Logg
- {
- #region BackendConfig
-
- // ReSharper disable once MemberCanBePrivate.Global
- public const string kDefaultLoggerLevelSplit = "::";
-
- private static ILoggHandler _backend;
-
- ///
- /// Which backend will be used for logger?
- ///
- public static ILoggHandler Backend
- {
- get => _backend;
- set => _backend = value ?? throw new NullReferenceException();
- }
-
- ///
- /// Logger level name spliter sign.
- ///
- public static string LoggerLevelSplit { get; set; } = kDefaultLoggerLevelSplit;
-
- #endregion
-
- #region Constructor
-
- private static readonly StringBuilder kStringBuilder = new();
-
- private readonly bool m_useLabel;
-
- private readonly string m_label;
-
- ///
- /// Create a logger with first-level namespace
- ///
- /// Namespace
- public Logg(string ns)
- {
- if (string.IsNullOrWhiteSpace(ns))
- {
- m_useLabel = false;
- m_label = null;
- }
- else
- {
- m_useLabel = true;
- m_label = ns.Trim();
- }
- }
-
- ///
- /// Create a copy of source logger.
- ///
- /// Source logger.
- public Logg(Logg source)
- {
- if (source.m_useLabel)
- {
- m_useLabel = true;
- m_label = source.m_label;
- }
- else
- {
- m_useLabel = false;
- m_label = null;
- }
- }
-
- ///
- /// Create a nested logger with given namespace.
- ///
- /// Nest source.
- /// Namespace
- public Logg(Logg source, string ns)
- {
- if (string.IsNullOrWhiteSpace(ns))
- {
- if (source.m_useLabel)
- {
- m_useLabel = true;
- m_label = source.m_label;
- }
- else
- {
- m_useLabel = false;
- m_label = null;
- }
- }
- else
- {
- m_useLabel = true;
- if (source.m_useLabel)
- {
- kStringBuilder.Clear();
- m_label = kStringBuilder.AppendJoin(LoggerLevelSplit, source.m_label, ns.Trim()).ToString();
- }
- else
- {
- m_label = ns.Trim();
- }
- }
-
- }
-
- #endregion
-
- #region EnvOverrider
-
- private static bool _init = false;
-
-#if UNITY_EDITOR
- [InitializeOnLoadMethod]
- private static void LoggInitEditor()
- {
- LoggInit();
- }
-#else
- [RuntimeInitializeOnLoadMethod]
- private static void RuntimeLoggInit()
- {
- LoggInit();
- }
-#endif
-
- private static void LoggInit()
- {
- if (!_init)
- {
- var prevLogHandler = UnityEngine.Debug.unityLogger.logHandler;
-
- if (prevLogHandler is ILoggHandler)
- {
- prevLogHandler.LogFormat(
- LogType.Warning,
- null,
- "Logg seems to be inited before initialize?");
- }
- else
- {
- var l = new LoggHandler(prevLogHandler);
- _backend = l;
- UnityEngine.Debug.unityLogger.logHandler = l;
- prevLogHandler.LogFormat(LogType.Log, null, "##### Debug.unityLogger was taken over by Logg #####");
- }
-
- _init = true;
- }
- }
-
- #endregion
-
- #region LogMethods
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void Format(LoggType type, Object context, string format, params object[] args)
- {
- if (_backend != null)
- {
- if (m_useLabel) _backend.SetLabel(m_label);
- _backend.LoggFormat(type, context, format, args);
- _backend.ClearLabel();
- }
- else
- {
- // Use fallback logger if Logg is not ready.
- UnityEngine.Debug.LogFormat((LogType) type, LogOption.NoStacktrace, context, format, args);
- }
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void Debug(string content, Object context = null)
- {
- Format(LoggType.Debug, context, content);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void Info(string content, Object context = null)
- {
- Format(LoggType.Log, context, content);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void Warning(string content, Object context = null)
- {
- Format(LoggType.Warning, context, content);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void Error(string content, Object context = null)
- {
- Format(LoggType.Error, context, content);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void Error(Exception err, Object context = null)
- {
- Format(LoggType.Exception, context, err.ToString());
- }
-
- #endregion
-
- }
-
- ///
- /// Quick log API for .
- ///
- public static class DebugLogg
- {
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static void Format(LoggType type, Object context, string format, params object[] args)
- {
- default(Logg).Format(type, context, format, args);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static void Debug(string content, Object context = null)
- {
- default(Logg).Debug(content, context);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static void Info(string content, Object context = null)
- {
- default(Logg).Info(content, context);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static void Warning(string content, Object context = null)
- {
- default(Logg).Warning(content, context);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static void Error(string content, Object context = null)
- {
- default(Logg).Error(content, context);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public static void Error(Exception err, Object context = null)
- {
- default(Logg).Error(err, context);
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/Assets/Toolkit/Toolkit/Scripts/Logg.cs.meta b/Assets/Toolkit/Toolkit/Scripts/Logg.cs.meta
deleted file mode 100644
index 7bb2ef8..0000000
--- a/Assets/Toolkit/Toolkit/Scripts/Logg.cs.meta
+++ /dev/null
@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: 59eb97c7769441599ea2569c2f5402b8
-timeCreated: 1715264700
\ No newline at end of file
diff --git a/Assets/Toolkit/Toolkit/Scripts/LoggHandler.cs b/Assets/Toolkit/Toolkit/Scripts/LoggHandler.cs
deleted file mode 100644
index f9aa1b9..0000000
--- a/Assets/Toolkit/Toolkit/Scripts/LoggHandler.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-#if ENABLE_LOGG
-using System;
-using System.Diagnostics;
-using System.Text;
-using UnityEngine;
-using Object = UnityEngine.Object;
-
-namespace Ca2d.Toolkit
-{
- public class LoggHandler : ILoggHandler
- {
- private readonly ILogHandler m_innerHandle;
-
- private readonly StringBuilder m_sb = new();
-
- private bool m_useLabel = false;
-
- private string m_labelText = default;
-
- #region PassThrough
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void LogFormat(LogType logType, Object context, string format, params object[] args)
- {
- LoggFormat((LoggType) logType, context, format, args);
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void LogException(Exception exception, Object context)
- {
- LoggFormat(LoggType.Exception, context, exception.ToString());
- }
-
- #endregion
-
- private void GenerateLabel(StringBuilder sb, LoggType type)
- {
- var logTypeText = type switch
- {
- LoggType.Assert => "ASSERT",
- LoggType.Exception => "EXCEPTION",
- LoggType.Error => "Error",
- LoggType.Warning => "Warning",
- LoggType.Log => "Info",
- _ => "Debug"
- };
-
- if (m_useLabel)
- {
- sb.AppendFormat("[{0:yyyy-M-d HH:mm:ss}] {1} ({2}) : ", DateTime.Now, logTypeText, m_labelText);
- }
- else
- {
- sb.AppendFormat("[{0:yyyy-M-d HH:mm:ss}] {1} : ", DateTime.Now, logTypeText);
- }
- }
-
- [HideInCallstack]
- [DebuggerHidden]
- [DebuggerStepThrough]
- public void LoggFormat(LoggType logType, Object context, string format, params object[] args)
- {
- m_sb.Clear();
-
- // Write label to the front
- GenerateLabel(m_sb, logType);
-
- // Write format text after front
- m_sb.AppendFormat(format, args);
-
- // Redirect Debug to Log.
- LogType finalType;
- if (logType == LoggType.Debug) finalType = LogType.Log;
- else finalType = (LogType) logType;
-
- // Use inner handle to write.
- m_innerHandle.LogFormat(finalType, context, m_sb.ToString());
- }
-
- public ILogHandler InnerLogHandler => m_innerHandle;
-
- public void SetLabel(string label)
- {
- m_labelText = label;
- m_useLabel = label != null;
- }
-
- public void ClearLabel()
- {
- m_labelText = null;
- m_useLabel = false;
- }
-
- public LoggHandler(ILogHandler innerHandle)
- {
- m_innerHandle = innerHandle ?? throw new ArgumentNullException(nameof(innerHandle));
- }
- }
-}
-#endif
\ No newline at end of file
diff --git a/Assets/Toolkit/Toolkit/Scripts/LoggHandler.cs.meta b/Assets/Toolkit/Toolkit/Scripts/LoggHandler.cs.meta
deleted file mode 100644
index 191f5fc..0000000
--- a/Assets/Toolkit/Toolkit/Scripts/LoggHandler.cs.meta
+++ /dev/null
@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: f543cfba5cf04258b3ab59b75849e7a9
-timeCreated: 1715271314
\ No newline at end of file
diff --git a/Assets/Toolkit/package.json b/Assets/Toolkit/package.json
index 8a8f22d..8c5d051 100644
--- a/Assets/Toolkit/package.json
+++ b/Assets/Toolkit/package.json
@@ -1,6 +1,6 @@
{
"name": "xyz.ca2didi.unity.toolkit",
- "version": "0.1.1",
+ "version": "0.1.2",
"displayName": "Ca2D Toolkit",
"description": "Set of toolkits which can boost your develop experience and speed in Unity.",
"unity": "2021.3",
diff --git a/Ca2d.Toolkit.csproj.DotSettings b/Ca2d.Toolkit.csproj.DotSettings
index 6e6c12c..017fb9e 100644
--- a/Ca2d.Toolkit.csproj.DotSettings
+++ b/Ca2d.Toolkit.csproj.DotSettings
@@ -5,6 +5,7 @@
True
True
True
+ True
True
True
True
\ No newline at end of file