Пример #1
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());
    }
Пример #2
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;
        }
    }
    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());
    }