using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class ObjectToCameraWatch : MonoBehaviour { private ViewType vievType; public Transform upDown; public Transform arrowLeft; public Transform arrowRight; public Transform arrowFront; public Transform arrowBack; private Transform mainObject; private Camera camera; private float offsetToArrow = 1.5f; private float upfloor = 0.01f; private Transform rotateArrows; private Transform rotateArrowsBack; private Vector3 modelSize; private bool isInit = false; private bool isRotate; public void Initialize(Vector3 arrowScale, Transform arrows, Transform arrowsBack) { vievType = BuildingRoom.Instance.ViewType; camera = Camera.main; mainObject = GetComponentInChildren().parent.transform; modelSize = BuildingRoom.Instance.ModelSize; arrowFront.rotation = Quaternion.Euler(0, 0, 0); arrowBack.rotation = Quaternion.Euler(0, 180, 0); arrowLeft.rotation = Quaternion.Euler(0, 90, 0); arrowRight.rotation = Quaternion.Euler(0, -90, 0); Vector3 frontPosition = mainObject.position + Vector3.back * (modelSize.z / offsetToArrow); Vector3 backPosition = mainObject.position - Vector3.back * (modelSize.z / offsetToArrow); Vector3 leftPosition = mainObject.position - Vector3.right * (modelSize.x/ offsetToArrow); Vector3 rightPosition = mainObject.position + Vector3.right * (modelSize.x / offsetToArrow); rotateArrows = arrows; rotateArrowsBack = arrowsBack; frontPosition.y += upfloor; backPosition.y += upfloor; leftPosition.y += upfloor; rightPosition.y += upfloor; arrowFront.position = frontPosition; arrowBack.position = backPosition; arrowLeft.position = leftPosition; arrowRight.position = rightPosition; ArrowsScale(arrowScale); isInit = true; } private void LateUpdate() { if (!isInit) return; Vector3 newPosition = mainObject.position; newPosition.y += 1f; upDown.position = newPosition; upDown.rotation = Quaternion.Euler(90, camera.transform.eulerAngles.y, upDown.rotation.z); if (!isRotate) return; Vector3 mouseScreenPosition = Input.mousePosition; mouseScreenPosition.z = Vector3.Distance(Camera.main.transform.position, mainObject.position); Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(mouseScreenPosition); Vector3 direction = mouseWorldPosition - mainObject.position; direction.y = 0; } public void ChangeViewType(ViewType currentType) { vievType = currentType; camera = Camera.main; if (vievType != ViewType.ThreeD) { upDown.gameObject.SetActive(false); } else if(vievType == ViewType.Walk) { gameObject.SetActive(false); } else { upDown.gameObject.SetActive(true); } } public void ArrowsScale(Vector3 scale) { scale = new Vector3(scale.x + 1f, scale.y + 1f, scale.z + 1f); arrowBack.localScale = scale; arrowFront.localScale = scale; arrowLeft.localScale = scale; arrowRight.localScale = scale; upDown.localScale = scale / 2; rotateArrows.localScale = scale; rotateArrowsBack.localScale = scale; } public void SetArrowsRottation(bool rotate) { isRotate = rotate; } }