Exemplo n.º 1
0
        IEnumerator VacuumToViewer(IVacuumable vacuumable)
        {
            var vacuumTransform = vacuumable.transform;
            var startPosition   = vacuumTransform.position;
            var startRotation   = vacuumTransform.rotation;

            var offset = defaultOffset;

            offset.z += vacuumable.vacuumBounds.extents.z;
            offset   *= this.GetViewerScale();

            var camera       = CameraUtils.GetMainCamera().transform;
            var destPosition = camera.position + MathUtilsExt.ConstrainYawRotation(camera.rotation) * offset;
            var destRotation = Quaternion.LookRotation(camera.forward) * defaultTilt;

            var         currentValue    = 0f;
            var         currentVelocity = 0f;
            var         currentDuration = 0f;
            const float kTargetValue    = 1f;
            const float kTargetDuration = 0.5f;

            while (currentDuration < kTargetDuration)
            {
                currentDuration         += Time.deltaTime;
                currentValue             = MathUtilsExt.SmoothDamp(currentValue, kTargetValue, ref currentVelocity, kTargetDuration, Mathf.Infinity, Time.deltaTime);
                vacuumTransform.position = Vector3.Lerp(startPosition, destPosition, currentValue);
                vacuumTransform.rotation = Quaternion.Lerp(startRotation, destRotation, currentValue);
                yield return(null);
            }

            m_VacuumingCoroutines.Remove(vacuumTransform);
        }
Exemplo n.º 2
0
    IEnumerator VacuumToViewer(IVacuumable vacuumable)
    {
        var vacuumTransform = vacuumable.transform;
        //m_Vacuuming = true;
        var startPosition = vacuumTransform.position;
        var startRotation = vacuumTransform.rotation;

        var camera        = U.Camera.GetMainCamera().transform;
        var cameraForward = camera.forward;

        cameraForward.y = 0;
        var vacuumForward = vacuumTransform.forward;

        vacuumForward.y = 0;
        var cameraYaw = Quaternion.FromToRotation(vacuumForward, cameraForward);

        var offset = defaultOffset;

        offset.z += vacuumable.vacuumBounds.extents.z;

        var         destPosition    = camera.position + U.Math.ConstrainYawRotation(camera.rotation) * offset;
        var         destRotation    = vacuumTransform.rotation * cameraYaw;
        var         currentValue    = 0f;
        var         currentVelocity = 0f;
        var         currentDuration = 0f;
        const float kTargetValue    = 1f;
        const float kTargetDuration = 0.5f;

        while (currentDuration < kTargetDuration)
        {
            currentDuration         += Time.unscaledDeltaTime;
            currentValue             = U.Math.SmoothDamp(currentValue, kTargetValue, ref currentVelocity, kTargetDuration, Mathf.Infinity, Time.unscaledDeltaTime);
            vacuumTransform.position = Vector3.Lerp(startPosition, destPosition, currentValue);
            vacuumTransform.rotation = Quaternion.Lerp(startRotation, destRotation, currentValue);
            yield return(null);
        }

        m_VacuumingCoroutines.Remove(vacuumTransform);
    }