Advertisement
Guest User

Untitled

a guest
Apr 27th, 2023
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #################################
  2. Class the "conditions" are inheriting from:
  3. ----------------------------------
  4. public abstract class Conditions : ScriptableObject
  5. {
  6. public abstract bool ConditionAchieved(StateController controller);
  7. }
  8. ----------------------------------
  9.  
  10. ##################################
  11. Example for a "condition" type class:
  12. ----------------------------------
  13. public class C_CompareValue : Conditions
  14. {
  15. // what value (resource, for example) belonging to a faction am I trying to compare
  16. public enum value
  17. {
  18. gold,
  19. testvalue
  20. }
  21.  
  22. [InspectorName("Value")] public value valE;
  23.  
  24.  
  25. // what operation am I trying to test
  26. public enum operation
  27. {
  28. isBiggerThan,
  29. isSmallerThan,
  30. EqualsTo,
  31. }
  32.  
  33. [InspectorName("Operator")] public operation opeE;
  34.  
  35.  
  36. // what value am I comparing to
  37. [SerializeField] public float valueToCompareTo;
  38.  
  39.  
  40. // called every update by the state controller
  41. public override bool ConditionAchieved(StateController controller)
  42. {
  43. float valueToCompare = 0;
  44.  
  45. switch(valE)
  46. {
  47. case value.gold:
  48. valueToCompare = controller.factionModule.gold;
  49. break;
  50. }
  51.  
  52. switch (opeE)
  53. {
  54. case operation.EqualsTo:
  55. return (valueToCompare == valueToCompareTo);
  56.  
  57. case operation.isBiggerThan:
  58. return (valueToCompare > valueToCompareTo);
  59.  
  60. case operation.isSmallerThan:
  61. return (valueToCompare < valueToCompareTo);
  62. }
  63.  
  64. Debug.Log($"Condition CompareValue for {controller} has failed.");
  65. return true;
  66. }
  67. }
  68. ----------------------------------
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement