VoxelBuildingRuleset.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using KairoEngine.Chunks;
  6. namespace KairoEngine.VoxelBuildingSystem
  7. {
  8. [System.Serializable]
  9. public class VoxelBuildingRuleset
  10. {
  11. public ConditionType condition;
  12. public List<VoxelBuildingRule> rules = new List<VoxelBuildingRule>();
  13. public bool Evaluate(VoxelBuildingSystem buildingSystem, int templateIndex, Vector3Int position, int rotationIndex)
  14. {
  15. List<bool> results = new List<bool>();
  16. for (int i = 0; i < rules.Count; i++)
  17. {
  18. results.Add(rules[i].Evaluate(buildingSystem, templateIndex, position, rotationIndex));
  19. }
  20. if(condition == ConditionType.AND)
  21. {
  22. foreach (var value in results)
  23. {
  24. if(value == false) return false;
  25. }
  26. return true;
  27. }
  28. else
  29. {
  30. foreach (var value in results)
  31. {
  32. if(value == true) return true;
  33. }
  34. return false;
  35. }
  36. }
  37. }
  38. public enum ConditionType
  39. {
  40. AND,
  41. OR
  42. }
  43. }