CameraRect.cs 735 B

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. using System.Collections;
  3. public class CameraRect : MonoBehaviour {
  4. private InputController inputController;
  5. private RectTransform rectTrans;
  6. public void init(InputController inputController)
  7. {
  8. this.inputController = inputController;
  9. rectTrans = this.GetComponent<RectTransform>();
  10. }
  11. // Update is called once per frame
  12. void FixedUpdate ()
  13. {
  14. Vector3 position = inputController.cameraPosition;
  15. int col = (int)NumberUtil.forceBetween(position.x/Map.TILE_WIDTH, 0, 128f);
  16. int row = (int)NumberUtil.forceBetween((position.z)/Map.TILE_LENGTH, 0, 128f);
  17. Vector3 pos = rectTrans.localPosition;
  18. pos.x = MiniMap.offsetX+col;
  19. pos.y = MiniMap.offsetY+row;
  20. rectTrans.localPosition = pos;
  21. }
  22. }