public void Update() { if (!Operational) { return; } GetInputs.QueryInputSystem(); Vector3 START_POSITION = gameObject.transform.position; if (GetInputs.ResetMovement) { ResetMovement(); } else { float MAG = (GetInputs.isSlowModifier ? ControlKeyMagnification : 1f) * (GetInputs.isFastModifier ? ShiftKeyMagnification : 1f); if (GetInputs.isPanLeft) { _PanX.ChangeVelocity(0.7f * MAG * _Resolution * PanLeftRightSensitivity); } else if (GetInputs.isPanRight) { _PanX.ChangeVelocity(-0.7f * MAG * _Resolution * PanLeftRightSensitivity); } if (_PanX != null) { _PanX.Update(); } if (GetInputs.isMoveForward) { _Forward.ChangeVelocity(0.5f * MAG * _Resolution * MovementSpeedMagnification); } else if (GetInputs.isMoveBackward) { _Forward.ChangeVelocity(-0.5f * MAG * _Resolution * MovementSpeedMagnification); } if (GetInputs.isMoveForwardAlt) { _Forward.ChangeVelocity(0.5f * MAG * _Resolution * MovementSpeedMagnification * WheelMouseMagnification); } else if (GetInputs.isMoveBackwardAlt) { _Forward.ChangeVelocity(-0.5f * MAG * _Resolution * MovementSpeedMagnification * WheelMouseMagnification); } if (GetInputs.isPanUp) { _PanY.ChangeVelocity(0.7f * MAG * _Resolution * PanUpDownSensitivity); } else if (GetInputs.isPanDown) { _PanY.ChangeVelocity(-0.7f * MAG * _Resolution * PanUpDownSensitivity); } bool FORWARD_LOCK = GetInputs.isLockForwardMovement && ForwardMovementLockEnabled; _Forward.Update(!FORWARD_LOCK); _PanY.Update(); // Pan if (GetInputs.isRotateAction) { float X = (Input.mousePosition.x - GetInputs.RotateActionStart.x) / Screen.width * MouseRotationSensitivity; float Y = (Input.mousePosition.y - GetInputs.RotateActionStart.y) / Screen.height * MouseRotationSensitivity; _RotateX.SetVelocity(X * MAG * RotationMagnification * _Resolution); _RotateY.SetVelocity(Y * MAG * RotationMagnification * _Resolution); } _RotateX.Update(); _RotateY.Update(); } // Lock at object if (LookAtTarget != null) { transform.LookAt(LookAtTarget.transform); if (gameObject.GetComponent <UnityEngine.Camera>().fieldOfView < MinimumZoom) { ResetMovement(); gameObject.GetComponent <UnityEngine.Camera>().fieldOfView = MinimumZoom; } else if (gameObject.GetComponent <UnityEngine.Camera>().fieldOfView > MaximumZoom) { ResetMovement(); gameObject.GetComponent <UnityEngine.Camera>().fieldOfView = MaximumZoom; } } // Set ranges Vector3 END_POSITION = transform.position; if (LockX) { END_POSITION.x = START_POSITION.x; } if (LockY) { END_POSITION.y = START_POSITION.y; } if (LockZ) { END_POSITION.z = START_POSITION.z; } if (UseXRange && gameObject.transform.position.x < XRangeMin) { END_POSITION.x = XRangeMin; } if (UseXRange && gameObject.transform.position.x > XRangeMax) { END_POSITION.x = XRangeMax; } if (UseYRange && gameObject.transform.position.y < YRangeMin) { END_POSITION.y = YRangeMin; } if (UseYRange && gameObject.transform.position.y > YRangeMax) { END_POSITION.y = YRangeMax; } if (UseZRange && gameObject.transform.position.z < ZRangeMin) { END_POSITION.z = ZRangeMin; } if (UseZRange && gameObject.transform.position.z > ZRangeMax) { END_POSITION.z = ZRangeMax; } transform.position = END_POSITION; // Level Camera if (LevelCamera) { LevelTheCamera(); } }
public void Update() { if (!Operational) { return; } GetInputs.QueryInputSystem(); Vector3 START_POSITION = gameObject.transform.position; if (GetInputs.ResetMovement) { ResetMovement(); } else { float MAG = (GetInputs.isSlowModifier ? ControlKeyMagnification : 1f) * (GetInputs.isFastModifier ? ShiftKeyMagnification : 1f); if (GetInputs.isPanLeft) { _PanX.ChangeVelocity(0.01f * MAG * _Resolution * PanLeftRightSensitivity); } else if (GetInputs.isPanRight) { _PanX.ChangeVelocity(-0.01f * MAG * _Resolution * PanLeftRightSensitivity); } if (_PanX != null) { _PanX.Update(); } if (GetInputs.isMoveForward) { _Forward.ChangeVelocity(0.005f * MAG * _Resolution * MovementSpeedMagnification); } else if (GetInputs.isMoveBackward) { _Forward.ChangeVelocity(-0.005f * MAG * _Resolution * MovementSpeedMagnification); } if (GetInputs.isMoveForwardAlt) { _Forward.ChangeVelocity(0.005f * MAG * _Resolution * MovementSpeedMagnification * WheelMouseMagnification); } else if (GetInputs.isMoveBackwardAlt) { _Forward.ChangeVelocity(-0.005f * MAG * _Resolution * MovementSpeedMagnification * WheelMouseMagnification); } if (GetInputs.isPanUp) { _PanY.ChangeVelocity(0.005f * MAG * _Resolution * PanUpDownSensitivity); } else if (GetInputs.isPanDown) { _PanY.ChangeVelocity(-0.005f * MAG * _Resolution * PanUpDownSensitivity); } bool FORWARD_LOCK = GetInputs.isLockForwardMovement && ForwardMovementLockEnabled; _Forward.Update(!FORWARD_LOCK); _PanY.Update(); // Pan if (GetInputs.isRotateAction) { float X = (Input.mousePosition.x - GetInputs.RotateActionStart.x) / Screen.width * MouseRotationSensitivity; float Y = (Input.mousePosition.y - GetInputs.RotateActionStart.y) / Screen.height * MouseRotationSensitivity; _RotateX.SetVelocity(X * MAG * RotationMagnification * _Resolution); _RotateY.SetVelocity(Y * MAG * RotationMagnification * _Resolution); } _RotateX.Update(); _RotateY.Update(); } // Lock at object if (LookAtTarget != null) { transform.LookAt(LookAtTarget.transform); if (gameObject.GetComponent <UnityEngine.Camera>().fieldOfView < MinimumZoom) { ResetMovement(); gameObject.GetComponent <UnityEngine.Camera>().fieldOfView = MinimumZoom; } else if (gameObject.GetComponent <UnityEngine.Camera>().fieldOfView > MaximumZoom) { ResetMovement(); gameObject.GetComponent <UnityEngine.Camera>().fieldOfView = MaximumZoom; } } // Set ranges Vector3 END_POSITION = transform.position; if (LockX) { END_POSITION.x = START_POSITION.x; } if (LockY) { END_POSITION.y = START_POSITION.y; } if (LockZ) { END_POSITION.z = START_POSITION.z; } if (UseXRange && gameObject.transform.position.x < XRangeMin) { END_POSITION.x = XRangeMin; } if (UseXRange && gameObject.transform.position.x > XRangeMax) { END_POSITION.x = XRangeMax; } if (UseYRange && gameObject.transform.position.y < YRangeMin) { END_POSITION.y = YRangeMin; } if (UseYRange && gameObject.transform.position.y > YRangeMax) { END_POSITION.y = YRangeMax; } if (UseZRange && gameObject.transform.position.z < ZRangeMin) { END_POSITION.z = ZRangeMin; } if (UseZRange && gameObject.transform.position.z > ZRangeMax) { END_POSITION.z = ZRangeMax; } transform.position = END_POSITION; // Level Camera if (LevelCamera) { // Fix 1.2 // When leveling the camera you want to make sure you don't look straight up or straight down, otherwise the camera rolls wildly. // This code prevents this rolling from occurring. Vector3 ROT = gameObject.transform.rotation.eulerAngles; if (ROT.x > 180) { ROT.x -= 360; } if (ROT.x > (90 - LevelCameraAngleThreshold)) { ROT.x = (90 - LevelCameraAngleThreshold); gameObject.transform.rotation = Quaternion.Euler(ROT); } else if (ROT.x < (-90 + LevelCameraAngleThreshold)) { ROT.x = -90 + LevelCameraAngleThreshold; gameObject.transform.rotation = Quaternion.Euler(ROT); } LevelTheCamera(); } }