mirror of
https://github.com/Cardidi/ca2d-unity-toolkit.git
synced 2025-12-20 17:26:03 +08:00
feat: Complete Guard.IgnoreException families.
feat: Add XML documentation to some methods and classes. remove: Cleanup BootUnit for rewriting.
This commit is contained in:
parent
cffb31c1df
commit
91c24b27e8
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 682379589b9245c194f6d38b178c8a7b
|
|
||||||
timeCreated: 1712972381
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 1fdfef18a5d440bb8214c941d439e605
|
|
||||||
timeCreated: 1712972698
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
namespace Ca2d.Toolkit.Bootable
|
|
||||||
{
|
|
||||||
public struct BootDescription
|
|
||||||
{
|
|
||||||
public readonly string Id;
|
|
||||||
|
|
||||||
public readonly IBootCondition Condition;
|
|
||||||
|
|
||||||
public readonly IBootExecutor[] Executors;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 6ce9da660f08484f8ccebff2aaf3a825
|
|
||||||
timeCreated: 1713192001
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
namespace Ca2d.Toolkit.Bootable
|
|
||||||
{
|
|
||||||
public enum BootState
|
|
||||||
{
|
|
||||||
Created = 0,
|
|
||||||
|
|
||||||
Pending = 1,
|
|
||||||
|
|
||||||
Prepare = 2,
|
|
||||||
|
|
||||||
Running = 3,
|
|
||||||
|
|
||||||
Exit = 4,
|
|
||||||
|
|
||||||
Fatal = 5
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: ddd6ed54d6c24afa90dbe41a9cedbe22
|
|
||||||
timeCreated: 1713193446
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
namespace Ca2d.Toolkit.Bootable
|
|
||||||
{
|
|
||||||
public class IBootCondition
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: d711f6a53d984d4ab120859e20193edc
|
|
||||||
timeCreated: 1713192171
|
|
||||||
@ -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; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: e5221434446d45f9904f24ab2f9f4f3d
|
|
||||||
timeCreated: 1713193262
|
|
||||||
75
Assets/Main/Scripts/Boxing.cs
Normal file
75
Assets/Main/Scripts/Boxing.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 4f6e1e1705424ac39408a10837b49e52
|
|
||||||
timeCreated: 1713285459
|
|
||||||
@ -9,30 +9,47 @@ namespace Ca2d.Toolkit
|
|||||||
{
|
{
|
||||||
/* IgnoreException Utils */
|
/* IgnoreException Utils */
|
||||||
|
|
||||||
|
private static void IgnoreNoTarget()
|
||||||
|
{
|
||||||
|
Debug.LogError("Ignore Exception should run with executor!");
|
||||||
|
}
|
||||||
|
|
||||||
#region IgnoreException(Action)
|
#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)
|
public static void IgnoreException(Action exec)
|
||||||
{
|
{
|
||||||
|
if (exec == null)
|
||||||
|
{
|
||||||
|
IgnoreNoTarget();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
exec.Invoke();
|
exec.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(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)
|
public static T IgnoreException<T>(Func<T> exec)
|
||||||
{
|
{
|
||||||
|
if (exec == null)
|
||||||
|
{
|
||||||
|
IgnoreNoTarget();
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
return exec.Invoke();
|
return exec.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -41,88 +58,42 @@ namespace Ca2d.Toolkit
|
|||||||
return default(T);
|
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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
await exec.Invoke();
|
await exec.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(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();
|
/// <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);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{ Debug.LogError(e); }
|
|
||||||
|
|
||||||
return default(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task IgnoreException(Func<Task> exec)
|
|
||||||
{
|
|
||||||
try
|
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();
|
return await exec.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -133,30 +104,45 @@ namespace Ca2d.Toolkit
|
|||||||
|
|
||||||
#endregion
|
#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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
exec.Invoke(source);
|
exec.Invoke(source);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
return exec.Invoke(source);
|
return exec.Invoke(source);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -165,88 +151,42 @@ namespace Ca2d.Toolkit
|
|||||||
return default(T);
|
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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
await exec.Invoke(source);
|
await exec.Invoke(source);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(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(
|
IgnoreNoTarget();
|
||||||
nameof(exec),
|
return default(T);
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
return await exec.Invoke(source);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{ Debug.LogError(e); }
|
|
||||||
|
|
||||||
return default(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async Task IgnoreException<TSource>(TSource source, Func<TSource, Task> exec)
|
|
||||||
{
|
|
||||||
try
|
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);
|
return await exec.Invoke(source);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -257,30 +197,46 @@ namespace Ca2d.Toolkit
|
|||||||
|
|
||||||
#endregion
|
#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)
|
public static void IgnoreException<TP1>(Action<TP1> exec, TP1 p1)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (exec == null)
|
||||||
|
{
|
||||||
|
IgnoreNoTarget();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
exec.Invoke(p1);
|
exec.Invoke(p1);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(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)
|
public static T IgnoreException<TP1, T>(Func<TP1, T> exec, TP1 p1)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (exec == null)
|
||||||
|
{
|
||||||
|
IgnoreNoTarget();
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
return exec.Invoke(p1);
|
return exec.Invoke(p1);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -289,28 +245,44 @@ namespace Ca2d.Toolkit
|
|||||||
return default(T);
|
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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
await exec.Invoke(p1);
|
await exec.Invoke(p1);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(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
|
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);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -319,66 +291,477 @@ namespace Ca2d.Toolkit
|
|||||||
return default(T);
|
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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
exec.Invoke(p1, p2);
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
await exec.Invoke(p1);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
return exec.Invoke(p1, p2);
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
return await exec.Invoke(p1);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(e); }
|
{
|
||||||
|
Debug.LogError(e);
|
||||||
|
}
|
||||||
|
|
||||||
return default(T);
|
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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
await exec.Invoke(p1, p2);
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
await exec.Invoke(p1);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
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
|
try
|
||||||
{
|
{
|
||||||
if (exec == null) throw new ArgumentNullException(
|
return await exec.Invoke(p1, p2);
|
||||||
nameof(exec),
|
|
||||||
"Ignore Exception should run with executor!");
|
|
||||||
|
|
||||||
return await exec.Invoke(p1);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{ Debug.LogError(e); }
|
{
|
||||||
|
Debug.LogError(e);
|
||||||
|
}
|
||||||
|
|
||||||
return default(T);
|
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
|
#endregion
|
||||||
|
|
||||||
/* UnityObject Related */
|
/* UnityObject Related */
|
||||||
@ -390,7 +773,7 @@ namespace Ca2d.Toolkit
|
|||||||
if (opt.Enabled)
|
if (opt.Enabled)
|
||||||
{
|
{
|
||||||
if (opt.Value == null)
|
if (opt.Value == null)
|
||||||
throw new Exception();
|
throw new LoseRequirementException(typeof(T));
|
||||||
|
|
||||||
component = opt.Value;
|
component = opt.Value;
|
||||||
return true;
|
return true;
|
||||||
@ -427,7 +810,7 @@ namespace Ca2d.Toolkit
|
|||||||
{
|
{
|
||||||
if (!go.TryGetComponent<T>(out component))
|
if (!go.TryGetComponent<T>(out component))
|
||||||
{
|
{
|
||||||
throw new Exception();
|
throw new LoseRequirementException(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
return go;
|
return go;
|
||||||
@ -437,7 +820,7 @@ namespace Ca2d.Toolkit
|
|||||||
{
|
{
|
||||||
if (!source.TryGetComponent<T>(out component))
|
if (!source.TryGetComponent<T>(out component))
|
||||||
{
|
{
|
||||||
throw new Exception();
|
throw new LoseRequirementException(typeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
|
|||||||
@ -378,6 +378,9 @@ namespace Ca2d.Toolkit
|
|||||||
|
|
||||||
public void Error(string text)
|
public void Error(string text)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
public void Error(Exception err)
|
||||||
|
{}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class QLog
|
public static class QLog
|
||||||
|
|||||||
25
Assets/Main/Scripts/LoseRequirementException.cs
Normal file
25
Assets/Main/Scripts/LoseRequirementException.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Main/Scripts/LoseRequirementException.cs.meta
Normal file
3
Assets/Main/Scripts/LoseRequirementException.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9e6b670f1e074609bca59e1042256991
|
||||||
|
timeCreated: 1715182584
|
||||||
@ -3,6 +3,11 @@ using UnityEngine.Assertions;
|
|||||||
|
|
||||||
namespace Ca2d.Toolkit
|
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]
|
[Serializable]
|
||||||
public struct Option<T>
|
public struct Option<T>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 069b06808ea54580b3e8b8862e6b9587
|
|
||||||
timeCreated: 1712972593
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 16a7b38b52044b7983d66b421c2fab7c
|
|
||||||
timeCreated: 1712972588
|
|
||||||
@ -1,16 +1,25 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
|
||||||
|
|
||||||
namespace Ca2d.Toolkit
|
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]
|
[Serializable]
|
||||||
public struct UnityObjectWarp<T> where T : class
|
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;
|
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 T Object => m_referencedObject as T;
|
||||||
|
|
||||||
public static implicit operator T(UnityObjectWarp<T> wrapper)
|
public static implicit operator T(UnityObjectWarp<T> wrapper)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user