Added display of WIP CallbackEvents on the inspector

This commit is contained in:
Kah Wei 2022-10-25 01:34:46 +08:00
parent c6d29a1038
commit f6cbb18143
8 changed files with 167 additions and 10 deletions

View File

@ -57,6 +57,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -130,6 +134,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -204,6 +212,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -279,6 +291,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -355,6 +371,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -432,6 +452,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -510,6 +534,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -589,6 +617,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -669,6 +701,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>
@ -750,6 +786,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>

View File

@ -74,6 +74,10 @@ namespace SHADE
#region Constructors ------------------------------------------------------------ #region Constructors ------------------------------------------------------------
/// <summary> /// <summary>
/// Constructs an empty Callback action.
/// </summary>
public CallbackAction() {}
/// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified method on the
/// specified target. /// specified target.
/// </summary> /// </summary>

View File

@ -22,6 +22,10 @@ namespace SHADE
/// </summary> /// </summary>
public interface ICallbackEvent public interface ICallbackEvent
{ {
/// <summary>
/// Registers an empty ICallbackAction.
/// </summary>
void RegisterAction();
/// <summary> /// <summary>
/// Registers an ICallbackAction with the event such that it will be called in /// Registers an ICallbackAction with the event such that it will be called in
/// future /// future
@ -59,6 +63,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -140,6 +149,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -221,6 +235,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -302,6 +321,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3, T4>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -383,6 +407,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3, T4, T5>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -464,6 +493,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3, T4, T5, T6>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -545,6 +579,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3, T4, T5, T6, T7>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -626,6 +665,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3, T4, T5, T6, T7, T8>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -707,6 +751,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3, T4, T5, T6, T7, T8, T9>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action
@ -788,6 +837,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action

View File

@ -38,6 +38,10 @@ namespace SHADE
/// </summary> /// </summary>
public interface ICallbackEvent public interface ICallbackEvent
{ {
/// <summary>
/// Registers an empty ICallbackAction.
/// </summary>
void RegisterAction();
/// <summary> /// <summary>
/// Registers an ICallbackAction with the event such that it will be called in /// Registers an ICallbackAction with the event such that it will be called in
/// future /// future
@ -76,6 +80,11 @@ namespace SHADE
#region Usage Functions --------------------------------------------------------- #region Usage Functions ---------------------------------------------------------
/// <inheritdoc/> /// <inheritdoc/>
public void RegisterAction()
{
actions.Add(new CallbackAction<<# for (int t = 1; t < i + 1; ++t) { #>T<#=t#><# if (t != i) { #>, <# } #><# } #>>());
}
/// <inheritdoc/>
public void RegisterAction(ICallbackAction action) public void RegisterAction(ICallbackAction action)
{ {
// Check if valid action // Check if valid action

View File

@ -54,7 +54,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
bool SHEditorUI::CollapsingHeader(const std::string& title) bool SHEditorUI::CollapsingHeader(const std::string& title)
{ {
return ImGui::CollapsingHeader(title.c_str()); return ImGui::CollapsingHeader(title.c_str(), ImGuiTreeNodeFlags_DefaultOpen);
} }
void SHEditorUI::SameLine() void SHEditorUI::SameLine()

View File

@ -255,6 +255,10 @@ namespace SHADE
<HintPath Condition=\"Exists('..\\bin\\Debug\\SHADE_Managed.dll')\">..\\bin\\Debug\\SHADE_Managed.dll</HintPath>\n\ <HintPath Condition=\"Exists('..\\bin\\Debug\\SHADE_Managed.dll')\">..\\bin\\Debug\\SHADE_Managed.dll</HintPath>\n\
<HintPath Condition=\"Exists('..\\bin\\Release\\SHADE_Managed.dll')\">..\\bin\\Release\\SHADE_Managed.dll</HintPath>\n\ <HintPath Condition=\"Exists('..\\bin\\Release\\SHADE_Managed.dll')\">..\\bin\\Release\\SHADE_Managed.dll</HintPath>\n\
</Reference>\n\ </Reference>\n\
<Reference Include=\"SHADE_CSharp\">\n\
<HintPath Condition=\"Exists('..\\bin\\Debug\\SHADE_Managed.dll')\">..\\bin\\Debug\\SHADE_CSharp.dll</HintPath>\n\
<HintPath Condition=\"Exists('..\\bin\\Release\\SHADE_Managed.dll')\">..\\bin\\Release\\SHADE_CSharp.dll</HintPath>\n\
</Reference>\n\
</ItemGroup>\n\ </ItemGroup>\n\
</Project>"; </Project>";

View File

@ -286,17 +286,59 @@ namespace SHADE
registerUndoAction(object, field, Convert::ToCLI(val), Convert::ToCLI(oldVal)); registerUndoAction(object, field, Convert::ToCLI(val), Convert::ToCLI(oldVal));
} }
} }
else if (field->FieldType->BaseType == ICallbackEvent::typeid)
{
// Needs to present
// - name and param list
// Needs to present for each callbackaction
// - object, methodinfo OR action
// - Ways to add or remove items
}
else else
{ {
return; array<System::Type^>^ interfaces = field->FieldType->GetInterfaces();
if (interfaces->Length > 0 && interfaces[0] == ICallbackEvent::typeid)
{
array<System::Type^>^ typeArgs = field->FieldType->GenericTypeArguments;
System::String^ title = field->Name + " : CallbackEvent<";
for (int i = 0; i < typeArgs->Length; ++i)
{
title += typeArgs[i]->Name;
if (i < typeArgs->Length - 1)
title += ", ";
}
title += ">";
if (SHEditorUI::CollapsingHeader(Convert::ToNative(title)))
{
ICallbackEvent^ callbackEvent = safe_cast<ICallbackEvent^>(field->GetValue(object));
if (callbackEvent == nullptr)
{
// Construct one since it was not constructed before
callbackEvent = safe_cast<ICallbackEvent^>(System::Activator::CreateInstance(field->FieldType));
}
for each (ICallbackAction ^ action in callbackEvent->Actions)
{
if (action->IsRuntimeAction)
continue;
if (action->TargetObject == nullptr)
SHEditorUI::Text("Target Object");
else
SHEditorUI::Text(Convert::ToNative(action->TargetObject->GetType()->Name));
SHEditorUI::SameLine();
if (action->TargetMethodName == nullptr)
SHEditorUI::Text("Target Method Name");
else
SHEditorUI::Text(Convert::ToNative(action->TargetMethodName));
}
if (SHEditorUI::Button("Add Action"))
{
callbackEvent->RegisterAction();
}
}
// Needs to present
// - name and param list
// Needs to present for each callbackaction
// - object, methodinfo OR action
// - Ways to add or remove items
}
else
{
return;
}
} }
// Check if the field has a specific attribute // Check if the field has a specific attribute

View File

@ -7,6 +7,10 @@ public class RaccoonSpin : Script
[Tooltip("Speed of the rotation in radians per second.")] [Tooltip("Speed of the rotation in radians per second.")]
private double RotateSpeed = 1.0; private double RotateSpeed = 1.0;
private double rotation = 0.0; private double rotation = 0.0;
[SerializeField]
private CallbackEvent<int> testEvent;
[SerializeField]
private CallbackEvent<int, double, Vector3> testEvent3 = new CallbackEvent<int, double, Vector3>();
private Transform Transform; private Transform Transform;
public RaccoonSpin(GameObject gameObj) : base(gameObj) { } public RaccoonSpin(GameObject gameObj) : base(gameObj) { }