protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the scaled average movement vector of these fingers var drag = LeanGesture.GetScaledDelta(fingers); // Get base sensitivity var sensitivity = GetSensitivity(); // Adjust pitch Pitch += drag.y * PitchSensitivity * sensitivity; if (PitchClamp == true) { Pitch = Mathf.Clamp(Pitch, PitchMin, PitchMax); } // Adjust yaw Yaw -= drag.x * YawSensitivity * sensitivity; if (YawClamp == true) { Yaw = Mathf.Clamp(Yaw, YawMin, YawMax); } // Rotate to pitch and yaw values transform.localRotation = Quaternion.Euler(Pitch, Yaw, 0.0f); }
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); int layerMask = ~LayerMask.GetMask("Ignore Raycast"); if (Input.GetMouseButton(0)) { Ray raycast = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit raycastHit; if (Physics.Raycast(raycast, out raycastHit, Mathf.Infinity, layerMask, QueryTriggerInteraction.UseGlobal)) { // Perform the translation Debug.Log("Ray hit occurred!"); Translate(screenDelta, raycastHit); } } }
protected virtual void LateUpdate() { // Make sure the camera exists if (LeanTouch.GetCamera(ref Camera, gameObject) == true) { //Busca as informações da Controller do Level. LevelController lvl = (LevelController)gameController.GetComponent("LevelController"); float camPosDown = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, Camera.main.nearClipPlane)).y; float camPosUp = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, Camera.main.nearClipPlane)).y; // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var worldDelta = LeanGesture.GetWorldDelta(fingers, Distance, Camera); if (camPosDown < lvl.MaxCamPosDown) { transform.position -= new Vector3(0, camPosDown - lvl.MaxCamPosDown, 0); } else if (camPosUp > lvl.MaxCamPosUp) { transform.position += new Vector3(0, lvl.MaxCamPosUp - camPosUp, 0); } else if (((camPosDown > lvl.MaxCamPosDown) && worldDelta.y > 0) || ((camPosUp < lvl.MaxCamPosUp) && worldDelta.y < 0)) { // Pan the camera, on Y, based on the world delta Vector3 move = new Vector3(0, worldDelta.y * Sensitivity, 0); transform.position -= move; } } }
protected virtual void Update() { // If we require a selectable and it isn't selected, skip if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use to rotate var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the scaled average movement vector of these fingers var drag = LeanGesture.GetScaledDelta(fingers); // The angle we want to rotate by in degrees var angleX = drag.x * HorizontalSensitivity; // Rotate around axis transform.Rotate(HorizontalAxis, angleX, Space); // The angle we want to rotate by in degrees var angleY = drag.y * VerticalSensitivity; // Rotate around axis transform.Rotate(VerticalAxis, angleY, Space); }
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); // Perform the translation Translate(screenDelta); Debug.Log(collided); if (!collided) { positions.Add(transform.position); } else { transform.position = new Vector3(0, 3.8f, 1); //GameObject.Find("LeanSelect").GetComponent<LeanSelect>().DeselectAll(); } }
protected virtual void LateUpdate() { if (Input.touchCount == 2) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var worldDelta = LeanGesture.GetWorldDelta(fingers, Distance, Camera); // Pan the camera based on the world delta RemainingDelta -= worldDelta; // The framerate independent damping factor var factor = Mathf.Exp(-Dampening * Time.deltaTime); // Dampen remainingDelta var newDelta = RemainingDelta * factor; // Shift this transform by the change in delta transform.position += RemainingDelta - newDelta; // Update remainingDelta with the dampened value RemainingDelta = newDelta; } }
protected virtual void Update() { // Get the fingers we want to use to rotate var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Count positive and negative so opposite fingers cancel each other out var negative = 0; var positive = 0; for (var i = 0; i < fingers.Count; i++) { if (IsPositive(fingers[i]) == true) { positive += 1; } else { negative += 1; } } if (positive > negative) { transform.Rotate(Rotation * Time.deltaTime, Space); } if (negative > positive) { transform.Rotate(-Rotation * Time.deltaTime, Space); } }
// LateUpdate Runs after Every Frame protected virtual void LateUpdate() { // If camera is null, try and get the main camera, return true if a camera was found if (LeanTouch.GetCamera(ref Camera) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // 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 var factor = 1.0f - Mathf.Exp(-Dampening * Time.deltaTime); // Store the current size/fov in a temp variable var current = GetCurrent(); current = Mathf.Lerp(current, Target, factor); SetCurrent(current); } }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the required camera var camera = GetComponent <Camera>(); // Get the world delta of all the fingers var worldDelta = LeanGesture.GetWorldDelta(fingers, Distance, camera); // Pan the camera based on the world delta RemainingDelta -= worldDelta; // Get t value var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime); // Dampen remainingDelta var newDelta = Vector3.Lerp(RemainingDelta, Vector3.zero, factor); // Shift this transform by the change in delta transform.position += RemainingDelta - newDelta; // Update remainingDelta with the dampened value RemainingDelta = newDelta; }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Change the distance based on pinch gesture Distance *= LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Limit distance to min/max values? if (DistanceClamp == true) { Distance = Mathf.Clamp(Distance, DistanceMin, DistanceMax); } // Reset position transform.localPosition = Vector3.zero; // Collide against stuff? if (CollisionLayers != 0) { var hit = default(RaycastHit); var start = transform.TransformPoint(Direction.normalized * DistanceMin); var direction = transform.TransformDirection(Direction); var distanceSpread = DistanceMax - DistanceMin; if (Physics.SphereCast(start, CollisionRadius, direction, out hit, distanceSpread, CollisionLayers) == true) { Distance = DistanceMin + hit.distance; } } // Dolly back by on distance transform.Translate(Direction.normalized * Distance); }
/// <summary>If requiredSelectable is set and not selected, the fingers list will be empty. If selected then the fingers list will only contain the selecting finger.</summary> public static List <LeanFinger> GetFingers(bool ignoreIfStartedOverGui, bool ignoreIfOverGui, int requiredFingerCount = 0, LeanSelectable requiredSelectable = null) { var fingers = LeanTouch.GetFingers(ignoreIfStartedOverGui, ignoreIfOverGui, requiredFingerCount); if (requiredSelectable != null) { if (requiredSelectable.IsSelected == false) { fingers.Clear(); } if (requiredSelectable.IsolateSelectingFingers == true) { fingers.Clear(); fingers.AddRange(requiredSelectable.selectingFingers); if (requiredFingerCount > 0 && fingers.Count != requiredFingerCount) { fingers.Clear(); } } } return(fingers); }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel scaling // 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); if (fingers != null) { if (fingers.Count >= 2) { float dis = Vector2.Distance(fingers [0].ScreenPosition, fingers [1].ScreenPosition); //Debug.Log ("-----distance :" + dis); if (dis < 300) { return; } } } // Calculate the scaling values based on these fingers var scale = LeanGesture.GetPinchScale(fingers, WheelSensitivity); var screenCenter = LeanGesture.GetScreenCenter(fingers); // Perform the scaling Scale(scale, screenCenter); }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use to translate var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the scaled average movement vector of these fingers var drag = LeanGesture.GetScaledDelta(fingers); // Find the rotation var rotation = Quaternion.identity; if (RelativeTo != null) { rotation = RelativeTo.rotation; } // The distance we want to translate by in degrees var speedX = drag.x * HorizontalSensitivity; // Translate along axis transform.position += rotation * HorizontalAxis.normalized * speedX; // The angle we want to translate by in degrees var speedY = drag.y * VerticalSensitivity; // Translate along axis transform.position += rotation * VerticalAxis.normalized * speedY; }
protected virtual void Update() { // Get the fingers we want to use to rotate var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Active? if (fingers.Count > 0) { // Add the scaled average movement vector of these fingers activeScaledDelta += LeanGesture.GetScaledDelta(fingers); // Prevent division by zero if (HorizontalThreshold != 0.0f) { var stepX = (int)(activeScaledDelta.x / HorizontalThreshold); if (stepX != 0) { remainingRotation += HorizontalRotation * stepX; activeScaledDelta.x -= stepX * HorizontalThreshold; } } // Prevent division by zero if (VerticalThreshold != 0.0f) { var stepY = (int)(activeScaledDelta.y / VerticalThreshold); if (stepY != 0) { remainingRotation += VerticalRotation * stepY; activeScaledDelta.y -= stepY * VerticalThreshold; } } } // Reset else { activeScaledDelta.x = 0.0f; activeScaledDelta.y = 0.0f; } // Get t value var factor = LeanTouch.GetDampenFactor(Dampening, Time.deltaTime); // Store old rotation var oldRotation = remainingRotation; // Dampen remaining remainingRotation = Vector3.Lerp(remainingRotation, Vector3.zero, factor); // Rotate by delta transform.Rotate(oldRotation - remainingRotation, Space); }
void Update() { if (lastCount != count) { //boost the player speed! float boost = 500f / rb.velocity.magnitude; rb.AddForce(rb.velocity.normalized * boost, ForceMode.Impulse); lastCount = count; } resetTimeOutofCloud(checkOutOfCloud()); // Check if game started and implement touch & keyboard input accordingly if (!isStarted) { if (Input.anyKey || Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { rb.AddForce(new Vector3(0.0f, 0.0f, 100f) * speed); isStarted = true; } } else { if (Input.GetKey(KeyCode.RightArrow)) { transform.position += Vector3.right * speed * Time.deltaTime; } if (Input.GetKey(KeyCode.LeftArrow)) { transform.position += Vector3.left * speed * Time.deltaTime; } if (Input.GetKey(KeyCode.UpArrow)) { transform.position += Vector3.up * speed * Time.deltaTime; } if (Input.GetKey(KeyCode.DownArrow)) { transform.position += Vector3.down * speed * Time.deltaTime; } } // Touch input // 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 scaledDelta value based on these fingers var scaledDelta = LeanGesture.GetScaledDelta(fingers); // Perform the translation Translate(scaledDelta); }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var pinch = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Dolly the camera based on the pinch ratio transform.position += Vector - Vector * pinch; }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); // Get the degrees these fingers twisted var degrees = LeanGesture.GetTwistDegrees(fingers); // Apply twist transform.Rotate(Vector3.forward, -degrees, Space.Self); }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var worldDelta = LeanGesture.GetWorldDelta(fingers, Distance, Camera); // Pan the camera based on the world delta transform.position -= worldDelta; }
protected virtual void Update() { // 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); }
/// <summary>If requiredSelectable is set and not selected, the fingers list will be empty.</summary> public static List <LeanFinger> GetFingersOrClear(bool ignoreIfStartedOverGui, bool ignoreIfOverGui, int requiredFingerCount = 0, LeanSelectable requiredSelectable = null) { var fingers = LeanTouch.GetFingers(ignoreIfStartedOverGui, ignoreIfOverGui, requiredFingerCount); if (requiredSelectable != null && requiredSelectable.IsSelected == false) { fingers.Clear(); } return(fingers); }
/// <summary>If requiredSelectable is set and not selected, the fingers list will be empty. If selected then the fingers list will only contain the selecting finger.</summary> public static List <LeanFinger> GetFingers(bool ignoreIfStartedOverGui, bool ignoreIfOverGui, int requiredFingerCount = 0, LeanSelectable requiredSelectable = null) { var fingers = LeanTouch.GetFingers(ignoreIfStartedOverGui, ignoreIfOverGui, requiredFingerCount); if (requiredSelectable != null) { if (requiredSelectable.IsSelected == true) { var requiredSelectableByFinger = requiredSelectable as LeanSelectableByFinger; if (requiredSelectableByFinger != null) { switch (requiredSelectableByFinger.use) { case UseType.AllFingers: { } break; case UseType.OnlySelectingFingers: { fingers.Clear(); fingers.AddRange(requiredSelectableByFinger.selectingFingers); } break; case UseType.IgnoreSelectingFingers: { foreach (var selectingFinger in requiredSelectableByFinger.selectingFingers) { fingers.Remove(selectingFinger); } } break; } } if (requiredFingerCount > 0 && fingers.Count != requiredFingerCount) { fingers.Clear(); } } else { fingers.Clear(); } } return(fingers); }
protected virtual void LateUpdate() { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreStartedOverGui, IgnoreIsOverGui, RequiredFingerCount); // Get the last and current screen point of all fingers var lastScreenPoint = LeanGesture.GetLastScreenCenter(fingers); var screenPoint = LeanGesture.GetScreenCenter(fingers); // Get the world delta of them after conversion var worldDelta = ScreenDepth.ConvertDelta(lastScreenPoint, screenPoint, gameObject); // Pan the camera based on the world delta transform.position -= worldDelta * Sensitivity; }
protected virtual void LateUpdate() { // Make sure the camera exists if (LeanTouch.GetCamera(ref Camera, gameObject) == true) { // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var worldDelta = LeanGesture.GetWorldDelta(fingers, Distance, Camera); // Pan the camera based on the world delta transform.position -= worldDelta * Sensitivity; } }
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); // Calculate the screenDelta value based on these fingers var screenDelta = LeanGesture.GetScreenDelta(fingers); // Perform the translation Translate(screenDelta); }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel turn if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use to rotate var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // The twist angle based on these fingers var twist = LeanGesture.GetTwistDegrees(fingers) * TwistSensitivity; // Rotate around axis transform.Rotate(TwistAxis, twist, Space); }
protected virtual void Update() { // Get fingers and calculate how many are still touching the screen var fingers = LeanTouch.GetFingers(IgnoreGuiFingers); var fingerCount = GetFingerCount(fingers); // At least one finger set? if (fingerCount > 0) { // Did this just begin? if (lastFingerCount == 0) { age = 0.0f; HighestFingerCount = fingerCount; } else if (fingerCount > HighestFingerCount) { HighestFingerCount = fingerCount; } } age += Time.unscaledDeltaTime; // Reset MultiTap = false; // Is a multi-tap still eligible? if (age <= LeanTouch.CurrentTapThreshold) { // Null fingers released? if (fingerCount == 0 && lastFingerCount > 0) { MultiTapCount += 1; OnMultiTap.Invoke(MultiTapCount, HighestFingerCount); } } // Reset else { MultiTapCount = 0; HighestFingerCount = 0; } lastFingerCount = fingerCount; }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Get the world delta of all the fingers var pinch = LeanGesture.GetPinchRatio(fingers, WheelSensitivity); // Translate the GameObject along Axis based on the pinch ratio transform.Translate(Axis * (pinch - 1.0f) * Sensitivity, Space); }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel rotation if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, IgnoreGuiFinger, RequiredFingerCount); // Calculate the rotation values based on these fingers var center = LeanGesture.GetScreenCenter(fingers); var degrees = LeanGesture.GetTwistDegrees(fingers); // Perform the rotation Rotate(center, degrees); }
protected virtual void Update() { // If we require a selectable and it isn't selected, cancel scaling if (RequiredSelectable != null && RequiredSelectable.IsSelected == false) { return; } // Get the fingers we want to use var fingers = LeanTouch.GetFingers(IgnoreGuiFingers, RequiredFingerCount); // Calculate the scaling values based on these fingers var scale = LeanGesture.GetPinchScale(fingers); var screenCenter = LeanGesture.GetScreenCenter(fingers); // Perform the scaling Scale(scale, screenCenter); }
protected virtual void LateUpdate() { // 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); } // Set the new zoom SetZoom(Zoom); }