VoxelTerrainEditor.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. using Utilities = KairoEngine.Utility.Utilities;
  6. using KairoEngine.GameTools.InteractionTools;
  7. using KairoEngine.UI;
  8. using Sirenix.OdinInspector;
  9. namespace KairoEngine.TerrainEngine
  10. {
  11. public class VoxelTerrainEditor : MonoBehaviour
  12. {
  13. public enum Tool
  14. {
  15. None,
  16. Add,
  17. Remove,
  18. Level
  19. }
  20. public ChunkTerrainGenerator chunkTerrainGenerator;
  21. public LayerMask layerMask;
  22. public int radius = 3;
  23. public Tool currentTool = Tool.None;
  24. public uint code = 0;
  25. private void Update()
  26. {
  27. if(currentTool == Tool.None) return;
  28. if(MouseInputUIBlocker.BlockedByUI) return;
  29. Vector3 pos = Utilities.GetMouseWorldPosition(layerMask);
  30. switch (currentTool)
  31. {
  32. case Tool.Add:
  33. if(Input.GetMouseButtonDown(0)) chunkTerrainGenerator.ChangeVoxels(pos, code, ChunkTerrainGenerator.VoxelOperation.Add, radius);
  34. break;
  35. case Tool.Remove:
  36. if(Input.GetMouseButtonDown(0)) chunkTerrainGenerator.ChangeVoxels(pos, code, ChunkTerrainGenerator.VoxelOperation.Remove, radius);
  37. break;
  38. case Tool.Level:
  39. if(Input.GetMouseButtonDown(0)) chunkTerrainGenerator.ChangeVoxels(pos, code, ChunkTerrainGenerator.VoxelOperation.Level, radius);
  40. break;
  41. default:
  42. break;
  43. }
  44. }
  45. }
  46. }