RoomController.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /// <summary>
  6. /// Создание комнаты в редакторе
  7. /// не используется
  8. /// </summary>
  9. public class RoomController : MonoBehaviour
  10. {
  11. public float Height = 1f;
  12. public int Rounding = 1;
  13. public bool move = true;
  14. public bool BoxColliderEnabled = true;
  15. //GameObject cursor_end;
  16. private Vector3 screenPoint;
  17. private Vector3 offset;
  18. private Vector3 curScreenPoint;
  19. private Vector3 curPosition;
  20. public Vector3 start_pos = Vector3.zero; // координаты левого нижнего угла
  21. // Start is called before the first frame update
  22. void Start()
  23. {
  24. gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
  25. //cursor_end = transform.GetChild(6).gameObject;
  26. }
  27. // Update is called once per frame
  28. void Update()
  29. {
  30. if (gameObject.GetComponent<BoxCollider>().enabled != BoxColliderEnabled) gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
  31. }
  32. void OnMouseDown()
  33. {
  34. //Debug.Log(StagesEditorController.indexCursor);
  35. screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
  36. offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
  37. }
  38. // Перемещение
  39. void OnMouseDrag()
  40. {
  41. curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
  42. curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
  43. var x = (float)Math.Round(curPosition.x, Rounding);
  44. var z = (float)Math.Round(curPosition.z, Rounding);
  45. var boxCollider = gameObject.GetComponent<BoxCollider>();
  46. if (!move)
  47. {
  48. //transform.position = new Vector3(x, Height, z);
  49. boxCollider.size = new Vector3(x, Height, z);
  50. LocationController.Cube(gameObject, new Vector3(x, z, Height), new Vector2(start_pos.x, start_pos.z),0.05f);
  51. }
  52. else
  53. {
  54. start_pos = new Vector3(x, Height*0.5f, z);
  55. transform.position = start_pos;
  56. //var size = boxCollider.size;
  57. //start_pos = new Vector3(x - size.x/2, Height, z - size.z / 2);
  58. }
  59. }
  60. private void OnMouseUp()
  61. {
  62. //boxCollider.enabled=false;
  63. if (move) move = false;
  64. }
  65. }