private void UpdateDrag() { var fingers = LeanTouch.GetFingers(true); bool isDrag = fingers != null && fingers.Count > 0; if (isDrag) { var finger = fingers[0]; if (finger.Down) { velocity = Vector3.zero; } else if (finger.Set) { var worldDelta = finger.GetWorldDelta(distance, camera); if (worldDelta.sqrMagnitude > 0.01f) { Vector3 oldPos = target.position; Vector3 newPos = ClampTargetToPos(oldPos - worldDelta); velocity = newPos - oldPos; } else { velocity = Vector3.zero; } } } else if (velocity.sqrMagnitude > 0.01f) { ClampTargetToPos(target.position + velocity); velocity = Vector3.Lerp(velocity, Vector3.zero, Time.deltaTime * dampening); } }
/// <summary> /// Generic Zoom Controls /// </summary> protected virtual void ZoomPinchControls(bool ignoreGUI = true) { if (timeSingle > .1f) { return; } List <LeanFinger> fingers = LeanTouch.GetFingers(ignoreGUI); if (ViewingScope) { float pinchRadius = LeanGesture.GetPinchRatio(fingers, -.1f) - 1; if (Mathf.Abs(pinchRadius) > 0) { isZooming = true; } else { isZooming = false; } ScopeCamera.fieldOfView += pinchRadius * ZoomSpeed; ScopeCamera.fieldOfView = Mathf.Clamp(ScopeCamera.fieldOfView, MinZoom, MaxZoom); } }
public float GetPinchRatio() { List <LeanFinger> fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); float pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); return(pinchRatio); }
private void Update() { var fingers = LeanTouch.GetFingers(false, false); if (fingers.Count == 0) { return; } if (fingers.Count > 1) { var twistDegrees = LeanGesture.GetTwistDegrees(fingers); transform.Rotate(0, 0, twistDegrees); } else { var finger = fingers[0]; if (finger.Down) { _offset = finger.GetWorldPosition(_cameraDistance, _camera) - transform.position; } else { var position = transform.position; var dragPosition = finger.GetWorldPosition(_cameraDistance, _camera); if (Mathf.Abs(dragPosition.x - transform.position.x) <= _maxInputDistance) { dragPosition -= _offset; position.y = Mathf.Clamp(dragPosition.y, -4.5f, 4.5f); transform.position = position; } } } }
//This function moves the rigidbody of the explosive by first verifying the user is touching the explosive. // Once the variable isTouching is true, the Rigidbody moves accordingly. The big shift (1 << 10) refers to the // 10th layer in the scene which is dedicated to Objects in the scene. void MoveObject() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); if (fingers.Count == 1 && fingers[0].IsActive == true) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rayHit; if (Physics.Raycast(ray, out rayHit, Mathf.Infinity, 1 << 10 | 1 << 11)) { if (rb != null) { Debug.DrawRay(ray.origin, ray.direction * 100); explosive.transform.position = rayHit.point; //explosive.GetComponent<MeshRenderer>().material = material_color_original; if (rayHit.collider.gameObject.layer == 11) //Is the explosive out of bounds? { //Debug.Log("Out of bounds!"); //explosive.GetComponent<MeshRenderer>().material = material_color_red; inBoundsPos = Vector3.zero; } else { inBoundsPos = rb.transform.position; } } } } }
/// <summary> /// 获取缩放值 /// 触屏中取代鼠标中轮 /// </summary> /// <returns></returns> public float GetPinchRatio() { List <LeanFinger> fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); float pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); LogMgr.I("TouchMgr", "GetPinchRatio", "缩放 pinchRatio:" + pinchRatio, BeShowLog); return(1f - pinchRatio); }
private void HandleInput() { var touches = LeanTouch.GetFingers(true, false, 1); if (touches == null || touches.Count == 0) { return; } if (touches[0].Down) { var ray = WorldCamera.ScreenPointToRay(touches[0].ScreenPosition); Debug.DrawRay(ray.origin, ray.direction * 20); if (Physics.Raycast(ray, out RaycastHit hit, 20, ~(1 << 2)) && hit.collider.GetComponent <KinematicBlock>()) { var kb = hit.collider.GetComponent <KinematicBlock>(); var block = kb.GetOrientedBlock(out Vector2Int pos); if ( CheckAlphaKey(kb, KeyCode.Alpha0, 0) || CheckAlphaKey(kb, KeyCode.Alpha1, 1) || CheckAlphaKey(kb, KeyCode.Alpha2, 2) || CheckAlphaKey(kb, KeyCode.Alpha3, 3) || CheckAlphaKey(kb, KeyCode.Alpha4, 4) || CheckAlphaKey(kb, KeyCode.Alpha5, 5) || CheckAlphaKey(kb, KeyCode.Alpha6, 6) || CheckAlphaKey(kb, KeyCode.Alpha7, 7) || CheckAlphaKey(kb, KeyCode.Alpha8, 8) ) { return; } if (Input.GetKey(KeyCode.LeftShift)) { kb = kb.Clone(); } else { for (int x = 0; x < block.Width; x += 1) { for (int y = 0; y < block.Height; y += 1) { if (block.IsFieldSet(x, y)) { Explode(pos.x + x, pos.y - y); x += block.Width; break; } } } kinematicBlocks.Remove(kb); Reserialize(); } kb.Activate(touches[0], hit); } } }
public Vector2 GetScreenDelta() { List <LeanFinger> fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); Vector2 lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers); Vector2 screenPoint = LeanGesture.GetScreenCenter(fingers); ScreenDelta = screenPoint - lastScreenPoint; return(ScreenDelta); }
protected override void LateUpdate() { // Make sure the camera exists if (LeanTouch.GetCamera(Camera, gameObject) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Modify the zoom value Zoom *= pinchRatio; if (ZoomClamp == true) { Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax); } //Масштаб SetZoom(); // Get the scaled average movement vector of these fingers var drag = LeanGesture.GetScaledDelta(fingers); // Get base sensitivity var sensitivity = GetSensitivity(); // Adjust pitch if (usePitch) { Pitch += drag.y * PitchSensitivity * sensitivity; if (PitchClamp == true) { Pitch = Mathf.Clamp(Pitch, PitchMin, PitchMax); } } else { Pitch = 0.0f; } // Adjust yaw if (useYaw) { Yaw -= drag.x * YawSensitivity * sensitivity; if (YawClamp == true) { Yaw = Mathf.Clamp(Yaw, YawMin, YawMax); } } else { Yaw = 0.0f; } //Поворот SetRotation(); } ApplyTargetPosition(); }
// Drags with fingers to rotate void DragAndRotate() { // Drag and Rotate object var leanFingers = LeanTouch.GetFingers(true, false, 0); var screenDelta = Vector2.zero; // Rotate if (leanFingers.Count == 1) { screenDelta = LeanGesture.GetScreenDelta(leanFingers); } // For linear interpolation purpose only. actualRot = Vector3.Lerp(actualRot, screenDelta, Time.deltaTime * 20.0f); // if do not want to use linear interpolation // actualRot = dist; if (gameObject.name == "king" || gameObject.name == "queen") { // For 180 Degree Rotation transform.Rotate(0, -actualRot.x / 4.0f, 0, Space.Self); } else { // For 360 Degree Rotation transform.Rotate(actualRot.y / 4.0f, 0, 0, Space.World); // For local space rotation transform.Rotate(0, -actualRot.x / 4.0f, 0, Space.Self); } // For scalling sun if (gameObject.name == "sun") { var scale = transform.GetChild(0).transform.localScale; var twoFingers = LeanTouch.GetFingers(true, true, 2); var pinchScale = LeanGesture.GetPinchScale(twoFingers, 0); scale *= pinchScale; scale.x = Mathf.Clamp(scale.x, scaleMin, scaleMax); scale.y = Mathf.Clamp(scale.y, scaleMin, scaleMax); scale.z = Mathf.Clamp(scale.z, scaleMin, scaleMax); transform.GetChild(0).transform.localScale = scale; } // For scalling other object. else { GetComponent <LeanScale>().ScaleMin = new Vector3(scaleMin, scaleMin, scaleMin); GetComponent <LeanScale>().ScaleMax = new Vector3(scaleMax, scaleMax, scaleMax); } }
protected override void LateUpdate() { // Make sure the camera exists if (LeanTouch.GetCamera(Camera, gameObject) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the pinch ratio of these fingers var pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Modify the zoom value Zoom *= pinchRatio; if (ZoomClamp == true) { Zoom = Mathf.Clamp(Zoom, ZoomMin, ZoomMax); } //Масштаб SetZoom(); // Get the scaled average movement vector of these fingers var drag = LeanGesture.GetScaledDelta(fingers); // Get base sensitivity var sensitivity = GetSensitivity(); //Ось AxisX if (useAxisX) { AxisX -= drag.x * (AxisXSensitivity / sensitivity); if (AxisXClamp == true) { AxisX = Mathf.Clamp(AxisX, AxisXMin, AxisXMax); } } else { AxisX = 0.0f; } //Ось AxisY if (useAxisY) { AxisY += drag.y * (AxisYSensitivity / sensitivity); if (AxisYClamp == true) { AxisY = Mathf.Clamp(AxisY, AxisYMin, AxisYMax); } } else { AxisY = 0.0f; } //Смещение SetPosition(); } }
/// <summary> /// 获取拖动或旋转值 /// </summary> /// <returns></returns> public Vector2 GetScreenDelta() { List <LeanFinger> fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); Vector2 lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers); Vector2 screenPoint = LeanGesture.GetScreenCenter(fingers); ScreenDelta = screenPoint - lastScreenPoint; LogMgr.I("TouchMgr", "GetScreenDelta", "拖动 ScreenDelta:" + ScreenDelta, BeShowLog); return(ScreenDelta); }
private void Rotate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(_ignoreGuiFingers, 1); // Calculate the screenDelta value based on these fingers var screenDelta = LeanGesture.GetScreenDelta(fingers) * _rotationSens; _transform.RotateAround(_transform.position, Vector3.up, -screenDelta.x); _transform.RotateAround(_transform.position, Vector3.right, screenDelta.y); }
protected virtual void Update() { if (!IsRotatable || RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); var center = LeanGesture.GetScreenCenter(fingers); var degrees = LeanGesture.GetTwistDegrees(fingers); Rotate(center, degrees); }
protected virtual void FixedUpdate() { /* if (ball.IsOnSpawn) * return; */ var fingers = LeanTouch.GetFingers(false, false, 0); if (fingers.Count > 0) { targetPoint = LeanGesture.GetScreenCenter(fingers); newPosition = Camera.main.ScreenToWorldPoint(new Vector3(targetPoint.x, targetPoint.y, -Camera.main.transform.position.z)); newPosition.y = transform.position.y; newPosition.x = Mathf.Clamp(newPosition.x, leftLimit.position.x, rightLimit.position.x); factor = LeanTouch.GetDampenFactor(Dampening, Time.fixedDeltaTime); } transform.position = Vector3.Lerp(transform.position, newPosition, factor); }
protected virtual void Update() { if (!IsDraggable || (RequiredSelectable != null && RequiredSelectable.IsSelected == false)) { return; } if (BeenDragged) { GetComponent <SpriteRenderer>().sortingOrder = _startingLayer - 1; } var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount, RequiredSelectable); var screenDelta = LeanGesture.GetScreenDelta(fingers); Translate(screenDelta); }
protected virtual void LateUpdate() { if (!CanvasManager.IsGuiOpened) { // Get the fingers we want to use List <LeanFinger> fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); //MOVEMENT // Get the world delta of all the fingers Vector3 worldDelta = LeanGesture.GetWorldDelta(fingers, Distance, Camera); // Pan the camera based on the world delta RemainingDelta -= worldDelta; // The framerate independent damping factor System.Single factor = Mathf.Exp(-Dampening * Time.deltaTime); // Dampen remainingDelta Vector3 newDelta = RemainingDelta * factor; // Shift this transform by the change in delta transform.position += RemainingDelta - newDelta; // Update remainingDelta with the dampened value RemainingDelta = newDelta; //MOVEMENT //ZOOM // Scale the current value based on the pinch ratio Target *= LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Clamp the current value to min/max values Target = Mathf.Clamp(Target, Minimum, Maximum); // The framerate independent damping factor System.Single factorZoom = 1.0f - Mathf.Exp(-Dampening * Time.deltaTime); // Store the current size/fov in a temp variable var current = GetCurrent(); current = Mathf.Lerp(current, Target, factorZoom); SetCurrent(current); //ZOOM } }
//This function casts its own ray on explosives. This indicates whether the explosive is being touched by the user. // It then is consistently changing the global variable isTouching according to if there is a hit or not. // The bit shift (1 << 9) refers to the 9th layer in the scene [CurrentSelected] (explosive). void TouchObject() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); if (fingers.Count == 1 && fingers[0].IsActive == true) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit rayHit; if (Physics.Raycast(ray, out rayHit, Mathf.Infinity, 1 << 9 | 1 << 5)) { isTouching = true; explosive = rayHit.collider.gameObject; //Sets the explosive to which ever one is being selected. rb = explosive.GetComponent <Rigidbody>(); //Sets the rigidbody to the selected explosive. } } }
protected virtual void LateUpdate() { var fingers = LeanTouch.GetFingers(false, false, 1); if (fingers.Count >= 1) { _currentFrameTouchEnabled = true; var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers); var screenPoint = LeanGesture.GetScreenCenter(fingers); var worldDelta = lastScreenPoint - screenPoint; if (worldDelta.x > 0) { MoveLeft(Mathf.Abs(worldDelta.x)); } else if (worldDelta.x < 0) { MoveRight(Mathf.Abs(worldDelta.x)); } Shoot(); } else { _currentFrameTouchEnabled = false; } if (_prevFrameTouchEnabled && !_currentFrameTouchEnabled && GameManager.GameStarted) { Jump(); } if (!_prevFrameTouchEnabled && !_currentFrameTouchEnabled && !GameManager.GameStarted) { GameManager.GameStarted = true; } if (!_prevFrameTouchEnabled && _currentFrameTouchEnabled && !GameManager.GameStarted) { return; //if (!GameManager.GameStarted) GameManager.GameStarted = true; } _prevFrameTouchEnabled = _currentFrameTouchEnabled; }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel translation // if ((RequiredSelectable != null && RequiredSelectable.IsSelected == false) && !ModelManager._instance) // { // return; // } if ((RequiredSelectable != null && RequiredSelectable.IsSelected == false)) { return; } // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Calculate the screenDelta value based on these fingers var screenDelta = LeanGesture.GetScreenDelta(fingers); // Perform the translation Translate(screenDelta); }
private bool Scale() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(_ignoreGuiFingers, 2); // Calculate the scaling values based on these fingers var scale = LeanGesture.GetPinchScale(fingers, 0); if (scale == 1) { return(false); } float newScale = _camera.fieldOfView / scale; newScale = Mathf.Clamp(newScale, 5, _maxFoV); _camera.fieldOfView = newScale; var degrees = LeanGesture.GetTwistDegrees(fingers); _transform.RotateAround(_transform.position, Vector3.forward, degrees); return(true); }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel translation if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount, RequiredSelectable); // Calculate the screenDelta value based on these fingers var screenDelta = LeanGesture.GetScreenDelta(fingers); //Swipe Left or Right if (screenDelta.x < -Mathf.Abs(screenDelta.y) || screenDelta.x > Mathf.Abs(screenDelta.y)) { Translate(screenDelta); } // Perform the translation //sTranslate(screenDelta); }
protected virtual void LateUpdate() { var fingers = LeanTouch.GetFingers(false, false, 1); if (fingers.Count < 1) { return; } var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers); var screenPoint = LeanGesture.GetScreenCenter(fingers); var worldDelta = lastScreenPoint - screenPoint; if (worldDelta.x < 0) { MoveLeft(Mathf.Abs(worldDelta.x)); } else if (worldDelta.x > 0) { MoveRight(Mathf.Abs(worldDelta.x)); } Shoot(); }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel the translation if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Obtain the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount, RequiredSelectable); // Calculate the screenDelta value based on these fingers var screenDelta = LeanGesture.GetScreenDelta(fingers); // Calculate the rotation values based on these fingers var center = LeanGesture.GetScreenCenter(fingers); var degrees = LeanGesture.GetTwistDegrees(fingers); // Perform the rotation Rotate(center, degrees); // Perform the translation Translate(screenDelta); }
protected override void Update() { base.Update(); ShowMessage("CameraAngle", "Camera Angle : " + CameraRotation.ToString()); ShowMessage("Scope", "Toggle Scope : " + Convert.ToInt32(ViewingScope)); ShowMessage("Fire", "Fire : " + Convert.ToInt32(IsFiring)); ShowMessage("Reloading", "Is Reloading: " + Convert.ToInt32(isReloading)); ShowMessage("MiniReloading", "Is Reloading While In Scope: " + Convert.ToInt32(isMiniReloading)); ShowMessage("Supercharged", "Supercharged : " + Convert.ToInt32(isSupercharged)); txtReload.text = string.Format("{0:00}", currentAmmo); UpdateHealth(); RotationControls(); if (IsUserControllable) { bool prevPanning = panning; List <LeanFinger> fingers = LeanTouch.GetFingers(false); if (fingers.Count > 0) { if (canSwitch) { Ray ray = fingers[0].GetRay(); RaycastHit hit = default(RaycastHit); if (isDraggingZoom && ViewingScope) { panning = false; canSwitch = false; } else { panning = true; } } if (!panning) { Vector2 delta = LeanGesture.GetScreenDelta(fingers) * ZoomSpeed * Time.deltaTime; ScopeCamera.fieldOfView -= delta.y; ScopeCamera.fieldOfView = Mathf.Clamp(ScopeCamera.fieldOfView, MinZoom, MaxZoom); //For 60 degrees of rotation float zRot; if (SniperPrimaryHand == PrimaryHand.RightHanded) { zRot = Zoom * .6f; } else { zRot = -Zoom * .6f; } //Also adjust the progress bar Transform scopeCenter = ScopeUICenter.transform; scopeCenter.localEulerAngles = new Vector3(scopeCenter.localEulerAngles.x, scopeCenter.localEulerAngles.y, zRot); } } //Powerups Update if (isRechargingHealth) { Health += Time.deltaTime * HealthRegenSpeed; //No need to clamp - handled by UpdateHealth } string zm = string.Format("X{0:00}", GetZoomFrom(0, 4)); txtZoom.text = zm; } }
protected override void Update() { base.Update(); txtReload.text = currentAmmo + "/" + AmmoPerClip; ShowMessage("Reloading", "Is Reloading: " + Convert.ToInt32(isReloading)); ShowMessage("MiniReloading", "Is Adjusting Gun: " + Convert.ToInt32(isMiniReloading)); if (Target != null && (Target.GetComponent <Enemy>() && Target.GetComponent <Enemy>().Alive)) { if (Physics.Raycast(ScopeCamera.transform.position, ScopeCamera.transform.forward)) { distanceToTarget = Vector3.Distance(BulletSpawnLocation.position, Target.transform.position); } else { distanceToTarget = 0; } txtDistanceToTarget.text = Mathf.Round(distanceToTarget) + "m"; } else { txtDistanceToTarget.text = ""; } if (IsUserControllable) { ZoomPinchControls(false); if (!isReloading) { RotationControls(false, true); } //Time Freeze output ShowMessage("TimeFreeze", "Time Freeze : " + Convert.ToInt32(InTimeFreezeMode)); if (isReloading) { ReloadQuicktime(); } List <LeanFinger> fingers = LeanTouch.GetFingers(false); if (fingers.Count > 0 && !isMiniReloading && CanAutoFire) { if (LeanGesture.GetScreenDelta().magnitude > 0 || isZooming) { panning = true; } Ray ray = fingers[0].GetRay(); RaycastHit hit = default(RaycastHit); if (Physics.Raycast(ray, out hit, LayerMask.NameToLayer(ScopeLayerName)) && !panning) { //Check if we should exit scope mode if (hit.transform.gameObject.layer != LayerMask.NameToLayer(TouchableLayerName)) { fireTime += Time.deltaTime; if (fireTime >= TimeBetweenShots) { OnFireBegin(); fireTime = 0; } } } } } }
protected override void RotationControls(bool ignoreGUI = true, bool linear = false) { if (isZooming) { return; } //For smooth rotation Vector3 prevEuler = new Vector3(xRot, yRot, 0); List <LeanFinger> fingers = LeanTouch.GetFingers(true); float sens = RotationSensitivity; if (ViewingScope) { if (Zoom != 0) { sens = RotationSensitivity * InvZoom(Zoom, .25f); } else { sens = RotationSensitivity; } } //Change in finger position (sliding) Vector2 delta = LeanGesture.GetScreenDelta(fingers) * sens; //For the x rotation, we don't use the Camera's euler angles directly. //We initialize xRot to zero before this method (since we're using localEulerAngles), then we constanly subtract delta.y //Then we clamp that independent value, and apply to the localEulerAngles. //Inspired from joel_b on http://answers.unity3d.com/questions/18680/limiting-rotation-of-an-object.html if (panning) { xRot -= delta.y; yRot += delta.x; } if (RestrictXRotation) { xRot = WrapAngle(Mathf.Clamp(xRot, MinXRotation, MaxXRotation)); } if (RestrictYRotation) { yRot = WrapAngle(Mathf.Clamp(yRot, MinYRotation, MaxYRotation)); } // //Root.transform.rotation = Quaternion.Euler(); if (ExtraSmooth) { Quaternion look = Quaternion.Euler(new Vector3(xRot, yRot, 0)); if (RotationSmooth != -1) { Root.rotation = Quaternion.Slerp(Root.rotation, look, RotationSmooth); } else { Root.rotation = Quaternion.Slerp(Root.rotation, look, RotationSensitivity); } } else { if (RotationSmooth != -1) { Root.transform.eulerAngles = Vector3.Lerp(prevEuler, new Vector3(xRot, yRot, 0), RotationSmooth); } else { Root.transform.eulerAngles = Vector3.Lerp(prevEuler, new Vector3(xRot, yRot, 0), RotationSensitivity); } } ShowMessage("CameraAngle", "Camera Angle : " + CameraRotation.ToString()); }
void LateUpdate() { //if (IgnoreTouch) //{ // return; //} isMoved = false; Vector3 beforeMove = transform.position; bool zoomed = touchZoom(); if (!zoomed && !freezeMove) { if (isSnapMove) { beginMove(); if (isSmoothMove) { transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime, snapMoveMutiply); } else { transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * snapMoveMutiply); } updateCameraRect(); if (isMovedToTarget()) { endMove(); isSnapMove = false; } } else if (isSwipeMove) { beginMove(); transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); updateCameraRect(); if (isMovedToTarget()) { endMove(); isSwipeMove = false; } } else if (isFingerSet) { // isFingerDown = false; var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, 1); var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers); var screenPoint = LeanGesture.GetScreenCenter(fingers); var worldDelta = ScreenDepth.ConvertDelta(lastScreenPoint, screenPoint, Camera, gameObject); if (worldDelta != Vector3.zero) { beginMove(); transform.position -= worldDelta; updateCameraRect(); } } } if (isSnapZoom && !freezeZoom) { if (isSmoothZoom) { //snapZoomMutiply *= ((ZoomSteps+1) * (ZoomSteps + 1) / Mathf.Pow(Mathf.Abs(targetSize - currentSize)+1, 1)); ZoomSteps += Time.deltaTime; //currentSize = Mathf.SmoothStep(currentSize, targetSize, Time.deltaTime * snapZoomMutiply); currentSize = SineEaseOut(ZoomSteps, ZoomStart, targetSize - ZoomStart, snapZoomMutiply); } else { currentSize = Mathf.Lerp(currentSize, targetSize, Time.deltaTime * snapZoomMutiply); } SetZoom(); if (Mathf.Abs(currentSize - targetSize) < 0.01f) { currentSize = targetSize; SetZoom(); zoomed = true; endZoom(); isSnapZoom = false; } } if (isMoved || zoomed) { actualMoveDelta = transform.position - beforeMove; if (scrollZoomEvent != null) { scrollZoomEvent.OnViewRectChange(); } } }
protected virtual void LateUpdate() { if (!_isActive) { return; } var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); var screenDelta = LeanGesture.GetScreenDelta(fingers); screenDelta.x /= Screen.width; screenDelta.y /= Screen.height; var oldPosition = _transform.localPosition; _transform.Translate(new Vector3(screenDelta.x, 0f, screenDelta.y) * MoveSensitivity, Space.Self); _moveRemainingDelta += _transform.localPosition - oldPosition; if (_camera.orthographic) { _moveRemainingDelta.y = 0f; } var factor = LeanTouch.GetDampenFactor(MoveDampening, Time.deltaTime); var newDelta = Vector3.Lerp(_moveRemainingDelta, Vector3.zero, factor); _transform.localPosition = oldPosition + _moveRemainingDelta - newDelta; _isMoving = screenDelta.sqrMagnitude > 0.1f; _moveRemainingDelta = newDelta; if (_transform.position.x < _limitsOffset.x + _limitsX.x || _transform.position.x > _limitsOffset.x + _limitsX.y) { var limitedPos = _transform.localPosition; limitedPos.x = oldPosition.x; _transform.localPosition = limitedPos; _moveRemainingDelta.x = 0f; } if (_transform.position.z < _limitsOffset.y + _limitsZ.x || _transform.position.z > _limitsOffset.y + _limitsZ.y) { var limitedPos = _transform.localPosition; limitedPos.z = oldPosition.z; _transform.localPosition = limitedPos; _moveRemainingDelta.z = 0f; } var pinchRatio = LeanGesture.GetPinchRatio(fingers, ZoomWheelSensitivity); if (_camera.orthographic) { _zoom *= pinchRatio; _zoom = Mathf.Clamp(_zoom, _orthoLimits.x, _orthoLimits.y); _camera.orthographicSize = _zoom; } else { _zoom *= pinchRatio; _zoom = Mathf.Clamp(_zoom, _terrainOffsetMin, _terrainOffsetMax); var pos = _transform.position; var height = 0f; if (_terrain != null) { height = _terrain.SampleHeight(pos) + _zoom; } else { height = _offsetFromFloorIfNoTerrain + _zoom; } pos.y = height; _transform.position = pos; } var twistDegrees = LeanGesture.GetTwistDegrees(fingers); var rotation = _transform.localEulerAngles; rotation.y += twistDegrees; //_transform.localEulerAngles = rotation; }
protected virtual void LateUpdate() { // Make sure the camera exists if (LeanTouch.GetCamera(ref cameraMain, gameObject) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); //return; // if (fingers.Count == 0) // { // return; // } //单指操作 if (fingers.Count == 1) { if (bDisableAll) { return; } Vector2 screenDelta = LeanGesture.GetScreenDelta(fingers); if (!bIsMove && !bMouseRightDown) //鼠标右键按下时,不能平移 { if (Input.GetMouseButtonDown(0)) { _cameraDest = GetCenterDistance(); } CameraPan(screenDelta); } //鼠标右键按下时上下调整视角,左右绕中心旋转 MouseRightUpdate(); // if (Input.GetMouseButton (1)) { // MouseRightTour (); // } } //双指pinch捏放,缩放操作 float pinchRatio = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); //捏放比例 //判断pinchRatio是否为1,1表示没有缩放 if (pinchRatio != 1.0f) { CameraDistanceRatio(pinchRatio); //换为z轴方向移动 } //双指操作 if (fingers.Count == 2) { //双指上下移动,调整仰角 Vector2 heightDelta = LeanGesture.GetScreenDelta(fingers); //手指移动的屏幕距离 //双指Twist旋转,绕屏幕中心与地面交点旋转 float twistDegree = LeanGesture.GetTwistDegrees(fingers, LeanGesture.GetScreenCenter(), LeanGesture.GetLastScreenCenter()); //双指操作 CameraTwistAndHeight(heightDelta.y, twistDegree); //双指操作,调整仰角,绕屏幕中心与地面交点旋转(双指旋转时不符合功能,弃用) //计算屏幕中心点 // Vector3 centerPoint; // float enter; // if (GetInterPoint(cameraMain, new Vector3(0.5F, 0.5F, 0), out centerPoint, out enter)) // { // _cameraDest = enter + 0.3f; // // CameraTAndH(centerPoint, heightDelta.y, twistDegree); // } } } }