示例#1
0
    /// <summary>
    /// Rotate the camera towards the destination rotation, slowing down while reaching it.
    /// </summary>
    /// <returns></returns>
    private IEnumerator NormalLerpRotating(CameraTarget target, TargetParameters.StaticTargetRotationParameters parameters)
    {
        while (Quaternion.Angle(transform.rotation, target.transform.rotation) > parameters.LerpThreshold)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, target.transform.rotation, parameters.LerpSpeed * Time.deltaTime);
            yield return(null);
        }

        CameraEventSystem.CameraTargetRotationReached(target, parameters);
    }
示例#2
0
    /// <summary>
    /// Rotate the camera towards the destination rotation at constant speed, reaching in the given time.
    /// </summary>
    /// <returns></returns>
    private IEnumerator ConstantLerpRotating(CameraTarget target, TargetParameters.StaticTargetRotationParameters parameters)
    {
        float      elapsedRotatingLerpTime = 0;
        Quaternion startingRotation        = transform.rotation;
        float      step;

        while (elapsedRotatingLerpTime < parameters.Duration)
        {
            step = elapsedRotatingLerpTime / parameters.Duration;
            elapsedRotatingLerpTime += Time.deltaTime;
            transform.rotation       = Quaternion.Slerp(startingRotation, target.transform.rotation, step);
            yield return(null);
        }

        CameraEventSystem.CameraTargetRotationReached(target, parameters);
    }
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (TreatTargetAs == TargetType.Static) //STATIC TARGET
            {
                TargetParameters.StaticTargetRotationParameters rotParams = TargetParameters.GetDefaultStaticRotationParameters();
                rotParams.Duration = 8f;
                cameraTest.SetStaticCameraTarget(Target, rotParams);

                TargetParameters.StaticTargetPositionParameters posParams = TargetParameters.GetDefaultStaticPositionParameters();
                posParams.CameraExecutionMode = CameraExecutionMode.CustomLerp;
                posParams.StartSCParameters.SinIntensityChangeTimer = 2f;
                posParams.StartSCParameters.CosIntensityChangeTimer = 2f;
                posParams.StartSCParameters.MinCosIntensity         = 0.1f;
                posParams.StartSCParameters.MaxCosIntensity         = 0.12f;
                posParams.StartSCParameters.MinSinIntensity         = 0.1f;
                posParams.StartSCParameters.MaxSinIntensity         = 0.11f;

                posParams.SteadyCamOnStart = SteadyCamBehaviour.TurnOnAndOverride;
                posParams.SteadyCamOnEnd   = SteadyCamBehaviour.TurnOnAndOverride;

                cameraTest.SetStaticCameraTarget(Target, posParams);
            }
            else //DYNAMIC TARGET
            {
                TargetParameters.DynamicTargetPositionParameters dynamicPosParams = TargetParameters.GetDefaultDynamicPositionParameters();
                dynamicPosParams.LerpSpeed = 2f;
                cameraTest.SetDynamicCameraTarget(Target.transform.GetChild(0).GetComponent <CameraTarget>(), dynamicPosParams);

                TargetParameters.DynamicTargetRotationParameters dynamicRotParams = TargetParameters.GetDefaultDynamicRotationParameters();
                dynamicRotParams.DynamicRotationBehaviour = DynamicRotationBehaviour.LookAt;
                dynamicRotParams.LerpSpeed = 5f;
                cameraTest.SetDynamicCameraTarget(Target, dynamicRotParams);
            }
        }
        //else if (Input.GetKey(KeyCode.LeftControl))
        //{
        //    NextTarget();
        //}
    }
