// Use this for initialization void Start() { Cursor.lockState = CursorLockMode.Confined; mMode = mouseMode.Nothing; lvE = GameObject.FindObjectOfType <LevelEditor>(); ev = GameObject.Find("EventSystem").GetComponent <EventSystem>(); xFormCamera = this.transform; xFormParent = this.transform.parent; }
// Update is called once per frame void LateUpdate() { if (lvE == null) { lvE = GameObject.FindObjectOfType <LevelEditor>(); } if (lvE.blockSelected == false && lvE.inEditor && ev.IsPointerOverGameObject() == false) { //ORBITING if (Input.GetKey(KeyCode.Mouse2) && Input.GetKey(KeyCode.LeftShift) == false && Input.GetKey(KeyCode.RightShift) == false) { //Rotate camera based on mouse coordinates if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0) { localRotation.x += Input.GetAxis("Mouse X") * mouseSensitivity; localRotation.y -= Input.GetAxis("Mouse Y") * mouseSensitivity; //Clamp values to horizon and not flipping localRotation.y = Mathf.Clamp(localRotation.y, 1f, 90f); dothis = true; } } //Zooming if (Input.GetAxis("Mouse ScrollWheel") != lastScroll) { mMode = mouseMode.Zooming; float scrollAmount = Input.GetAxis("Mouse ScrollWheel") * scrollSensitivity; lastScroll = scrollAmount; scrollAmount *= cameraDistance * 0.3f; cameraDistance += scrollAmount * -1f; cameraDistance = Mathf.Clamp(cameraDistance, 1.5f, 1000f); dothis = true; } if (dothis) { //Camera transformations Quaternion qt = Quaternion.Euler(localRotation.y, localRotation.x, 0); xFormParent.rotation = Quaternion.Lerp(xFormParent.rotation, qt, Time.deltaTime * orbitDampening); if (xFormCamera.localPosition.z != cameraDistance * -1f) { xFormCamera.localPosition = new Vector3(0f, 0f, Mathf.Lerp(xFormCamera.localPosition.z, cameraDistance * -1f, Time.deltaTime * scrollDampening)); } dothis = false; } //Vector3 pos = transform.position; //if (Input.GetKey(KeyCode.W) || Input.mousePosition.y >= (Screen.height - panBorderThickness)) //{ // pos.z += panSpeed * Time.deltaTime; //} //if (Input.GetKey(KeyCode.S) || Input.mousePosition.y <= panBorderThickness) //{ // pos.z -= panSpeed * Time.deltaTime; //} //if (Input.GetKey(KeyCode.D) || Input.mousePosition.x >= (Screen.width - panBorderThickness)) //{ // pos.x += panSpeed * Time.deltaTime; //} //if (Input.GetKey(KeyCode.A) || Input.mousePosition.x <= panBorderThickness) //{ // pos.x -= panSpeed * Time.deltaTime; //} //float scroll = Input.GetAxis("Mouse ScrollWheel"); //pos.y += -scroll * scrollSpeed * 100 * Time.deltaTime; //pos.y = Mathf.Clamp(pos.y, minScroll, maxScroll); //pos.x = Mathf.Clamp(pos.x, -bounds.x, bounds.x); //pos.z = Mathf.Clamp(pos.z, -bounds.y, bounds.y); //transform.position = pos; } }