Custom Conditions
Let’s see how we can add Custom
conditions to the inspector list of the SUElementCanvas
/SUElementsToolkit
.
What we have to do is to open the script ConditionChecks that we can find in the Condition folder.
Then we must simply add a new entry to the dictionary called “All”.
The KeyValuePair entry is structured in this way :
Key
: is a string use to identify the condition in the inspector (if you change it , all the references in all the inspector will be lost)Value
: is a combination of a string and a function. The string is the name/path of the condition that you will see written in the Inspector ( you can change it as many times as you want ). The function is the logic that should do the check in order to see if the condition is satisfied.
Then, there is the Input
value that contains the gameObject
that called the condition so that you can perform some check even related to the caller itself.
In the example below “_weeke” is the key, “Date/IsWeekEnd” is the inspector name and then there are two comparisons of "DayOfWeek".
Custom Fields
If you want to add custom fields to the conditions, you just have to add a list of PathField
the moment you create the condition, like this :
//checkbox test
{"_test",
new PathFunc("Test/MyCondition",
new List<PathField>()
{
new PathField("My bool",PathFieldType_ID.Bool_1),
},
(input)=>
{
Debug.Log(input.fieldsValues.Bool_1);
return true;
})},
In this way , a checkbox will appear in the inspector of the condition.
...even more Custom Fields
If we want to add a serialized field without using built-in fields like above, we must open the file CustomSerializedConditionFields
and add our public serialized field, like below
public partial class SUConditionData
{
//user-defined serialized fields
[SerializeField]
RigidbodySleepMode2D _myField = default;
public RigidbodySleepMode2D MyField { get => _myField; }
}
Then, when adding a new condition, we just add a PathField with the name of the field added before; this field will also be accessible by using input.conditionData...
like below
//conditions container
public readonly static Dictionary <string,PathFunc> All = new Dictionary <string,PathFunc>()
{
{"_key",
new PathFunc("Test/MyCondition",
new List<PathField>()
{
new PathField("Wow","_myField")
},
(input)=>
{
Debug.Log(input.conditionData.MyField);
return true;
})},
};
Here's the inspector of our condition