Room.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class Room : MonoBehaviour
  6. {
  7. public float Height = 0.5f;
  8. public int Rounding = 1;
  9. public bool move = false;
  10. public bool BoxColliderEnabled = true;
  11. private Vector3 screenPoint;
  12. private Vector3 offset;
  13. private Vector3 curScreenPoint;
  14. private Vector3 curPosition;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
  19. }
  20. // Update is called once per frame
  21. void Update()
  22. {
  23. if (gameObject.GetComponent<BoxCollider>().enabled != BoxColliderEnabled) gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
  24. }
  25. void OnMouseDown()
  26. {
  27. //Debug.Log(StagesEditorController.indexCursor);
  28. screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
  29. offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
  30. }
  31. // Перемещение
  32. void OnMouseDrag()
  33. {
  34. curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
  35. curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
  36. var x = (float)Math.Round(curPosition.x, Rounding);
  37. var z = (float)Math.Round(curPosition.z, Rounding);
  38. //transform.position = new Vector3(x, Height, z);
  39. gameObject.GetComponent<BoxCollider>().size = new Vector3(x, Height, z);
  40. LocationController.Cube(gameObject, new Vector3(x, z, Height));
  41. }
  42. }