示例#1
0
    public void Update()
    {
        if (transitionPoint > 1f - TresholdToAcceptNextTarget)
        {
            CameraShot selectedShot = CameraShot.FirstHighestPrioritySelected;
            if (nextCameraShot != selectedShot)
            {
                lastCameraShot           = nextCameraShot;
                lastPivot                = curPivot;
                lastRotation             = curRotation;
                lastDistance             = curDistance;
                lastControlledRotation   = curControlledRotation;
                nextCameraShot           = selectedShot;
                transitionPoint          = 0f;
                curControlledRotation    = Vector2.zero;
                rotationInputSmoothPoint = Vector2.zero;
                rotationInputSmoothSpeed = Vector2.zero;
                if (lastCameraShot != null)
                {
                    lastCameraShot.onEndTargeted.Invoke();
                }
                if (nextCameraShot != null)
                {
                    onTargetingNewShot.Invoke();
                    nextCameraShot.onBeginTargeted.Invoke();
                }
                else
                {
                    onTargetingNoShot.Invoke();
                }
            }
        }

        Vector3    nextPivot    = curPivot;
        Quaternion nextRotation = curRotation;
        float      nextDistance = curDistance;

        if (nextCameraShot != null)
        {
            if (allowInput)
            {
                Vector2 rotationInput = new Vector2(Input.GetAxis(verticalRotationInputName) * rotationInputSpeed.y, Input.GetAxis(horizontalRotationInputName) * rotationInputSpeed.x) * nextCameraShot.controlledRotationSpeedMultiplier;
                if (invertYAxis)
                {
                    rotationInput.y *= -1f;
                }
                rotationInputSmoothPoint = Vector2.SmoothDamp(rotationInputSmoothPoint, rotationInput, ref rotationInputSmoothSpeed, inputSmoothTime);
                curControlledRotation   += rotationInputSmoothPoint * sensibility;
            }
            nextCameraShot.ClampControlledRotation(ref curControlledRotation);
            nextPivot    = nextCameraShot.GetCurrentPivot(ActionInput);
            nextRotation = nextCameraShot.GetCurrentRotation(curControlledRotation);
            nextDistance = nextCameraShot.GetCurrentDistance(ActionInput, curControlledRotation);
        }
        if (lastCameraShot != null)
        {
            lastPivot    = lastCameraShot.GetCurrentPivot(ActionInput);
            lastRotation = lastCameraShot.GetCurrentRotation(lastControlledRotation);
            lastDistance = lastCameraShot.GetCurrentDistance(ActionInput, lastControlledRotation);
        }
        transitionPoint = Mathf.SmoothDamp(transitionPoint, 1f, ref transitionSpeed, transitionSmoothTime);
        curPivot        = Vector3.Slerp(lastPivot, nextPivot, transitionPoint);
        curRotation     = Quaternion.Lerp(lastRotation, nextRotation, transitionPoint);
        curDistance     = Mathf.Lerp(lastDistance, nextDistance, transitionPoint);
        ApplyTransform();
    }