feat: Complete Guard.IgnoreException families.

feat: Add XML documentation to some methods and classes.
remove: Cleanup BootUnit for rewriting.
This commit is contained in:
Ca2didi 2024-05-08 23:48:17 +08:00
parent cffb31c1df
commit 91c24b27e8
22 changed files with 742 additions and 348 deletions

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 682379589b9245c194f6d38b178c8a7b
timeCreated: 1712972381

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 1fdfef18a5d440bb8214c941d439e605
timeCreated: 1712972698

View File

@ -1,11 +0,0 @@
namespace Ca2d.Toolkit.Bootable
{
public struct BootDescription
{
public readonly string Id;
public readonly IBootCondition Condition;
public readonly IBootExecutor[] Executors;
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 6ce9da660f08484f8ccebff2aaf3a825
timeCreated: 1713192001

View File

@ -1,17 +0,0 @@
namespace Ca2d.Toolkit.Bootable
{
public enum BootState
{
Created = 0,
Pending = 1,
Prepare = 2,
Running = 3,
Exit = 4,
Fatal = 5
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: ddd6ed54d6c24afa90dbe41a9cedbe22
timeCreated: 1713193446

View File

@ -1,7 +0,0 @@
namespace Ca2d.Toolkit.Bootable
{
public class IBootCondition
{
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: d711f6a53d984d4ab120859e20193edc
timeCreated: 1713192171

View File

@ -1,14 +0,0 @@
using System;
using Cysharp.Threading.Tasks;
namespace Ca2d.Toolkit.Bootable
{
public interface IBootExecutor
{
public bool FatalAsExit { get; }
public BootState RegisteredStage { get; }
public Func<UniTask<bool>> Runner { get; }
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: e5221434446d45f9904f24ab2f9f4f3d
timeCreated: 1713193262

View File

@ -0,0 +1,75 @@
using System;
using UnityEngine;
using UnityEngine.UIElements;
namespace Ca2d.Toolkit
{
/// <summary>
/// An utility which gives a type safe boxing.
/// </summary>
/// <typeparam name="T">The value type which will being boxing.</typeparam>
[Serializable]
public class Boxing<T> where T : struct
{
[SerializeField] private T m_value;
/// <summary>
/// Create a copy of given boxing source.
/// </summary>
public Boxing(Boxing<T> source)
{
m_value = source.Unbox;
}
/// <summary>
/// Create a copy of given value.
/// </summary>
public Boxing(T value)
{
m_value = value;
}
/// <summary>
/// Create a empty boxing.
/// </summary>
public Boxing()
{}
/// <summary>
/// Get a copy of boxing value.
/// </summary>
public T Unbox
{
get => m_value;
set => m_value = value;
}
/// <summary>
/// Access to the boxing value directly.
/// </summary>
public ref T Direct => ref m_value;
/// <summary>
/// Clean this boxing container to the default value of boxing target.
/// </summary>
public void Empty()
{
m_value = default;
}
public override string ToString()
{
return m_value.ToString();
}
public static implicit operator T(Boxing<T> wrapper)
{
return wrapper.Unbox;
}
public static implicit operator Boxing<T>(T value)
{
return new Boxing<T>(value);
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 4f6e1e1705424ac39408a10837b49e52
timeCreated: 1713285459

View File

@ -9,30 +9,47 @@ namespace Ca2d.Toolkit
{
/* IgnoreException Utils */
private static void IgnoreNoTarget()
{
Debug.LogError("Ignore Exception should run with executor!");
}
#region IgnoreException(Action)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
public static void IgnoreException(Action exec)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
exec.Invoke();
}
catch (Exception e)
{ Debug.LogError(e); }
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
public static T IgnoreException<T>(Func<T> exec)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return exec.Invoke();
}
catch (Exception e)
@ -41,88 +58,42 @@ namespace Ca2d.Toolkit
return default(T);
}
public static async UniTask IgnoreException(Func<UniTask> exec)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
public static async UniTask IgnoreExceptionAsync(Func<UniTask> exec)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke();
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static async UniTask<T> IgnoreException<T>(Func<UniTask<T>> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke();
}
catch (Exception e)
{ Debug.LogError(e); }
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
public static async UniTask<T> IgnoreExceptionAsync<T>(Func<UniTask<T>> exec)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
public static async Task IgnoreException(Func<Task> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke();
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static async Task<T> IgnoreException<T>(Func<Task<T>> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke();
}
catch (Exception e)
{ Debug.LogError(e); }
return default(T);
}
public static async ValueTask IgnoreException(Func<ValueTask> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke();
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static async ValueTask<T> IgnoreException<T>(Func<ValueTask<T>> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke();
}
catch (Exception e)
@ -133,30 +104,45 @@ namespace Ca2d.Toolkit
#endregion
#region IgnoreException(this Source, Action<Source::Type>)
#region IgnoreException(this Source, Action<Source>)
public static void IgnoreException<TSource>(TSource source, Action<TSource> exec)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="source">The source of this operation</param>
/// <param name="exec">Executor of source executor</param>
public static void IgnoreException<TSource>(this TSource source, Action<TSource> exec)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
exec.Invoke(source);
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static T IgnoreException<TSource, T>(TSource source, Func<TSource, T> exec)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="source">The source of this operation</param>
/// <param name="exec">Executor of source executor</param>
public static T IgnoreException<TSource, T>(this TSource source, Func<TSource, T> exec)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return exec.Invoke(source);
}
catch (Exception e)
@ -165,88 +151,42 @@ namespace Ca2d.Toolkit
return default(T);
}
public static async UniTask IgnoreException<TSource>(TSource source, Func<TSource, UniTask> exec)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="source">The source of this operation</param>
/// <param name="exec">Executor of source executor</param>
public static async UniTask IgnoreExceptionAsync<TSource>(this TSource source, Func<TSource, UniTask> exec)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke(source);
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static async UniTask<T> IgnoreException<TSource, T>(TSource source, Func<TSource, UniTask<T>> exec)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="source">The source of this operation</param>
/// <param name="exec">Executor of source executor</param>
public static async UniTask<T> IgnoreExceptionAsync<TSource, T>(this TSource source, Func<TSource, UniTask<T>> exec)
{
try
if (exec == null)
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke(source);
}
catch (Exception e)
{ Debug.LogError(e); }
IgnoreNoTarget();
return default(T);
}
public static async Task IgnoreException<TSource>(TSource source, Func<TSource, Task> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke(source);
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static async Task<T> IgnoreException<TSource, T>(TSource source, Func<TSource, Task<T>> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke(source);
}
catch (Exception e)
{ Debug.LogError(e); }
return default(T);
}
public static async ValueTask IgnoreException<TSource>(this TSource source, Func<TSource, ValueTask> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke(source);
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static async ValueTask<T> IgnoreException<TSource, T>(this TSource source, Func<TSource, ValueTask<T>> exec)
{
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke(source);
}
catch (Exception e)
@ -257,30 +197,46 @@ namespace Ca2d.Toolkit
#endregion
#region IgnoreException(Action<P1::Type>, P1)
#region IgnoreException(Action<P1>, P1)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
public static void IgnoreException<TP1>(Action<TP1> exec, TP1 p1)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
exec.Invoke(p1);
}
catch (Exception e)
{ Debug.LogError(e); }
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
public static T IgnoreException<TP1, T>(Func<TP1, T> exec, TP1 p1)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return exec.Invoke(p1);
}
catch (Exception e)
@ -289,28 +245,44 @@ namespace Ca2d.Toolkit
return default(T);
}
public static async UniTask IgnoreException<TP1>(Func<TP1, UniTask> exec, TP1 p1)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
public static async UniTask IgnoreExceptionAsync<TP1>(Func<TP1, UniTask> exec, TP1 p1)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke(p1);
}
catch (Exception e)
{ Debug.LogError(e); }
}
public static async UniTask<T> IgnoreException<TP1, T>(Func<TP1, UniTask<T>> exec, TP1 p1)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
public static async UniTask<T> IgnoreExceptionAsync<TP1, T>(Func<TP1, UniTask<T>> exec, TP1 p1)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke(p1);
}
catch (Exception e)
@ -319,66 +291,477 @@ namespace Ca2d.Toolkit
return default(T);
}
public static async Task IgnoreException<TP1>(Func<TP1, Task> exec, TP1 p1)
#endregion
#region IgnoreException(Action<P1, P2>, P1, P2)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
public static void IgnoreException<TP1, TP2>(Action<TP1, TP2> exec, TP1 p1, TP2 p2)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke(p1);
exec.Invoke(p1, p2);
}
catch (Exception e)
{ Debug.LogError(e); }
{
Debug.LogError(e);
}
}
public static async Task<T> IgnoreException<TP1, T>(Func<TP1, Task<T>> exec, TP1 p1)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
public static T IgnoreException<TP1, TP2, T>(Func<TP1, TP2, T> exec, TP1 p1, TP2 p2)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke(p1);
return exec.Invoke(p1, p2);
}
catch (Exception e)
{ Debug.LogError(e); }
{
Debug.LogError(e);
}
return default(T);
}
public static async ValueTask IgnoreException<TP1>(Func<TP1, ValueTask> exec, TP1 p1)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
public static async UniTask IgnoreExceptionAsync<TP1, TP2>(Func<TP1, TP2, UniTask> exec, TP1 p1, TP2 p2)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
await exec.Invoke(p1);
await exec.Invoke(p1, p2);
}
catch (Exception e)
{ Debug.LogError(e); }
{
Debug.LogError(e);
}
}
public static async ValueTask<T> IgnoreException<TP1, T>(Func<TP1, ValueTask<T>> exec, TP1 p1)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
public static async UniTask<T> IgnoreExceptionAsync<TP1, TP2, T>(
Func<TP1, TP2, UniTask<T>> exec, TP1 p1, TP2 p2)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
if (exec == null) throw new ArgumentNullException(
nameof(exec),
"Ignore Exception should run with executor!");
return await exec.Invoke(p1);
return await exec.Invoke(p1, p2);
}
catch (Exception e)
{ Debug.LogError(e); }
{
Debug.LogError(e);
}
return default(T);
}
#endregion
#region IgnoreException(Action<P1, P2, P3>, P1, P2, P3)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
public static void IgnoreException<TP1, TP2, TP3>(
Action<TP1, TP2, TP3> exec,
TP1 p1, TP2 p2, TP3 p3)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
exec.Invoke(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
public static T IgnoreException<TP1, TP2, TP3, T>(
Func<TP1, TP2, TP3, T> exec,
TP1 p1, TP2 p2, TP3 p3)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
return exec.Invoke(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError(e);
}
return default(T);
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
public static async UniTask IgnoreExceptionAsync<TP1, TP2, TP3>(
Func<TP1, TP2, TP3, UniTask> exec,
TP1 p1, TP2 p2, TP3 p3)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
await exec.Invoke(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
public static async UniTask<T> IgnoreExceptionAsync<TP1, TP2, TP3, T>(
Func<TP1, TP2, TP3, UniTask<T>> exec,
TP1 p1, TP2 p2, TP3 p3)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
return await exec.Invoke(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError(e);
}
return default(T);
}
#endregion
#region IgnoreException(Action<P1, P2, P3, P4>, P1, P2, P3, P4)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
public static void IgnoreException<TP1, TP2, TP3, TP4>(
Action<TP1, TP2, TP3, TP4> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
exec.Invoke(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
public static T IgnoreException<TP1, TP2, TP3, TP4, T>(
Func<TP1, TP2, TP3, TP4, T> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
return exec.Invoke(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError(e);
}
return default(T);
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
public static async UniTask IgnoreExceptionAsync<TP1, TP2, TP3, TP4>(
Func<TP1, TP2, TP3, TP4, UniTask> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
await exec.Invoke(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
public static async UniTask<T> IgnoreExceptionAsync<TP1, TP2, TP3, TP4, T>(
Func<TP1, TP2, TP3, TP4, UniTask<T>> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
return await exec.Invoke(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError(e);
}
return default(T);
}
#endregion
#region IgnoreException(Action<P1, P2, P3, P4, P5>, P1, P2, P3, P4, P5)
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
/// <param name="p5">Fifth parameter of this method</param>
public static void IgnoreException<TP1, TP2, TP3, TP4, TP5>(
Action<TP1, TP2, TP3, TP4, TP5> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
exec.Invoke(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
/// <param name="p5">Fifth parameter of this method</param>
public static T IgnoreException<TP1, TP2, TP3, TP4, TP5, T>(
Func<TP1, TP2, TP3, TP4, TP5, T> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
return exec.Invoke(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError(e);
}
return default(T);
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
/// <param name="p5">Fifth parameter of this method</param>
public static async UniTask IgnoreExceptionAsync<TP1, TP2, TP3, TP4, TP5>(
Func<TP1, TP2, TP3, TP4, TP5, UniTask> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5)
{
if (exec == null)
{
IgnoreNoTarget();
return;
}
try
{
await exec.Invoke(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
/// <summary>
/// Ignore <see cref="Exception"/>s raised with this method and log them into console directly.
/// </summary>
/// <param name="exec">Executor of method</param>
/// <param name="p1">First parameter os this method</param>
/// <param name="p2">Second parameter of this method</param>
/// <param name="p3">Third parameter of this method</param>
/// <param name="p4">Fourth parameter of this method</param>
/// <param name="p5">Fifth parameter of this method</param>
public static async UniTask<T> IgnoreExceptionAsync<TP1, TP2, TP3, TP4, TP5, T>(
Func<TP1, TP2, TP3, TP4, TP5, UniTask<T>> exec,
TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5)
{
if (exec == null)
{
IgnoreNoTarget();
return default(T);
}
try
{
return await exec.Invoke(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError(e);
}
return default(T);
}
#endregion
/* UnityObject Related */
@ -390,7 +773,7 @@ namespace Ca2d.Toolkit
if (opt.Enabled)
{
if (opt.Value == null)
throw new Exception();
throw new LoseRequirementException(typeof(T));
component = opt.Value;
return true;
@ -427,7 +810,7 @@ namespace Ca2d.Toolkit
{
if (!go.TryGetComponent<T>(out component))
{
throw new Exception();
throw new LoseRequirementException(typeof(T));
}
return go;
@ -437,7 +820,7 @@ namespace Ca2d.Toolkit
{
if (!source.TryGetComponent<T>(out component))
{
throw new Exception();
throw new LoseRequirementException(typeof(T));
}
return source;

View File

@ -378,6 +378,9 @@ namespace Ca2d.Toolkit
public void Error(string text)
{}
public void Error(Exception err)
{}
}
public static class QLog

View File

@ -0,0 +1,25 @@
using System;
namespace Ca2d.Toolkit
{
public class LoseRequirementException : Exception
{
public Type RequiredType { get; }
public LoseRequirementException(Type type) : base($"Required type {type?.FullName} was lost when resolving.")
{
RequiredType = type;
}
public LoseRequirementException(Object obj) : base($"Required type {obj?.GetType().FullName} was lost when resolving.")
{
RequiredType = obj?.GetType();
}
public LoseRequirementException(ValueType obj) : base($"Required type {obj.GetType().FullName} was lost when resolving.")
{
RequiredType = obj.GetType();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9e6b670f1e074609bca59e1042256991
timeCreated: 1715182584

View File

@ -3,6 +3,11 @@ using UnityEngine.Assertions;
namespace Ca2d.Toolkit
{
/// <summary>
/// An utility structure which helps you to create an optional field in Unity Editor or a <see cref="Nullable"/>
/// alternative.
/// </summary>
/// <typeparam name="T">The type which will be optional.</typeparam>
[Serializable]
public struct Option<T>
{

View File

@ -1,33 +0,0 @@
namespace Ca2d.Toolkit
{
public class Ref<T> where T : struct
{
private T m_value;
public Ref(T mValue)
{
m_value = mValue;
}
public T Value
{
get => m_value;
set => m_value = value;
}
public override string ToString()
{
return m_value.ToString();
}
public static implicit operator T(Ref<T> wrapper)
{
return wrapper.Value;
}
public static implicit operator Ref<T>(T value)
{
return new Ref<T>(value);
}
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 069b06808ea54580b3e8b8862e6b9587
timeCreated: 1712972593

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 16a7b38b52044b7983d66b421c2fab7c
timeCreated: 1712972588

View File

@ -1,16 +1,25 @@
using System;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Ca2d.Toolkit
{
/// <summary>
/// An utility which allows you to reference an <see cref="UnityEngine.Object"/> via it's interface.
/// </summary>
/// <typeparam name="T">The type of class which you are willing to reference as.</typeparam>
[Serializable]
public struct UnityObjectWarp<T> where T : class
{
[SerializeField] private Object m_referencedObject;
[SerializeField] private UnityEngine.Object m_referencedObject;
/// <summary>
/// Is this warp reference to a valid target?
/// </summary>
public bool Valid => m_referencedObject is T;
/// <summary>
/// Trying to get the actual object of this reference.
/// </summary>
public T Object => m_referencedObject as T;
public static implicit operator T(UnityObjectWarp<T> wrapper)