private void Update() { if (GameManager.Instance.currentState == GameManager.GameState.LevelEditor) { #if UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_EDITOR GetCameraInputs(); #else if (isControlActive) { GetCameraInputs(); } #endif //Makes sure you can't zoom in / out too much. Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize, _baseSize, _baseSize * 3); Vector3 scale = transform.localScale; scale.x = Camera.main.orthographicSize / _baseSize; scale.y = scale.x; transform.localScale = scale; //After moving the camera, checks if it's still inside the gameview. CheckBoundaries(); UpdateGrid(); } //Maps interfaces can't zoom. only level editor else if (GameManager.Instance.currentState == GameManager.GameState.Map) { //Camera movement. if (LevelEditorInputs.GetCameraLeft()) { transform.Translate(Vector2.left * _translationSpeed * Time.deltaTime); } if (LevelEditorInputs.GetCameraRight()) { transform.Translate(Vector2.right * _translationSpeed * Time.deltaTime); } //Screen base size float baseSize = _gameviewSize / 2f * Screen.height / Screen.width; Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize, baseSize, baseSize * 3); CheckBoundaries(); } }
private void GetCameraInputs() { if (LevelEditorInputs.GetCameraUp(isDraging)) { Camera.main.transform.Translate(Vector2.up * _translationSpeed * Time.deltaTime); } if (LevelEditorInputs.GetCameraLeft(isDraging)) { Camera.main.transform.Translate(Vector2.left * _translationSpeed * Time.deltaTime); } if (LevelEditorInputs.GetCameraDown(isDraging)) { Camera.main.transform.Translate(Vector2.down * _translationSpeed * Time.deltaTime); } if (LevelEditorInputs.GetCameraRight(isDraging)) { Camera.main.transform.Translate(Vector2.right * _translationSpeed * Time.deltaTime); } //Zoom in/out. Camera.main.orthographicSize -= LevelEditorInputs.GetZoomIn() * _zoomSensitivity * Time.deltaTime; Camera.main.orthographicSize += LevelEditorInputs.GetZoomOut() * _zoomSensitivity * Time.deltaTime; }