Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
    public void ScaleObject()
    {
        List <LeanFinger> fingers = m_use.GetFingers();

        pinchScale = Mathf.Clamp(LeanGesture.GetPinchScale(fingers), 0, 2f);

        if (pinchScale != 1f)
        {
            //update local scale
            transform.localScale *= pinchScale;
            if (transform.localScale.x > maxScale)
            {
                transform.localScale = new Vector3(maxScale, maxScale, maxScale);
            }
            if (transform.localScale.x < minScale)
            {
                transform.localScale = new Vector3(minScale, minScale, minScale);
            }
        }
    }
Ejemplo n.º 3
0
        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);
    }
Ejemplo n.º 5
0
    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();
    }
Ejemplo n.º 6
0
    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);
    }
Ejemplo n.º 7
0
    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);
//				}
            }
        }
    }
Ejemplo n.º 8
0
        private void OnFingerPinch(IUiElement uie, List <LeanFinger> fingers)
        {
            float pinchScale = LeanGesture.GetPinchScale(fingers);

            uie.OnFingerPinch(pinchScale);
        }
Ejemplo n.º 9
0
    // GameObject debugObj;

    // void Update()
    // {
    //     if (null == debugObj)
    //     {
    //         debugObj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
    //         debugObj.name = "__TouchDebug";
    //         debugObj.layer = Layers.Debris;
    //         debugObj.transform.SetParent(transform);
    //         debugObj.GetComponent<MeshRenderer>().material.color = Color.red;
    //     }

    //     if (null != mainFinger)
    //     {
    //         var worldPos = PuzzleCamera.Main.ScreenToWorldPoint(mainFinger.ScreenPosition);
    //         worldPos.z = -Config.Instance.camera.distance + 100;
    //         debugObj.transform.position = worldPos;
    //         debugObj.transform.localScale = Vector3.one * TouchVars.raycastRadius * 2;
    //         debugObj.SetActive(true);
    //     }
    //     else
    //     {
    //         debugObj.SetActive(false);
    //     }
    // }

    void OnGesture(List <LeanFinger> fingers)
    {
        if (AllFingersOff(fingers))
        {
            phase      = Phase.Picking;
            holdTimer  = 0f;
            mainFinger = null;
            if (null != objPicked)
            {
                onObjReleased?.Invoke(objPicked);
                objPicked = null;
            }
            return;
        }

        if (null == mainFinger || !mainFinger.IsActive || !mainFinger.Set)
        {
            if (null != objPicked)
            {
                onObjReleased?.Invoke(objPicked);
                objPicked = null;
            }
            mainFinger = fingers[0];
        }

        if (phase == Phase.Picking)
        {
            if (fingers.Count > 1 || FingerMoved(mainFinger))
            {
                phase = Phase.Update;
            }
            else if ((holdTimer += Time.deltaTime) >= TouchVars.holdThreshold.FloatValue)
            {
                var ray       = PuzzleCamera.Main.ScreenPointToRay(mainFinger.ScreenPosition);
                int numOfHits = Physics.SphereCastNonAlloc(
                    ray,
                    TouchVars.raycastRadius,
                    hits,
                    Config.Instance.camera.distance,
                    ~Layers.Debris);

                if (numOfHits > 0)
                {
                    Vector3 origin = ray.origin;
                    origin.z = PuzzleCamera.Main.transform.position.z;
                    Transform selected = null;
                    float     distance = float.MaxValue;
                    for (int i = 0; i < numOfHits; ++i)
                    {
                        var xform = hits[i].transform;
                        if (null == selected)
                        {
                            float newDistance = Vector2.Distance(xform.position, origin);
                            if (newDistance < distance)
                            {
                                selected = xform;
                                distance = newDistance;
                            }
                        }
                    }

                    if (null != selected)
                    {
                        TouchLog.Log("Picking " + selected);
                        if (null != onObjPicked && onObjPicked(selected))
                        {
                            objPicked = selected;
                            TouchLog.Log(objPicked + " Picked");
                        }
                    }
                }
                phase = Phase.Update;
            }
        }

        if (phase == Phase.Update)
        {
            if (null == objPicked || fingers.Count > 1)
            {
                Vector2 current = LeanGesture.GetScreenCenter(fingers);
                Vector2 delta   = current - LeanGesture.GetLastScreenCenter(fingers);
                onFingerDrag?.Invoke(delta);

                if (fingers.Count == 2)
                {
                    onFingerPinched?.Invoke(LeanGesture.GetPinchRatio());
                }
            }

            if (null != objPicked && fingers.Count == 1)
            {
                onObjMove?.Invoke(objPicked, mainFinger.ScreenPosition);
            }
        }
    }
