Esempio n. 1
0
    bool AxisClamp(CameraAxis a, bool max)
    {
        switch (a)
        {
        case CameraAxis.hor:
            horizontal = Mathf.Clamp(horizontal, horizontalMin, horizontalMax);
            if (max)
            {
                return(horizontal != horizontalMax);
            }
            else
            {
                return(horizontal != horizontalMin);
            }

        case CameraAxis.ver:
            vertical = Mathf.Clamp(vertical, verticalMin, verticalMax);
            if (max)
            {
                return(vertical != verticalMax);
            }
            else
            {
                return(vertical != verticalMin);
            }
        }
        return(false);
    }
Esempio n. 2
0
    /// <summary>
    /// Calculate the camera rotation speed based on the mouse position, the axis and the direction of movement.
    /// </summary>
    float CalculateSpeed(float inputVal, CameraAxis axis, float dir)
    {
        float delta    = 0;
        float max      = 0;
        float maxSpeed = 0;
        float speed    = 0;

        if (axis == CameraAxis.Horizontal)
        {
            delta    = horizontalDelta;
            max      = dir > 0 ? Screen.width : 0;
            maxSpeed = horizontalSpeed;
        }
        else
        {
            delta    = verticalDelta;
            max      = dir > 0 ? Screen.height : 0;
            maxSpeed = verticalSpeed;
        }

        if (max > delta)
        {
            speed = (inputVal - (max - delta)) / -delta * maxSpeed;
        }
        else
        {
            speed = (inputVal - delta) / -delta * maxSpeed;
        }

        return(speed);
    }
Esempio n. 3
0
    /// <summary>
    /// Calculate the trigger area for the mouse using the Soft Zones of the Cinemachine Middle Rig.
    /// </summary>
    float CalculateDelta(float softZoneWeight, CameraAxis axis)
    {
        float dim   = 0;
        float delta = 0;

        if (axis == CameraAxis.Horizontal)
        {
            dim   = softZoneWeight * Screen.width;
            delta = dim < Screen.width ? Screen.width - dim : Screen.width;
        }
        else
        {
            dim   = softZoneWeight * Screen.height;
            delta = dim < Screen.height ? Screen.height - dim : Screen.height;
        }

        return(delta / 2);
    }
Esempio n. 4
0
    private float GetClampedCoordinate(CameraAxis axis)
    {
        float targetCoordinate = target.position.x;

        float halfOfScreen = Camera.main.orthographicSize * aspectRatio;

        float clampMin = clampedAreaBounds.min.x * clampedAreaRenderer.transform.localScale.x;
        float clampMax = clampedAreaBounds.max.x * clampedAreaRenderer.transform.localScale.x;

        if (axis == CameraAxis.Y)
        {
            halfOfScreen     = Camera.main.orthographicSize;
            targetCoordinate = target.position.y;
            clampMin         = clampedAreaBounds.min.y * clampedAreaRenderer.transform.localScale.y;
            clampMax         = clampedAreaBounds.max.y * clampedAreaRenderer.transform.localScale.y;
        }

        return(Mathf.Clamp(targetCoordinate, halfOfScreen + clampMin, clampMax - halfOfScreen));
    }
    public static IEnumerator LinearShake(this Camera cam, float duration, float magnitude, CameraAxis axis)
    {
        for (float time = 0; time < duration; time += Time.deltaTime) {
            float x,y,z;
            Vector3 offset;
            x = Random.Range(-magnitude, magnitude);
            y = Random.Range(-magnitude, magnitude);
            z = Random.Range(-magnitude, magnitude);

            switch (axis) {
            case CameraAxis.X:
                offset = new Vector3(x,0,0);
                break;
            case CameraAxis.Y:
                offset = new Vector3(0,y,0);
                break;
            case CameraAxis.Z:
                offset = new Vector3(0,0,z);
                break;
            case CameraAxis.XY:
                offset = new Vector3(x,y,0);
                break;
            case CameraAxis.XZ:
                offset = new Vector3(x,0,z);
                break;
            case CameraAxis.YZ:
                offset = new Vector3(0,y,z);
                break;
            case CameraAxis.ALL:
                offset = new Vector3(x,y,z);
                break;
            default:
                offset = Vector3.zero;
                break;
            }

            cam.transform.position += offset;
            yield return new WaitForEndOfFrame();
            cam.transform.position -= offset;
        }
    }