-
Notifications
You must be signed in to change notification settings - Fork 0
How To
Conditions are evaluated with OR Superiority. Meaning if I have a condition A OR B AND C, the condition is evaluated as (A OR B) AND C. In otherwords, the order of operation is such that immediately an OR is encountered, it grabs the next immediate Condition to evaluate until it hits an AND. An OR Condition with nothing after it is treated as an AND. Meaning if it's False, the total operation is false. See Examples below. The order in which you have your conditions MATTER. One false means the whole ConditionManager is false. A OR B AND C is VERY different from B AND A OR C or any variation.
There are 2 main steps to creating and using a condition. The first part is setting up the condition itself. Regarding this package, this is the only scripting required. It is simply marking a method or property with the [Condition] attribute. The second part is attaching conditions to a script using ConditionManager or to a gameObject using . The term "condition function" will refer to a function marked with the condition attribute. NOTE: An empty ConditionManager evaluates to the specified default return.ConditionManagerComponent
Attributes, for reference, are the metadata in square brackets above a class, method, field, etc in a script. Such as [SerializeField] or [Tooltip]. The Condition attribute is only valid on Methods and Properties. Marking a Property or a Method as a condition lets the ConditionManager know that this function can serve also as a condition. It enables the ConditionManager to seamlessly integrate into systems you likely would've already created. It is also important that the return type of the function in question implements the IComparable interface so that they can be easily compared.
The [Condition] Attribute is your first step to creating a condition. As stated above, it is important that the return type of the condition implement the IComparable interface provided by C#. Once that is done, the next step is to add a ConditionManager field to a given object. Once added, you can create a condition with the Create Condition button in the inspector. This will open a window for you to create your condition (As of now, Creating Conditions with the "+" button is unsupported. You can remove functions with the "-" button however). Simply drag a gameObject or script into the object field to begin. If there are any valid condition functions on the game object, they will appear for you to select from. Note that asset objects should only accept other asset objects. That's it. it is HIGHLY recommended that you test conditions as I put additional checks when you run that function in the editor. Again, An empty ConditionManager evaluates to true If the object is a MonoScript, only static members are valid.
I have created a simple class called ArbitraryClass which has a ConditionManager field on it just as you would in your own class and attached it to a gameObject. When I refer to ArbitraryClass, substitute with the actual class you are working with.

The examples below are all from the script EZSampleScript1 which is located in Packages\EZ-Conditions\Documentation\EZConditionsSample1.cs in the inspector. You can look at it yourself In this example, EZSampleScript1 and EZSampleScript2 are attached to a gameObject called "Player". ScriptableObjects and MonoScripts themselves are supported as well.
- Create a property just like you would do. (I added the SerializeField attribute so that it can be edited in the inspector. It is NOT needed for this to function)
[field: SerializeField]
[Condition]
public string Name {get; set;} // Return type is string. Therefore we will be comparing against a string- Select the
Create Conditionbutton and then drag the object with the script in which you have a condition (In this case, the Player gameObject is being dragged into the ObjectField because it is the object I am trying to condition)
-
As you can see, this script has more than one condition function on it and it has been grouped appropriately.
-
Select the desired Condition Function. Checks are in place if the object is not an
IComparabletype to prevent you from progressing. Assuming you have a valid return type, you will be greeted with an appropriate comparison enum and the object to compare to. In this case, a string:

-
Pressing Create Condition will create your new condition and add it to the condition manager. (It is recommended that you press test Conditions after you add/remove a condition).

-
That's it. Now all you need to do is run it when you want with the
EvaluateConditionsmethod. In this example, I run the condition by pressing the spacebar key. For reference, the Player's name is "Steve"
// ArbitraryClass.cs
private void Update()
{
// Evaluate the condition set when I press space. The boolean parameter signifies I want debug logs
if (Input.GetKeyDown(KeyCode.Space))
{
conditionManager.EvaluateConditions(true);
}
}- We get a false return just as we should expect from comparing "Steve" to "John Doe"
\ - Alternatively, adding an or condition and rearranging the order, evaluates to true:
- DO NOT Add conditions with the "+" button. The "-" button is useful for removing conditions. The "+" button should not be utilised to create a function. (I hope to enable this feature)
- Once a condition is created, it is read only. You have to remove it from the condition manager and create a new one if you want it to be different.
- Because of the above, it is ill-advised to create conditions outside of the condition manager. Although you’re not restricted from doing so. Make sure to validate with
Condition.IsValidproperty to check the validity of whatever condition you make before utilising it.
"+" Means OR "*" means "AND"
- A = A OR = A AND
- A*B = A AND B
- A+B = A OR B
- A * B + C = A AND (B + C)
A = TRUE, B = FALSE, C = FALSE, D = TRUE, E = FALSE
- A = TRUE
- B = FALSE
- A AND B
- TRUE AND FALSE
- FALSE
- TRUE AND FALSE
- A OR B
- TRUE OR FALSE
- TRUE
- TRUE OR FALSE
- A OR B OR C
- TRUE OR FALSE OR FALSE
- TRUE
- TRUE OR FALSE OR FALSE
- A OR B AND C
- TRUE OR FALSE AND FALSE
- (TRUE OR FALSE) AND FALSE
- TRUE AND FALSE
- FALSE
- TRUE AND FALSE
- (TRUE OR FALSE) AND FALSE
- TRUE OR FALSE AND FALSE
- B AND A OR C
- FALSE AND TRUE OR FALSE
- FALSE AND (TRUE OR FALSE)
- FALSE AND TRUE
- FALSE
- FALSE AND TRUE
- FALSE AND (TRUE OR FALSE)
- FALSE AND TRUE OR FALSE
- B AND C AND A
- FALSE AND FALSE AND TRUE
- FALSE
- FALSE AND FALSE AND TRUE
- B OR C OR E OR A
- FALSE OR FALSE OR FALSE OR TRUE
- TRUE
- FALSE OR FALSE OR FALSE OR TRUE