Ejemplo n.º 10
0
    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;
        }
    }
Ejemplo n.º 11
0
    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;
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 12
0
    protected override void Update()
    {
        base.Update();
        ShowMessage("Fire", "Fire : " + Convert.ToInt32(IsFiring));
        ShowMessage("Scope", "Toggle Scope : " + Convert.ToInt32(ViewingScope));
        ShowMessage("Reloading", "Is Reloading: " + Convert.ToInt32(isReloading));
        ShowMessage("MiniReloading", "Is Adjusting Root: " + Convert.ToInt32(isMiniReloading));

        ShowMessage("Ducking", "Is Ducking: " + Convert.ToInt32(isDucking));

        txtReload.text = "Ammo: " + currentAmmo + "/" + AmmoPerClip;

        UpdateHealth();


        string zm = string.Format("X{0:0}", GetZoomFrom(6, 20));

        txtZoom.text = zm;

        if (IsUserControllable)
        {
            RotationControls(false);

            //Zoom Controls
            List <LeanFinger> fingers = LeanTouch.GetFingers(false);

            Vector3[] corners = new Vector3[4];
            ScopeUICenter.transform.GetChild(0).GetComponent <RectTransform>().GetWorldCorners(corners);
            Vector3 pivot = corners[0];
            for (int i = 0; i < fingers.Count; i++)
            {
                if (fingers[i].LastScreenPosition.x <= corners[0].x)
                {
                    fingers.RemoveAt(i);
                    i--;
                }
            }


            if (fingers.Count > 0)
            {
                if (isDraggingZoom)
                {
                    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);
                }
            }

            if (animatingReticule)
            {
                rTime += Time.deltaTime * ReticuleOscillationSpeed;

                float osc = Mathf.PingPong(rTime, .25f) + 1;
                CurrentSniperPanel.transform.GetChild(0).transform.localScale = new Vector3(osc, osc, osc);

                if (rTime >= .5f)
                {
                    animatingReticule = false;
                    rTime             = 0;
                }
            }
        }
    }
Ejemplo n.º 13
0
    protected override void RotationControls(bool ignoreGUI = true, bool linear = false)
    {
        //For smooth rotation
        Vector3 prevEuler = new Vector3(xRot, yRot, 0);

        List <LeanFinger> fingers = LeanTouch.GetFingers(ignoreGUI);

        Vector3[] corners = new Vector3[4];
        ScopeUICenter.transform.GetChild(0).GetComponent <RectTransform>().GetWorldCorners(corners);
        Vector3 pivot = corners[0];

        for (int i = 0; i < fingers.Count; i++)
        {
            if (fingers[i].LastScreenPosition.x > corners[0].x)
            {
                fingers.RemoveAt(i);
                i--;
            }
        }



        //Optional linear mode
        float sens = RotationSensitivity;

        if (linear && ViewingScope)
        {
            if (Zoom != 0)
            {
                sens = RotationSensitivity * InvZoom(Zoom, MinimumRotationModifier);
            }
            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


        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());
    }
