Beispiel #1
0
    //check and snap camera
    public bool CheckAndSnapCamera()
    {
        bool canSnap = false;

        targetMarkPositionScript = markPositionGroupManager.CheckForCameraSnapTarget(cameraPivotV.rotation.eulerAngles.x, cameraPivotH.rotation.eulerAngles.y);
        if (targetMarkPositionScript != null)
        {
            snapTweenerV = cameraPivotV.DOLocalRotate(new Vector3(targetMarkPositionScript.GetRotation().x, 0, 0), snapDuration);
            snapTweenerH = cameraPivotH.DOLocalRotate(new Vector3(0, targetMarkPositionScript.GetRotation().y, 0), snapDuration);
            snapTweenerV.OnComplete(DoTargetEvent);
            canSnap = true;
        }
        return(canSnap);
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        //move part
        if (Input.GetMouseButton(1) && rotateIsActive)
        {
            fMouseX = Input.GetAxis("Mouse X");
            fMouseY = Input.GetAxis("Mouse Y");

            if (targetMarkPositionScript != null)
            {
                DoTargetExitEvent();
                targetMarkPositionScript = null;
            }

            isSnapping = false;
            snapTweenerV.Kill();
            snapTweenerH.Kill();
        }
        else
        {
            //speedV = Mathf.Lerp(speedV, 0, Time.deltaTime * 5f);
            //speedH = Mathf.Lerp(speedH, 0, Time.deltaTime * 5f);
            fMouseX = Mathf.Lerp(fMouseX, 0, Time.deltaTime * 5f);
            fMouseY = Mathf.Lerp(fMouseY, 0, Time.deltaTime * 5f);


            rotateSpeedMultiply = Mathf.Sqrt(fMouseX * fMouseX + fMouseY + fMouseY);
            if (rotateSpeedMultiply < minRotateSpeedMultiplyForSnap && !isSnapping)
            {
                if (CheckAndSnapCamera())
                {
                    isSnapping = true;
                }
            }
        }


        //buffer area part
        if (NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x) > maxUpAngle)
        {
            if (Input.GetMouseButton(1))
            {
                isBounceBack = false;
                //speedV *= Mathf.Pow((maxUpAngleWithBuffer - NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x)) / (maxUpAngleWithBuffer - maxUpAngle), 4);
                fMouseY *= Mathf.Pow((maxUpAngleWithBuffer - NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x)) / (maxUpAngleWithBuffer - maxUpAngle), 4);
            }
            else
            {
                fMouseY = 0;
                cameraPivotV.Rotate(Vector3.right, -(NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x) - maxUpAngle) / 20f, Space.Self);
            }
        }
        else if (NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x) < maxDownAngle)
        {
            if (Input.GetMouseButton(1))
            {
                isBounceBack = false;
                //speedV *= Mathf.Pow((maxDownAngleWithBuffer - NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x)) / (maxDownAngleWithBuffer - maxDownAngle), 4);
                fMouseY *= Mathf.Pow((maxDownAngleWithBuffer - NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x)) / (maxDownAngleWithBuffer - maxDownAngle), 4);
            }
            else
            {
                fMouseY = 0;
                cameraPivotV.Rotate(Vector3.right, -(NormalizeEuler(cameraPivotV.localRotation.eulerAngles.x) - maxDownAngle) / 20f, Space.Self);
            }
        }
        else
        {
            isBounceBack = false;
        }

        //final rotate part
        if (!isBounceBack)
        {
            cameraPivotV.Rotate(Vector3.right, -fMouseY * speedV, Space.Self);
        }
        cameraPivotH.Rotate(Vector3.up, fMouseX * speedH, Space.Self);
    }