Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #################################
- Class the "conditions" are inheriting from:
- ----------------------------------
- public abstract class Conditions : ScriptableObject
- {
- public abstract bool ConditionAchieved(StateController controller);
- }
- ----------------------------------
- ##################################
- Example for a "condition" type class:
- ----------------------------------
- public class C_CompareValue : Conditions
- {
- // what value (resource, for example) belonging to a faction am I trying to compare
- public enum value
- {
- gold,
- testvalue
- }
- [InspectorName("Value")] public value valE;
- // what operation am I trying to test
- public enum operation
- {
- isBiggerThan,
- isSmallerThan,
- EqualsTo,
- }
- [InspectorName("Operator")] public operation opeE;
- // what value am I comparing to
- [SerializeField] public float valueToCompareTo;
- // called every update by the state controller
- public override bool ConditionAchieved(StateController controller)
- {
- float valueToCompare = 0;
- switch(valE)
- {
- case value.gold:
- valueToCompare = controller.factionModule.gold;
- break;
- }
- switch (opeE)
- {
- case operation.EqualsTo:
- return (valueToCompare == valueToCompareTo);
- case operation.isBiggerThan:
- return (valueToCompare > valueToCompareTo);
- case operation.isSmallerThan:
- return (valueToCompare < valueToCompareTo);
- }
- Debug.Log($"Condition CompareValue for {controller} has failed.");
- return true;
- }
- }
- ----------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement