Methods Parameters Management

Print

Dynamic Components can have methods with parameters. You insert their values via the inspector during the Dynamic Scenario configuration.

BDD Extension Framework can manage many types of parameters natively:

C# base types: bool, byte, sbyte, char, decimal, double, float, int, uint, long, ulong, short, ushort, string.

Unity3d: GameObject, Transform, Component,

Vector2, Vector3, Vector4, Rect, Quaternion, Matrix4x4, Color, Color32, LayerMask, AnimationCurve, Gradient, RectOffset, GUIStyle.

However, you can add other managed types to your own Dynamic Component. To do that, you have to declare a ParametersValuesStorage field inside your Dynamic Component as follow:

[HideInInspector]

[ParametersValuesStorage]

[SerializeField]

protected CustomType[] customFieldName;

 

Where CustomType is the type of the parameter you want to manage, and customFieldName is the name of the array field that is going to contain the values of your parameters. You have not to initialise the field; it is completely managed by the BDD Framework.

We want to bring your attention on the field declaration: it has to be, always, an array. Do not forget to make it an array or you will receive an error on the component inspector.

A Dynamic Component can have only one ParametersValuesStorage for each Type. If you declare two ParametersValuesStorage fields with the same element type, you will receive an error on the component inspector.

You cannot manage every type of classes. Unity has rules about that:

see the chapter "Simple field types that can be serialized" in this page on the Unity3D Documentation.

As you can read on Unity documentation, you cannot serialise multilevel types. Our field is already an array, so if you try to manage a container type, you will have unexpected behaviours.

If a custom type has its own custom inspector, the framework is going to use it to show the parameter properly on the inspector.

 

Q: How can I verify if I can use a type?

You can, initially, make the field public and delete the attribute [HideInInspector]. If the inspector of the component shows the field, the type can be used for your parameters.

 

Q: What if I want to manage a List<T> or an array?

The quick solution could be to declare a normal public field in your Component. Obviously, the type of the elements has to be one of those that Unity can serialise.

 

Q: If I make the ParametersValuesStorage field public and I delete the [HideInInspector] I can see the field in the component inspector. Is it right?

Yes, it is, but we suggest always to hide the field to avoid the temptation to modify its values manually. You cannot know how the BDD Framework is going to manage your changes.

 

Back to: Static BDD Test: Creation of a GameObject Read next: Headless running (batch mode)