GridController.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Tilemaps;
  5. public class GridController : MonoBehaviour {
  6. [SerializeField] Tilemap highlightMap = null;
  7. [SerializeField] TileBase hilightTile = null;
  8. private IAction hilightAction;
  9. public IAction HilightAction { get => hilightAction; set => hilightAction = value; }
  10. // Update is called once per frame
  11. void Update() {
  12. if (Input.GetMouseButtonDown(0) && hilightAction != null && hilightAction.GetHilightEnabled()) {
  13. Vector3Int clickedPos = GetMousePosition();
  14. highlightMap.SetTile(clickedPos, hilightTile);
  15. // TODO needs better handling.. Should be in MoveAction???
  16. YesNoDilougueUI.Instance.ShowDialog("Are you sure you want to move here?",
  17. () => { Debug.Log("YES PRESSED"); /* Confirm the move and paint the path to take. */},
  18. () => { Debug.Log("NO PRESSED"); highlightMap.SetTile(clickedPos, null); });
  19. }
  20. }
  21. Vector3Int GetMousePosition() {
  22. Vector3 mousePos = Input.mousePosition;
  23. mousePos.z = -Camera.main.transform.position.z;
  24. Vector3 worldPoint = Camera.main.ScreenToWorldPoint(mousePos);
  25. return GameManagerScript.GetInstance().TileMap.WorldToCell(worldPoint);
  26. }
  27. }