Skip to content

Conditions Extending

Richard Kopelow edited this page Aug 29, 2018 · 1 revision

Conditions - Extending

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

Conditions handle the meet of evaluations.

  1. Inherit from Condition<T> with T being the datatype to work on.
  2. Create an enum for the type of evaluation. i.e. greater than, less than
  3. 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.
  4. Define public YourEnum Condition
  5. Define public Y Argument.
  6. Define public Z Event.
  7. Override Evaluate(T value). This function should handle doing evaluation between value and Argument. As well as firing Event. It needs to consider all the ConditionEvaluationModes.
  8. 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.
  9. Add the [Serializable] attribute to any of the final classes that will get attached to objects.

Condition Collections

  1. Define a class that inherits from ConditionCollection<T,Y>. with T being the datatype and Y being the Condition Type.
  2. Add the [Serializable] attribute to the Collection.

Conditionable Variables

Conditionable Variables are variables with conditions built into them.

  1. Create a new code file.
  2. Rather than inheriting from BaseVariable<T>, inherit from ConditionableVariable<T, Y> with Y being the ConditionCollection.
  3. Follow the rest of the Variable Extension steps

Watchers

Watchers are scripts that live on GameObjectss that watch Variables.

  1. Create a new code file.
  2. Define a class that inherits from BaseConditionWatcher<T, Y, Z> with T being the datatype, Y being the Variable type, and Z being the ConditionCollection type.

Clone this wiki locally