-
Notifications
You must be signed in to change notification settings - Fork 0
Conditions Extending
Richard Kopelow edited this page Aug 29, 2018
·
1 revision
Conditions are one of the more complicated systems to extend. This will involve writing actual code do the comparisons, rather than just inheriting from several generics. There's a lot of wiggle room here to do custom work, but stray from the cookie cutter too much and you may need to write custom property drawers.
Conditions handle the meet of evaluations.
- Inherit from
Condition<T>withTbeing the datatype to work on. - Create an
enumfor the type of evaluation. i.e. greater than, less than - If you're making a generic condition (i.e. one that handles the logic to IComarable), you'll want to take three type parameters
<T, Y, Z>, the datatype, the ValueType for the corresponding datatype, and the event type for the datatype. - Define
public YourEnum Condition - Define
public Y Argument. - Define
public Z Event. - Override
Evaluate(T value). This function should handle doing evaluation betweenvalueandArgument. As well as firingEvent. It needs to consider all theConditionEvaluationModes. - If you made a generic condition, you will then inherit from that, filling in the type parameters for all the data types you want to handle. Unity Can't serialize Generics which is why you need to make specific classes that inherit from the generic with the type parameter filled in.
- Add the
[Serializable]attribute to any of the final classes that will get attached to objects.
- Define a class that inherits from
ConditionCollection<T,Y>. withTbeing the datatype andYbeing the Condition Type. - Add the
[Serializable]attribute to the Collection.
Conditionable Variables are variables with conditions built into them.
- Create a new code file.
- Rather than inheriting from
BaseVariable<T>, inherit fromConditionableVariable<T, Y>withYbeing the ConditionCollection. - Follow the rest of the Variable Extension steps
Watchers are scripts that live on GameObjectss that watch Variables.
- Create a new code file.
- Define a class that inherits from
BaseConditionWatcher<T, Y, Z>withTbeing the datatype,Ybeing the Variable type, andZbeing the ConditionCollection type.
- Events
- Variables
- Conditions
- Extras
- GUI Elements
- Systems