Fixed script error and added support for static functions in CallbackAction

This commit is contained in:
Kah Wei 2022-10-30 02:37:58 +08:00
parent dbf1b0b8de
commit da05cb3edc
4 changed files with 243 additions and 56 deletions

View File

@ -61,8 +61,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[1];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -86,7 +103,7 @@ namespace SHADE
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1> action) public CallbackAction(Action<T1> action)
{ {
targetAction = action; targetAction = action;
@ -103,7 +120,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1); targetAction.Invoke(t1);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
_ = targetMethod.Invoke(TargetObject, parameters); _ = targetMethod.Invoke(TargetObject, parameters);
@ -138,8 +155,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[2];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -158,12 +192,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[2];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2> action) public CallbackAction(Action<T1, T2> action)
{ {
targetAction = action; targetAction = action;
@ -180,7 +214,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2); targetAction.Invoke(t1, t2);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -216,8 +250,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[3];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -236,12 +287,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[3];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3> action) public CallbackAction(Action<T1, T2, T3> action)
{ {
targetAction = action; targetAction = action;
@ -258,7 +309,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3); targetAction.Invoke(t1, t2, t3);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -295,8 +346,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[4];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -315,12 +383,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[4];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3, T4> action) public CallbackAction(Action<T1, T2, T3, T4> action)
{ {
targetAction = action; targetAction = action;
@ -337,7 +405,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3, t4); targetAction.Invoke(t1, t2, t3, t4);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -375,8 +443,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[5];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -395,12 +480,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[5];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3, T4, T5> action) public CallbackAction(Action<T1, T2, T3, T4, T5> action)
{ {
targetAction = action; targetAction = action;
@ -417,7 +502,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3, t4, t5); targetAction.Invoke(t1, t2, t3, t4, t5);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -456,8 +541,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[6];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -476,12 +578,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[6];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3, T4, T5, T6> action) public CallbackAction(Action<T1, T2, T3, T4, T5, T6> action)
{ {
targetAction = action; targetAction = action;
@ -498,7 +600,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3, t4, t5, t6); targetAction.Invoke(t1, t2, t3, t4, t5, t6);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -538,8 +640,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[7];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -558,12 +677,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[7];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7> action) public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7> action)
{ {
targetAction = action; targetAction = action;
@ -580,7 +699,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7); targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -621,8 +740,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[8];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -641,12 +777,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[8];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8> action) public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8> action)
{ {
targetAction = action; targetAction = action;
@ -663,7 +799,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8); targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -705,8 +841,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[9];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -725,12 +878,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[9];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action) public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9> action)
{ {
targetAction = action; targetAction = action;
@ -747,7 +900,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9); targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;
@ -790,8 +943,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[10];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -810,12 +980,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[10];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action) public CallbackAction(Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> action)
{ {
targetAction = action; targetAction = action;
@ -832,7 +1002,7 @@ namespace SHADE
{ {
targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); targetAction.Invoke(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
parameters[0] = t1; parameters[0] = t1;
parameters[1] = t2; parameters[1] = t2;

View File

@ -78,8 +78,25 @@ namespace SHADE
/// </summary> /// </summary>
public CallbackAction() {} public CallbackAction() {}
/// <summary> /// <summary>
/// Constructs a CallbackAction that represents a call to the specified method on the /// Constructs a CallbackAction that represents a call to the specified static
/// specified target. /// method.
/// </summary>
/// <param name="method">Method to call.</param>
/// <exception cref="ArgumentException">
/// Thrown if a method that is not compatible with the target is specified. The method's
/// source type must match the target's type.
/// </exception>
public CallbackAction(MethodInfo method)
{
// No errors, assign
targetMethod = method;
// Create storage for parameters for calling
parameters = new Object[<#=i#>];
}
/// <summary>
/// Constructs a CallbackAction that represents a call to a specified member
/// method on the specified target.
/// </summary> /// </summary>
/// <param name="target">Object to call the method on.</param> /// <param name="target">Object to call the method on.</param>
/// <param name="method">Method to call.</param> /// <param name="method">Method to call.</param>
@ -98,12 +115,12 @@ namespace SHADE
targetMethod = method; targetMethod = method;
// Create storage for parameters for calling // Create storage for parameters for calling
parameters = new Object[1]; parameters = new Object[<#=i#>];
} }
/// <summary> /// <summary>
/// Constructs a Callback action based on an action. /// Constructs a Callback action based on an action.
/// </summary> /// </summary>
/// <param name="action"></param> /// <param name="action">Action that wraps a function to be called.</param>
public CallbackAction(Action<<# for (int t = 1; t < i + 1; ++t) { #>T<#=t#><# if (t != i) { #>, <# } #><# } #>> action) public CallbackAction(Action<<# for (int t = 1; t < i + 1; ++t) { #>T<#=t#><# if (t != i) { #>, <# } #><# } #>> action)
{ {
targetAction = action; targetAction = action;
@ -120,7 +137,7 @@ namespace SHADE
{ {
targetAction.Invoke(<# for (int t = 1; t < i + 1; ++t) { #>t<#=t#><# if (t != i) { #>, <# } #><# } #>); targetAction.Invoke(<# for (int t = 1; t < i + 1; ++t) { #>t<#=t#><# if (t != i) { #>, <# } #><# } #>);
} }
else if (TargetObject != null && targetMethod != null) else if (targetMethod != null)
{ {
<# for (int t = 0; t < i; ++t) {#>parameters[<#=t#>] = t<#=t+1#>; <# for (int t = 0; t < i; ++t) {#>parameters[<#=t#>] = t<#=t+1#>;
<# } #>_ = targetMethod.Invoke(TargetObject, parameters); <# } #>_ = targetMethod.Invoke(TargetObject, parameters);

View File

@ -194,7 +194,7 @@ namespace SHADE
/* Properties */ /* Properties */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/// <summary> /// <summary>
/// Total number of ColliderBounds in the Collider component. /// Total number of ColliderShapes in the Collider component.
/// </summary> /// </summary>
property int CollisionShapeCount property int CollisionShapeCount
{ {

View File

@ -28,7 +28,7 @@ public class PhysicsTest : Script
Debug.LogError("Collider is NULL!"); Debug.LogError("Collider is NULL!");
} }
var subColider = Collider.ColliderBoundsCount; var subColider = Collider.CollisionShapeCount;
Debug.Log($"There are {subColider} colliders."); Debug.Log($"There are {subColider} colliders.");
} }
protected override void update() protected override void update()