first commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
namespace SingularityGroup.HotReload {
|
||||
/// <summary>
|
||||
/// Utility class to set the log level of the Hot Reload package
|
||||
/// </summary>
|
||||
public static class HotReloadLogging {
|
||||
/// <summary>
|
||||
/// Sets the log level for logs inside the Hot Reload package
|
||||
/// The default log level is <see cref="LogLevel.Info"/>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To see more detailed logs, set the log level to <see cref="LogLevel.Debug"/>
|
||||
/// </remarks>
|
||||
public static void SetLogLevel(LogLevel level) {
|
||||
Log.minLevel = level;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48845e010a33e2d4993888d9c18e8d95
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace SingularityGroup.HotReload {
|
||||
/// <summary>
|
||||
/// Methods with this attribute will get invoked after a hot reload
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The method with this attribute needs to have no parameters.
|
||||
/// Further more it needs to either be static or and instance method inside a <see cref="UnityEngine.MonoBehaviour"/>.
|
||||
/// For the latter case the method of all instances of the <see cref="UnityEngine.MonoBehaviour"/> will be called.
|
||||
/// In case the method has a return value it will be ignored.
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class InvokeOnHotReload : Attribute {
|
||||
}
|
||||
|
||||
public class MethodPatch {
|
||||
// Compiled by the Unity Editor. Null for newly added methods.
|
||||
public MethodBase originalMethod;
|
||||
// Method before Hot Reload applied it's patch. Null for newly added methods.
|
||||
public MethodBase previousMethod;
|
||||
// Method generated by Hot Reload.
|
||||
public MethodBase newMethod;
|
||||
|
||||
public MethodPatch(MethodBase originalMethod, MethodBase previousMethod, MethodBase newMethod) {
|
||||
this.originalMethod = originalMethod;
|
||||
this.previousMethod = previousMethod;
|
||||
this.newMethod = newMethod;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de8fb6e6e05ccae46a410932e1545848
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
|
||||
namespace SingularityGroup.HotReload {
|
||||
/// <summary>
|
||||
/// Method with this attribute will get invoked when it gets patched
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The method with this attribute needs to have no parameters.
|
||||
/// Furthermore it needs to either be static or an instance method inside a <see cref="UnityEngine.MonoBehaviour"/>.
|
||||
/// For the latter case the method of all instances of the <see cref="UnityEngine.MonoBehaviour"/> will be called.
|
||||
/// In case the method has a return value it will be ignored.
|
||||
/// </remarks>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class InvokeOnHotReloadLocal : Attribute {
|
||||
public readonly string methodToInvoke;
|
||||
|
||||
public InvokeOnHotReloadLocal(string methodToInvoke = null) {
|
||||
this.methodToInvoke = methodToInvoke;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4629f348dad47d4add28eca71be748c
|
||||
timeCreated: 1694274524
|
||||
108
Packages/com.singularitygroup.hotreload/Runtime/Public/Log.cs
Normal file
108
Packages/com.singularitygroup.hotreload/Runtime/Public/Log.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using JetBrains.Annotations;
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
using UnityEngine;
|
||||
#endif
|
||||
|
||||
namespace SingularityGroup.HotReload {
|
||||
public static class Log {
|
||||
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Global")]
|
||||
public static LogLevel minLevel = LogLevel.Info;
|
||||
|
||||
/// <summary>
|
||||
/// Tag every log so that users know which logs came from Hot Reload
|
||||
/// </summary>
|
||||
private const string TAG = "[HotReload] ";
|
||||
|
||||
public static void Debug(string message) {
|
||||
if (minLevel <= LogLevel.Debug) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
|
||||
#else
|
||||
UnityEngine.Debug.Log(TAG + message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[StringFormatMethod("message")]
|
||||
public static void Debug(string message, params object[] args) {
|
||||
if (minLevel <= LogLevel.Debug) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, TAG + message, args);
|
||||
#else
|
||||
UnityEngine.Debug.LogFormat(TAG + message, args);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static void Info(string message) {
|
||||
if (minLevel <= LogLevel.Info) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
|
||||
#else
|
||||
UnityEngine.Debug.Log(TAG + message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[StringFormatMethod("message")]
|
||||
public static void Info(string message, params object[] args) {
|
||||
if (minLevel <= LogLevel.Info) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Log, LogOption.NoStacktrace, null, TAG + message, args);
|
||||
#else
|
||||
UnityEngine.Debug.LogFormat(TAG + message, args);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static void Warning(string message) {
|
||||
if (minLevel <= LogLevel.Warning) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
|
||||
#else
|
||||
UnityEngine.Debug.LogWarning(TAG + message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[StringFormatMethod("message")]
|
||||
public static void Warning(string message, params object[] args) {
|
||||
if (minLevel <= LogLevel.Warning) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, null, TAG + message, args);
|
||||
#else
|
||||
UnityEngine.Debug.LogWarningFormat(TAG + message, args);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static void Error(string message) {
|
||||
if (minLevel <= LogLevel.Error) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, "{0}{1}", TAG, message);
|
||||
#else
|
||||
UnityEngine.Debug.LogError(TAG + message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[StringFormatMethod("message")]
|
||||
public static void Error(string message, params object[] args) {
|
||||
if (minLevel <= LogLevel.Error) {
|
||||
#if (UNITY_2019_4_OR_NEWER)
|
||||
UnityEngine.Debug.LogFormat(LogType.Error, LogOption.NoStacktrace, null, TAG + message, args);
|
||||
#else
|
||||
UnityEngine.Debug.LogErrorFormat(TAG + message, args);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public static void Exception(Exception exception) {
|
||||
if (minLevel <= LogLevel.Exception) {
|
||||
UnityEngine.Debug.LogException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0719c57eeba24f4cac8d99016ba5b967
|
||||
timeCreated: 1674203567
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SingularityGroup.HotReload {
|
||||
/// <summary>
|
||||
/// The log level enumeration for the Hot Reload package
|
||||
/// Used in <see cref="HotReloadLogging.SetLogLevel"/> to set the log level.
|
||||
/// </summary>
|
||||
public enum LogLevel {
|
||||
/// Debug logs are useful for developers of Hot Reload
|
||||
Debug = 1,
|
||||
|
||||
/// Info logs potentially useful for users of Hot Reload
|
||||
Info = 2,
|
||||
|
||||
/// Warnings are visible to users of Hot Reload
|
||||
Warning = 3,
|
||||
|
||||
/// Errors are visible to users of Hot Reload
|
||||
Error = 4,
|
||||
|
||||
/// Exceptions are visible to users of Hot Reload
|
||||
Exception = 5,
|
||||
|
||||
/// No logs are visible to users of Hot Reload
|
||||
Disabled = 6,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b5723ec3c2140041a9c25bbf16eeac4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "SingularityGroup.HotReload.Runtime.Public"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2be1b7392ef6cc4eafd0ee8ac7a090a
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user