private void _keyPressed(FlyCamera flyCam) { if (Input.GetKeyDown(KeyCode.W)) { _flyCameraAction(flyCam, FlyCameraAction.Forward, 1); } if (Input.GetKeyDown(KeyCode.S)) { _flyCameraAction(flyCam, FlyCameraAction.Backword, 1); } if (Input.GetKeyDown(KeyCode.A)) { _flyCameraAction(flyCam, FlyCameraAction.Leftword, 1); } if (Input.GetKeyDown(KeyCode.D)) { _flyCameraAction(flyCam, FlyCameraAction.Rightword, 1); } if (Input.GetKeyDown(KeyCode.Q)) { _flyCameraAction(flyCam, FlyCameraAction.Lower, 1); } if (Input.GetKeyDown(KeyCode.E)) { _flyCameraAction(flyCam, FlyCameraAction.Rise, 1); } }
private void _keyReleased(FlyCamera flyCam) { if (Input.GetKeyUp(KeyCode.W)) { _flyCameraAction(flyCam, FlyCameraAction.Forward, 0); } if (Input.GetKeyUp(KeyCode.S)) { _flyCameraAction(flyCam, FlyCameraAction.Backword, 0); } if (Input.GetKeyUp(KeyCode.A)) { _flyCameraAction(flyCam, FlyCameraAction.Leftword, 0); } if (Input.GetKeyUp(KeyCode.D)) { _flyCameraAction(flyCam, FlyCameraAction.Rightword, 0); } if (Input.GetKeyUp(KeyCode.Q)) { _flyCameraAction(flyCam, FlyCameraAction.Lower, 0); } if (Input.GetKeyUp(KeyCode.E)) { _flyCameraAction(flyCam, FlyCameraAction.Rise, 0); } }
static void _wheelScrooled(FlyCamera flyCam) { float amount = Input.GetAxis("Mouse ScrollWheel"); if (amount > 0) { _flyCameraAction(flyCam, FlyCameraAction.ZoomIn, (float)amount); } else if (amount < 0) { _flyCameraAction(flyCam, FlyCameraAction.ZoomOut, -(float)amount); } }
static void _mouseMoved(FlyCamera flyCam, int x, int y) { if (Input.touchCount >= 1) { if (Input.touches[0].phase == TouchPhase.Began) { flyCam._leftMouseDown = true; flyCam._oldMouseX = x; flyCam._oldMouseY = y; } if (Input.touches[0].phase == TouchPhase.Ended) { flyCam._leftMouseDown = false; } if (Input.touches[0].phase == TouchPhase.Moved) { flyCam._oldMouseX = x; flyCam._oldMouseY = y; } } if (Input.GetKeyDown(KeyCode.Mouse1)) //if (Input.GetMouseButtonDown(0)) { flyCam._rightMouseDown = true; flyCam._oldMouseX = x; flyCam._oldMouseY = y; } if (Input.GetKeyUp(KeyCode.Mouse1)) // if (Input.GetMouseButtonUp(0)) { flyCam._rightMouseDown = false; } if (Input.GetKeyDown(KeyCode.Mouse0)) //if (Input.GetMouseButtonDown(0)) { flyCam._leftMouseDown = true; flyCam._oldMouseX = x; flyCam._oldMouseY = y; } if (Input.GetKeyUp(KeyCode.Mouse0)) // if (Input.GetMouseButtonUp(0)) { flyCam._leftMouseDown = false; } float aspect = 1; //flyCam._camera.aspect; if (flyCam._rightMouseDown && (flyCam._oldMouseX != x || flyCam._oldMouseY != y)) { int offsetX = x - flyCam._oldMouseX; int offsetY = y - flyCam._oldMouseY; if (offsetX > 0) { _flyCameraAction(flyCam, FlyCameraAction.Right, offsetX / 10.0f); } else { _flyCameraAction(flyCam, FlyCameraAction.Left, -offsetX / 10.0f); } if (offsetY > 0) { _flyCameraAction(flyCam, FlyCameraAction.Down, offsetY / 10.0f / aspect); } else { _flyCameraAction(flyCam, FlyCameraAction.Up, -offsetY / 10.0f / aspect); } } if (flyCam._leftMouseDown && (flyCam._oldMouseX != x || flyCam._oldMouseY != y)) { int offsetX = x - flyCam._oldMouseX; int offsetY = y - flyCam._oldMouseY; Vector3 dir = new Vector3(offsetX, 0, offsetY); float len = dir.magnitude; dir.Normalize(); Vector3 horizontalCamDir = new Vector3(flyCam.transform.forward.x, 0, flyCam.transform.forward.z).normalized; Vector3 originalDir = new Vector3(0, 0, 1); Quaternion q = Quaternion.FromToRotation(originalDir, horizontalCamDir); Vector3 tmp = -(q * dir); flyCam._dragDir = new Vector2(tmp.x, tmp.z); _flyCameraAction(flyCam, FlyCameraAction.Drag, len * 0.2f); } flyCam._oldMouseX = x; flyCam._oldMouseY = y; }
static void _flyCameraAction(FlyCamera flyCam, FlyCameraAction action, float value) { flyCam._actionStatus[(int)action] = value; }