diff --git a/Assets/Main/Resources/Ca2d/Toolkit.meta b/Assets/Main/Resources/Ca2d/Toolkit.meta deleted file mode 100644 index 4795ac3..0000000 --- a/Assets/Main/Resources/Ca2d/Toolkit.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 682379589b9245c194f6d38b178c8a7b -timeCreated: 1712972381 \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable.meta b/Assets/Main/Scripts/Bootable.meta deleted file mode 100644 index 26bce28..0000000 --- a/Assets/Main/Scripts/Bootable.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1fdfef18a5d440bb8214c941d439e605 -timeCreated: 1712972698 \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/BootDescription.cs b/Assets/Main/Scripts/Bootable/BootDescription.cs deleted file mode 100644 index d8dd137..0000000 --- a/Assets/Main/Scripts/Bootable/BootDescription.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Ca2d.Toolkit.Bootable -{ - public struct BootDescription - { - public readonly string Id; - - public readonly IBootCondition Condition; - - public readonly IBootExecutor[] Executors; - } -} \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/BootDescription.cs.meta b/Assets/Main/Scripts/Bootable/BootDescription.cs.meta deleted file mode 100644 index 1cf1b54..0000000 --- a/Assets/Main/Scripts/Bootable/BootDescription.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6ce9da660f08484f8ccebff2aaf3a825 -timeCreated: 1713192001 \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/BootState.cs b/Assets/Main/Scripts/Bootable/BootState.cs deleted file mode 100644 index 6ad32ed..0000000 --- a/Assets/Main/Scripts/Bootable/BootState.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Ca2d.Toolkit.Bootable -{ - public enum BootState - { - Created = 0, - - Pending = 1, - - Prepare = 2, - - Running = 3, - - Exit = 4, - - Fatal = 5 - } -} \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/BootState.cs.meta b/Assets/Main/Scripts/Bootable/BootState.cs.meta deleted file mode 100644 index 071b0c8..0000000 --- a/Assets/Main/Scripts/Bootable/BootState.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: ddd6ed54d6c24afa90dbe41a9cedbe22 -timeCreated: 1713193446 \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/IBootCondition.cs b/Assets/Main/Scripts/Bootable/IBootCondition.cs deleted file mode 100644 index 7acf927..0000000 --- a/Assets/Main/Scripts/Bootable/IBootCondition.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Ca2d.Toolkit.Bootable -{ - public class IBootCondition - { - - } -} \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/IBootCondition.cs.meta b/Assets/Main/Scripts/Bootable/IBootCondition.cs.meta deleted file mode 100644 index b2bfd51..0000000 --- a/Assets/Main/Scripts/Bootable/IBootCondition.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d711f6a53d984d4ab120859e20193edc -timeCreated: 1713192171 \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/IBootExecutor.cs b/Assets/Main/Scripts/Bootable/IBootExecutor.cs deleted file mode 100644 index 31cd211..0000000 --- a/Assets/Main/Scripts/Bootable/IBootExecutor.cs +++ /dev/null @@ -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> Runner { get; } - } -} \ No newline at end of file diff --git a/Assets/Main/Scripts/Bootable/IBootExecutor.cs.meta b/Assets/Main/Scripts/Bootable/IBootExecutor.cs.meta deleted file mode 100644 index 85cc774..0000000 --- a/Assets/Main/Scripts/Bootable/IBootExecutor.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e5221434446d45f9904f24ab2f9f4f3d -timeCreated: 1713193262 \ No newline at end of file diff --git a/Assets/Main/Scripts/Boxing.cs b/Assets/Main/Scripts/Boxing.cs new file mode 100644 index 0000000..051b4bb --- /dev/null +++ b/Assets/Main/Scripts/Boxing.cs @@ -0,0 +1,75 @@ +using System; +using UnityEngine; +using UnityEngine.UIElements; + +namespace Ca2d.Toolkit +{ + /// + /// An utility which gives a type safe boxing. + /// + /// The value type which will being boxing. + [Serializable] + public class Boxing where T : struct + { + [SerializeField] private T m_value; + + /// + /// Create a copy of given boxing source. + /// + public Boxing(Boxing source) + { + m_value = source.Unbox; + } + + /// + /// Create a copy of given value. + /// + public Boxing(T value) + { + m_value = value; + } + + /// + /// Create a empty boxing. + /// + public Boxing() + {} + + /// + /// Get a copy of boxing value. + /// + public T Unbox + { + get => m_value; + set => m_value = value; + } + + /// + /// Access to the boxing value directly. + /// + public ref T Direct => ref m_value; + + /// + /// Clean this boxing container to the default value of boxing target. + /// + public void Empty() + { + m_value = default; + } + + public override string ToString() + { + return m_value.ToString(); + } + + public static implicit operator T(Boxing wrapper) + { + return wrapper.Unbox; + } + + public static implicit operator Boxing(T value) + { + return new Boxing(value); + } + } +} \ No newline at end of file diff --git a/Assets/Main/Scripts/Ref.cs.meta b/Assets/Main/Scripts/Boxing.cs.meta similarity index 100% rename from Assets/Main/Scripts/Ref.cs.meta rename to Assets/Main/Scripts/Boxing.cs.meta diff --git a/Assets/Main/Scripts/Exceptions.meta b/Assets/Main/Scripts/Exceptions.meta deleted file mode 100644 index cd31175..0000000 --- a/Assets/Main/Scripts/Exceptions.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4f6e1e1705424ac39408a10837b49e52 -timeCreated: 1713285459 \ No newline at end of file diff --git a/Assets/Main/Scripts/Guard.cs b/Assets/Main/Scripts/Guard.cs index 37c2a8a..fa98e80 100644 --- a/Assets/Main/Scripts/Guard.cs +++ b/Assets/Main/Scripts/Guard.cs @@ -8,31 +8,48 @@ namespace Ca2d.Toolkit public static class Guard { /* IgnoreException Utils */ + + private static void IgnoreNoTarget() + { + Debug.LogError("Ignore Exception should run with executor!"); + } #region IgnoreException(Action) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method 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); } } + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method public static T IgnoreException(Func 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,28 +58,42 @@ namespace Ca2d.Toolkit return default(T); } - public static async UniTask IgnoreException(Func exec) + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + public static async UniTask IgnoreExceptionAsync(Func 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 IgnoreException(Func> exec) + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + public static async UniTask IgnoreExceptionAsync(Func> exec) { + 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(); } catch (Exception e) @@ -71,92 +102,47 @@ namespace Ca2d.Toolkit return default(T); } - public static async Task IgnoreException(Func 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 IgnoreException(Func> 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 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 IgnoreException(Func> 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); - } - #endregion - #region IgnoreException(this Source, Action) + #region IgnoreException(this Source, Action) - public static void IgnoreException(TSource source, Action exec) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// The source of this operation + /// Executor of source executor + public static void IgnoreException(this TSource source, Action 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 source, Func exec) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// The source of this operation + /// Executor of source executor + public static T IgnoreException(this TSource source, Func 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 source, Func exec) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// The source of this operation + /// Executor of source executor + public static async UniTask IgnoreExceptionAsync(this TSource source, Func 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 IgnoreException(TSource source, Func> exec) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// The source of this operation + /// Executor of source executor + public static async UniTask IgnoreExceptionAsync(this TSource source, Func> exec) { - try + if (exec == null) { - if (exec == null) throw new ArgumentNullException( - nameof(exec), - "Ignore Exception should run with executor!"); - - return await exec.Invoke(source); + IgnoreNoTarget(); + return default(T); } - catch (Exception e) - { Debug.LogError(e); } - - return default(T); - } - - public static async Task IgnoreException(TSource source, Func 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 IgnoreException(TSource source, Func> 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(this TSource source, Func 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 IgnoreException(this TSource source, Func> 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) + #region IgnoreException(Action, P1) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method public static void IgnoreException(Action 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); } } + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method public static T IgnoreException(Func 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,88 +245,44 @@ namespace Ca2d.Toolkit return default(T); } - public static async UniTask IgnoreException(Func exec, TP1 p1) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + public static async UniTask IgnoreExceptionAsync(Func 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 IgnoreException(Func> exec, TP1 p1) + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + public static async UniTask IgnoreExceptionAsync(Func> exec, TP1 p1) { - try + + if (exec == null) { - if (exec == null) throw new ArgumentNullException( - nameof(exec), - "Ignore Exception should run with executor!"); - - return await exec.Invoke(p1); + IgnoreNoTarget(); + return default(T); } - catch (Exception e) - { Debug.LogError(e); } - - return default(T); - } - - public static async Task IgnoreException(Func exec, TP1 p1) - { + 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 Task IgnoreException(Func> exec, TP1 p1) - { - try - { - if (exec == null) throw new ArgumentNullException( - nameof(exec), - "Ignore Exception should run with executor!"); - - return await exec.Invoke(p1); - } - catch (Exception e) - { Debug.LogError(e); } - - return default(T); - } - - public static async ValueTask IgnoreException(Func exec, TP1 p1) - { - 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 ValueTask IgnoreException(Func> exec, TP1 p1) - { - try - { - if (exec == null) throw new ArgumentNullException( - nameof(exec), - "Ignore Exception should run with executor!"); - return await exec.Invoke(p1); } catch (Exception e) @@ -381,6 +293,477 @@ namespace Ca2d.Toolkit #endregion + #region IgnoreException(Action, P1, P2) + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + public static void IgnoreException(Action exec, TP1 p1, TP2 p2) + { + if (exec == null) + { + IgnoreNoTarget(); + return; + } + + try + { + exec.Invoke(p1, p2); + } + catch (Exception e) + { + Debug.LogError(e); + } + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + public static T IgnoreException(Func exec, TP1 p1, TP2 p2) + { + if (exec == null) + { + IgnoreNoTarget(); + return default(T); + } + + try + { + return exec.Invoke(p1, p2); + } + catch (Exception e) + { + Debug.LogError(e); + } + + return default(T); + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + public static async UniTask IgnoreExceptionAsync(Func exec, TP1 p1, TP2 p2) + { + if (exec == null) + { + IgnoreNoTarget(); + return; + } + + try + { + await exec.Invoke(p1, p2); + } + catch (Exception e) + { + Debug.LogError(e); + } + } + + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + public static async UniTask IgnoreExceptionAsync( + Func> exec, TP1 p1, TP2 p2) + { + if (exec == null) + { + IgnoreNoTarget(); + return default(T); + } + + try + { + return await exec.Invoke(p1, p2); + } + catch (Exception e) + { + Debug.LogError(e); + } + + return default(T); + } + + + #endregion + + #region IgnoreException(Action, P1, P2, P3) + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + public static void IgnoreException( + Action exec, + TP1 p1, TP2 p2, TP3 p3) + { + if (exec == null) + { + IgnoreNoTarget(); + return; + } + + try + { + exec.Invoke(p1, p2, p3); + } + catch (Exception e) + { + Debug.LogError(e); + } + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + public static T IgnoreException( + Func 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); + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + public static async UniTask IgnoreExceptionAsync( + Func 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); + } + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + public static async UniTask IgnoreExceptionAsync( + Func> 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) + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + public static void IgnoreException( + Action 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); + } + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + public static T IgnoreException( + Func 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); + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + public static async UniTask IgnoreExceptionAsync( + Func 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); + } + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + public static async UniTask IgnoreExceptionAsync( + Func> 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) + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + /// Fifth parameter of this method + public static void IgnoreException( + Action 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); + } + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + /// Fifth parameter of this method + public static T IgnoreException( + Func 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); + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + /// Fifth parameter of this method + public static async UniTask IgnoreExceptionAsync( + Func 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); + } + } + + /// + /// Ignore s raised with this method and log them into console directly. + /// + /// Executor of method + /// First parameter os this method + /// Second parameter of this method + /// Third parameter of this method + /// Fourth parameter of this method + /// Fifth parameter of this method + public static async UniTask IgnoreExceptionAsync( + Func> 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 */ #region RequireComponent @@ -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(out component)) { - throw new Exception(); + throw new LoseRequirementException(typeof(T)); } return go; @@ -437,7 +820,7 @@ namespace Ca2d.Toolkit { if (!source.TryGetComponent(out component)) { - throw new Exception(); + throw new LoseRequirementException(typeof(T)); } return source; diff --git a/Assets/Main/Scripts/Log.cs b/Assets/Main/Scripts/Log.cs index 86be7fa..09d5db0 100644 --- a/Assets/Main/Scripts/Log.cs +++ b/Assets/Main/Scripts/Log.cs @@ -378,6 +378,9 @@ namespace Ca2d.Toolkit public void Error(string text) {} + + public void Error(Exception err) + {} } public static class QLog diff --git a/Assets/Main/Scripts/LoseRequirementException.cs b/Assets/Main/Scripts/LoseRequirementException.cs new file mode 100644 index 0000000..62bc0a1 --- /dev/null +++ b/Assets/Main/Scripts/LoseRequirementException.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/Assets/Main/Scripts/LoseRequirementException.cs.meta b/Assets/Main/Scripts/LoseRequirementException.cs.meta new file mode 100644 index 0000000..07fb53d --- /dev/null +++ b/Assets/Main/Scripts/LoseRequirementException.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9e6b670f1e074609bca59e1042256991 +timeCreated: 1715182584 \ No newline at end of file diff --git a/Assets/Main/Scripts/Option.cs b/Assets/Main/Scripts/Option.cs index 82a7800..3a9b3f8 100644 --- a/Assets/Main/Scripts/Option.cs +++ b/Assets/Main/Scripts/Option.cs @@ -3,6 +3,11 @@ using UnityEngine.Assertions; namespace Ca2d.Toolkit { + /// + /// An utility structure which helps you to create an optional field in Unity Editor or a + /// alternative. + /// + /// The type which will be optional. [Serializable] public struct Option { diff --git a/Assets/Main/Scripts/Ref.cs b/Assets/Main/Scripts/Ref.cs deleted file mode 100644 index c0431b9..0000000 --- a/Assets/Main/Scripts/Ref.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Ca2d.Toolkit -{ - public class Ref 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 wrapper) - { - return wrapper.Value; - } - - public static implicit operator Ref(T value) - { - return new Ref(value); - } - } -} \ No newline at end of file diff --git a/Assets/Main/Scripts/Rx.meta b/Assets/Main/Scripts/Rx.meta deleted file mode 100644 index af1f5d4..0000000 --- a/Assets/Main/Scripts/Rx.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 069b06808ea54580b3e8b8862e6b9587 -timeCreated: 1712972593 \ No newline at end of file diff --git a/Assets/Main/Scripts/UI.meta b/Assets/Main/Scripts/UI.meta deleted file mode 100644 index 082200c..0000000 --- a/Assets/Main/Scripts/UI.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 16a7b38b52044b7983d66b421c2fab7c -timeCreated: 1712972588 \ No newline at end of file diff --git a/Assets/Main/Scripts/UnityObjectWarp.cs b/Assets/Main/Scripts/UnityObjectWarp.cs index 37d009d..038992c 100644 --- a/Assets/Main/Scripts/UnityObjectWarp.cs +++ b/Assets/Main/Scripts/UnityObjectWarp.cs @@ -1,16 +1,25 @@ using System; using UnityEngine; -using Object = UnityEngine.Object; namespace Ca2d.Toolkit { + /// + /// An utility which allows you to reference an via it's interface. + /// + /// The type of class which you are willing to reference as. [Serializable] public struct UnityObjectWarp where T : class { - [SerializeField] private Object m_referencedObject; + [SerializeField] private UnityEngine.Object m_referencedObject; + /// + /// Is this warp reference to a valid target? + /// public bool Valid => m_referencedObject is T; + /// + /// Trying to get the actual object of this reference. + /// public T Object => m_referencedObject as T; public static implicit operator T(UnityObjectWarp wrapper)