12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class RoomController : MonoBehaviour
- {
- public float Height = 1f;
- public int Rounding = 1;
- public bool move = true;
- public bool BoxColliderEnabled = true;
-
- private Vector3 screenPoint;
- private Vector3 offset;
- private Vector3 curScreenPoint;
- private Vector3 curPosition;
- public Vector3 start_pos = Vector3.zero;
-
- void Start()
- {
- gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
-
- }
-
- void Update()
- {
- if (gameObject.GetComponent<BoxCollider>().enabled != BoxColliderEnabled) gameObject.GetComponent<BoxCollider>().enabled = BoxColliderEnabled;
- }
- void OnMouseDown()
- {
-
-
- screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
- offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
-
- }
-
-
- void OnMouseDrag()
- {
- curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
- curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
- var x = (float)Math.Round(curPosition.x, Rounding);
- var z = (float)Math.Round(curPosition.z, Rounding);
- var boxCollider = gameObject.GetComponent<BoxCollider>();
- if (!move)
- {
-
-
- boxCollider.size = new Vector3(x, Height, z);
-
- LocationController.Cube(gameObject, new Vector3(x, z, Height), new Vector2(start_pos.x, start_pos.z),0.05f);
- }
- else
- {
- start_pos = new Vector3(x, Height*0.5f, z);
- transform.position = start_pos;
-
-
- }
-
- }
- private void OnMouseUp()
- {
-
- if (move) move = false;
- }
- }
|