3#include "../Utils/Delegate.hpp"
4#include "../Utils/Il2cpp.hpp"
5#include "../Utils/MonoPtr.hpp"
7#include <custom-types/shared/delegate.hpp>
8#include <UnityEngine/Object.hpp>
9#include <UnityEngine/Events/UnityAction.hpp>
10#include <UnityEngine/Events/UnityAction_1.hpp>
11#include <UnityEngine/Events/UnityAction_2.hpp>
12#include <UnityEngine/Events/UnityAction_3.hpp>
13#include <UnityEngine/Events/UnityAction_4.hpp>
14#include <UnityEngine/UI/Button_ButtonClickedEvent.hpp>
19 template<
class t_Type>
26 template<
class t_Type>
32 template<
class t_Type>
35 static_assert(std::is_assignable_v<UnityEngine::Object, t_Type>);
53 #define CP_SDK_UI_IL2CPP_BIND_FIELD(__Field, __Variable) __Field = [this]() -> CP_SDK::UI::UIFieldRefDelExtractor<typeof(__Field)>::t_PtrType { return __Variable; };
63 template <
typename t_Type,
typename t_DelegateType>
66 return custom_types::MakeDelegate<t_Type>(p_Delegate);
73 template<
typename... t_Args>
76 constexpr int l_ArgCount =
sizeof...(t_Args);
78 if constexpr (l_ArgCount == 0)
return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction*>(p_Delegate);
79 else if constexpr (l_ArgCount == 1)
return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_1<t_Args...>*>(p_Delegate);
80 else if constexpr (l_ArgCount == 2)
return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_2<t_Args...>*>(p_Delegate);
81 else if constexpr (l_ArgCount == 3)
return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_3<t_Args...>*>(p_Delegate);
82 else if constexpr (l_ArgCount == 4)
return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_4<t_Args...>*>(p_Delegate);
85 static_assert(l_ArgCount <= 4,
"argument count was greater than supported");
92 template<
typename t_Type,
typename...t_Args>
93 requires(std::is_constructible_v<std::function<void(t_Args...)>, t_Type> && !std::is_same_v<std::function<void(t_Args...)>, t_Type>)
96 return MakeUnityAction<t_Args...>(std::function<void(t_Args...)>(p_Delegate));
103 template<
typename...t_Args>
106 if (p_MethodInfo->parameters_count !=
sizeof...(t_Args))
107 throw std::runtime_error(
"Argcount mismatch between p_MethodInfo and t_Args");
109 return MakeUnityAction<t_Args...>(std::function<void(t_Args...)>([p_Instance, p_MethodInfo](t_Args... p_Args){
110 il2cpp_utils::RunMethod(p_Instance, p_MethodInfo, p_Args...);
User interface components, views, flow coordinator, builders and factories.
t_Type CustomTypesMakeDelegate(t_DelegateType p_Delegate)
a templated method to put the MakeDelegate call into a function so that when we change where the Make...
auto MakeUnityAction(std::function< void(t_Args...)> p_Delegate)
templated method to turn an std::function into an action