VoxelBuildingRule.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. public enum RuleType
  9. {
  10. EmptyVoxels
  11. }
  12. [System.Serializable]
  13. public class VoxelBuildingRule
  14. {
  15. private string title
  16. {
  17. get
  18. {
  19. switch (rule)
  20. {
  21. case RuleType.EmptyVoxels: return $"Empty voxels";
  22. default: return "?";
  23. }
  24. }
  25. }
  26. [SerializeField, FoldoutGroup("@title")] private RuleType rule;
  27. public bool Evaluate(VoxelBuildingSystem buildingSystem, int templateIndex, Vector3Int position, int rotationIndex)
  28. {
  29. switch (rule)
  30. {
  31. case RuleType.EmptyVoxels: return EvaluateEmptyVoxels(buildingSystem, templateIndex, position, rotationIndex);
  32. default: return false;
  33. }
  34. }
  35. public bool EvaluateEmptyVoxels(VoxelBuildingSystem buildingSystem, int templateIndex, Vector3Int position, int rotationIndex)
  36. {
  37. List<Vector3Int> voxelPositions = buildingSystem.GetBuildingVoxelList(position, templateIndex, rotationIndex);
  38. for (int i = 0; i < voxelPositions.Count; i++)
  39. {
  40. VoxelBuildData block = buildingSystem.chunkSystem.GetBlock(voxelPositions[i]);
  41. if(block.buildingIndex != -1)
  42. {
  43. return false;
  44. }
  45. }
  46. return true;
  47. }
  48. }
  49. }