示例#4
0
    /// <summary>
    /// The camera has reached the target rotation.
    /// </summary>
    private void CameraTargetRotationReached(CameraTarget target, TargetParameters.StaticTargetRotationParameters parameters)
    {
        Rotating = false;
        Debug.Log("ROTATION REACHED");

        switch (parameters.SteadyCamOnEnd)
        {
        case SteadyCamBehaviour.Ignore:
            return;

        case SteadyCamBehaviour.TurnOnAndOverride:
            if (steadyCamCoroutine == null)
            {
                ActivateSteadyCam(parameters.EndSCParameters);
            }
            else
            {
                steadyCamParameters = parameters.EndSCParameters;
            }
            break;

        case SteadyCamBehaviour.TurnOff:
            if (steadyCamCoroutine != null)
            {
                StopCoroutine(steadyCamCoroutine);
                StartCoroutine(RecenterCamera());
            }
            break;

        case SteadyCamBehaviour.OverrideIfOn:
            if (steadyCamCoroutine != null)
            {
                steadyCamParameters = parameters.EndSCParameters;
            }
            break;
        }

        Debug.Log(rotationCoroutine != null);
    }
示例#5
0
 public static void CameraTargetRotationReached(CameraTarget reachedTarget, TargetParameters.StaticTargetRotationParameters parameters)
 {
     CameraTargetRotationReachedEvent.Invoke(reachedTarget, parameters);
 }
示例#6
0
 public static void SetCameraStaticTargetRotation(CameraTarget targetRotation, TargetParameters.StaticTargetRotationParameters parameters)
 {
     SetCameraStaticTargetRotationEvent.Invoke(targetRotation, parameters);
 }
示例#7
0
 public void SetStaticCameraTarget(CameraTarget cameraTarget, TargetParameters.StaticTargetPositionParameters posParameters, TargetParameters.StaticTargetRotationParameters rotParameters)
 {
     CameraEventSystem.SetCameraStaticTargetPosition(cameraTarget, posParameters);
     CameraEventSystem.SetCameraStaticTargetRotation(cameraTarget, rotParameters);
 }
示例#8
0
 public void SetStaticCameraTarget(CameraTarget cameraTarget, TargetParameters.StaticTargetRotationParameters parameters)
 {
     CameraEventSystem.SetCameraStaticTargetRotation(cameraTarget, parameters);
 }
示例#9
0
 /// <summary>
 /// Immediately rotate the camera to match the target rotation.
 /// </summary>
 private void ImmediateRotating(CameraTarget target, TargetParameters.StaticTargetRotationParameters parameters)
 {
     transform.rotation = target.transform.rotation;
     CameraEventSystem.CameraTargetRotationReached(target, parameters);
 }
示例#10
0
    private void SetCameraStaticTargetRotation(CameraTarget target, TargetParameters.StaticTargetRotationParameters parameters)
    {
        if (rotationCoroutine != null)
        {
            StopCoroutine(rotationCoroutine);
        }

        switch (parameters.CameraExecutionMode)
        {
        case CameraExecutionMode.Immediate:
            ImmediateRotating(target, parameters);
            break;

        case CameraExecutionMode.ConstantLerp:
            rotationCoroutine = StartCoroutine(ConstantLerpRotating(target, parameters));
            break;

        case CameraExecutionMode.NormalLerp:
            rotationCoroutine = StartCoroutine(NormalLerpRotating(target, parameters));
            break;

        case CameraExecutionMode.SmoothLerp:
            rotationCoroutine = StartCoroutine(SmoothLerpRotating(target, parameters));
            break;

        case CameraExecutionMode.CustomLerp:
            rotationCoroutine = StartCoroutine(customStaticRotatingLerp(target, parameters));
            break;
        }

        Rotating = true;

        switch (parameters.SteadyCamOnStart)
        {
        case SteadyCamBehaviour.Ignore:
            return;

        case SteadyCamBehaviour.TurnOnAndOverride:
            if (steadyCamCoroutine == null)
            {
                ActivateSteadyCam(parameters.StartSCParameters);
            }
            else
            {
                steadyCamParameters = parameters.StartSCParameters;
            }
            break;

        case SteadyCamBehaviour.TurnOff:
            if (steadyCamCoroutine != null)
            {
                StopCoroutine(steadyCamCoroutine);
                StartCoroutine(RecenterCamera());
            }
            break;

        case SteadyCamBehaviour.OverrideIfOn:
            if (steadyCamCoroutine != null)
            {
                steadyCamParameters = parameters.StartSCParameters;
            }
            break;
        }
    }