PlaceableObjectRuleGroup.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. namespace KairoEngine.Grids
  6. {
  7. [System.Serializable]
  8. public class PlaceableObjectRuleGroup
  9. {
  10. public ConditionType condition;
  11. public List<PlaceableObjectRule> rules = new List<PlaceableObjectRule>();
  12. public bool Evaluate(Grid<GridObject> grid, PlacedObjectType placedObjectType, int x, int y, PlacedObjectType.Dir dir)
  13. {
  14. List<bool> results = new List<bool>();
  15. for (int i = 0; i < rules.Count; i++)
  16. {
  17. results.Add(rules[i].Evaluate(grid, placedObjectType, x, y, dir));
  18. }
  19. if(condition == ConditionType.AND)
  20. {
  21. foreach (var value in results)
  22. {
  23. if(value == false) return false;
  24. }
  25. return true;
  26. }
  27. else
  28. {
  29. foreach (var value in results)
  30. {
  31. if(value == true) return true;
  32. }
  33. return false;
  34. }
  35. }
  36. }
  37. }