Ejemplo n.º 14
0
        private void UnityInputUpdate()
        {
            var oneOverScale = 1f / Batcher.scale;

            //Finger/mouse handling
            if (UnityEngine.Application.isMobilePlatform && UserPreferences.UseMouseOnMobile.CurrentValue == 0)
            {
                var fingers = Lean.Touch.LeanTouch.GetFingers(true, false);

                //Detect two finger tap gesture for closing gumps
                for (int i = 0; i < fingers.Count && i < 5; i++)
                {
                    var finger = fingers[i];
                    if (finger.Age < 0.1f)
                    {
                        var mousePositionPoint = ConvertUnityMousePosition(finger.ScreenPosition, oneOverScale);
                        controlsUnderFingers[i] = UIManager.GetMouseOverControl(mousePositionPoint)?.RootParent;
                        if (controlsUnderFingers[i] != null)
                        {
                            for (int k = 0; k < i; k++)
                            {
                                if (controlsUnderFingers[k] == controlsUnderFingers[i])
                                {
                                    //Simulate right mouse down and up
                                    SimulateMouse(false, false, true, false, false, true);
                                    SimulateMouse(false, false, false, true, false, true);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        controlsUnderFingers[i] = null;
                    }
                }

                //Only process one finger that has not started over gui because using multiple fingers with UIManager
                //causes issues due to the assumption that there's only one pointer, such as on finger "stealing"
                //a dragged gump from another
                if (fingers.Count > 0)
                {
                    var finger      = fingers[0];
                    var mouseMotion = finger.ScreenPosition != finger.LastScreenPosition;
                    SimulateMouse(finger.Down, finger.Up, false, false, mouseMotion, false);
                }

                //var fingerss = Lean.Touch.LeanTouch.GetFingers(true, false);
                if (fingers.Count == 2 && ProfileManager.Current.EnableMousewheelScaleZoom && IsMouseOverViewport)
                {
                    var scale = LeanGesture.GetPinchScale(fingers, 0.0f);
                    if (scale < 1)
                    {
                        _zoomoutCounter++;
                        //Client.Game.GetScene<GameScene>().ZoomOut();
                    }
                    else if (scale > 1)
                    {
                        _zoominCounter++;
                        //Client.Game.GetScene<GameScene>().ZoomIn();
                    }

                    if (_zoominCounter > 3)
                    {
                        _zoominCounter  = 0;
                        _zoomoutCounter = 0;
                        Client.Game.GetScene <GameScene>().ZoomIn();
                    }
                    else if (_zoomoutCounter > 3)
                    {
                        _zoominCounter  = 0;
                        _zoomoutCounter = 0;
                        Client.Game.GetScene <GameScene>().ZoomOut();
                    }
                }
            }
            else
            {
                var leftMouseDown  = UnityEngine.Input.GetMouseButtonDown(0);
                var leftMouseUp    = UnityEngine.Input.GetMouseButtonUp(0);
                var rightMouseDown = UnityEngine.Input.GetMouseButtonDown(1);
                var rightMouseUp   = UnityEngine.Input.GetMouseButtonUp(1);
                var mousePosition  = UnityEngine.Input.mousePosition;
                var mouseMotion    = mousePosition != lastMousePosition;
                lastMousePosition = mousePosition;

                if (Lean.Touch.LeanTouch.PointOverGui(mousePosition))
                {
                    Mouse.Position.X = 0;
                    Mouse.Position.Y = 0;
                    leftMouseDown    = false;
                    leftMouseUp      = false;
                    rightMouseDown   = false;
                    rightMouseUp     = false;
                }

                SimulateMouse(leftMouseDown, leftMouseUp, rightMouseDown, rightMouseUp, mouseMotion, false);
            }

            //Keyboard handling
            var keymod = KeymodOverride;

            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftAlt))
            {
                keymod |= SDL_Keymod.KMOD_LALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightAlt))
            {
                keymod |= SDL_Keymod.KMOD_RALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftShift))
            {
                keymod |= SDL_Keymod.KMOD_LSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightShift))
            {
                keymod |= SDL_Keymod.KMOD_RSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftControl))
            {
                keymod |= SDL_Keymod.KMOD_LCTRL;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightControl))
            {
                keymod |= SDL_Keymod.KMOD_RCTRL;
            }

            //Potential fix for hold alt to move gumps not working on mobile?
            Keyboard.Shift = (keymod & SDL_Keymod.KMOD_SHIFT) != SDL_Keymod.KMOD_NONE;
            Keyboard.Alt   = (keymod & SDL_Keymod.KMOD_ALT) != SDL_Keymod.KMOD_NONE;
            Keyboard.Ctrl  = (keymod & SDL_Keymod.KMOD_CTRL) != SDL_Keymod.KMOD_NONE;

            foreach (var keyCode in _keyCodeEnumValues)
            {
                var key = new SDL_KeyboardEvent {
                    keysym = new SDL_Keysym {
                        sym = (SDL_Keycode)keyCode, mod = keymod
                    }
                };
                if (UnityEngine.Input.GetKeyDown(keyCode))
                {
                    Keyboard.OnKeyDown(key);

                    if (Plugin.ProcessHotkeys((int)key.keysym.sym, (int)key.keysym.mod, true))
                    {
                        _ignoreNextTextInput = false;
                        UIManager.KeyboardFocusControl?.InvokeKeyDown(key.keysym.sym, key.keysym.mod);
                        _scene.OnKeyDown(key);
                    }
                    else
                    {
                        _ignoreNextTextInput = true;
                    }
                }
                if (UnityEngine.Input.GetKeyUp(keyCode))
                {
                    Keyboard.OnKeyUp(key);
                    UIManager.KeyboardFocusControl?.InvokeKeyUp(key.keysym.sym, key.keysym.mod);
                    _scene.OnKeyUp(key);
                    Plugin.ProcessHotkeys(0, 0, false);
                }
            }

            //Input text handling
            if (UnityEngine.Application.isMobilePlatform && TouchScreenKeyboard != null)
            {
                var text = TouchScreenKeyboard.text;

                if (_ignoreNextTextInput == false && TouchScreenKeyboard.status == UnityEngine.TouchScreenKeyboard.Status.Done)
                {
                    //Clear the text of TouchScreenKeyboard, otherwise it stays there and is re-evaluated every frame
                    TouchScreenKeyboard.text = string.Empty;

                    //Set keyboard to null so we process its text only once when its status is set to Done
                    TouchScreenKeyboard = null;

                    //Need to clear the existing text in textbox before "pasting" new text from TouchScreenKeyboard
                    if (UIManager.KeyboardFocusControl is StbTextBox stbTextBox)
                    {
                        stbTextBox.SetText(string.Empty);
                    }

                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);

                    //When targeting SystemChat textbox, "auto-press" return key so that the text entered on the TouchScreenKeyboard is submitted right away
                    if (UIManager.KeyboardFocusControl != null && UIManager.KeyboardFocusControl == UIManager.SystemChat?.TextBoxControl)
                    {
                        //Handle different chat modes
                        HandleChatMode(text);
                        //"Press" return
                        UIManager.KeyboardFocusControl.InvokeKeyDown(SDL_Keycode.SDLK_RETURN, SDL_Keymod.KMOD_NONE);
                        //Revert chat mode to default
                        UIManager.SystemChat.Mode = ChatMode.Default;
                    }
                }
            }
            else
            {
                var text = UnityEngine.Input.inputString;
                //Backspace character should not be sent as text input
                text = text.Replace("\b", "");
                if (_ignoreNextTextInput == false && string.IsNullOrEmpty(text) == false)
                {
                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);
                }
            }
        }
Ejemplo n.º 15
0
        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;
        }
Ejemplo n.º 16
0
    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();
            }
        }
    }
Ejemplo n.º 17
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());
    }