Ejemplo n.º 1
0
        /**
         * <summary>Creates a new class that mixes its values with another class</summary>
         * <param name="otherData">The other data to mix with</param>
         * <param name="otherDataWeight">The blending weight of the other data</param>
         * <param name="slerpRotation">If True, rotation is Slerped, not Lerped</param>
         * <returns>The mixed class</returns>
         */
        public GameCameraData CreateMix(GameCameraData otherData, float otherDataWeight, bool slerpRotation = false)
        {
            if (otherDataWeight <= 0f)
            {
                return(this);
            }

            if (otherDataWeight >= 1f)
            {
                return(otherData);
            }

            GameCameraData mixData = new GameCameraData();

            mixData.is2D = otherData.is2D;

            if (mixData.is2D)
            {
                float offsetX = AdvGame.Lerp(perspectiveOffset.x, otherData.perspectiveOffset.x, otherDataWeight);
                float offsetY = AdvGame.Lerp(perspectiveOffset.y, otherData.perspectiveOffset.y, otherDataWeight);

                mixData.perspectiveOffset = new Vector2(offsetX, offsetY);
            }

            mixData.position = Vector3.Lerp(position, otherData.position, otherDataWeight);
            mixData.rotation = (slerpRotation)
                                                                ? Quaternion.Lerp(rotation, otherData.rotation, otherDataWeight)
                                                                : Quaternion.Slerp(rotation, otherData.rotation, otherDataWeight);

            mixData.isOrthographic   = otherData.isOrthographic;
            mixData.fieldOfView      = Mathf.Lerp(fieldOfView, otherData.fieldOfView, otherDataWeight);
            mixData.orthographicSize = Mathf.Lerp(orthographicSize, otherData.orthographicSize, otherDataWeight);
            mixData.focalDistance    = Mathf.Lerp(focalDistance, otherData.focalDistance, otherDataWeight);

                        #if ALLOW_PHYSICAL_CAMERA
            mixData.usePhysicalProperties = otherData.usePhysicalProperties;
            mixData.sensorSize            = Vector2.Lerp(sensorSize, otherData.sensorSize, otherDataWeight);
            mixData.lensShift             = Vector2.Lerp(lensShift, otherData.lensShift, otherDataWeight);
                        #endif

            return(mixData);
        }
Ejemplo n.º 2
0
        private IEnumerator _UpdateMovement()
        {
            while (isMoving)
            {
                if (Time.time < moveStartTime + moveChangeTime)
                {
                    if (transformType == TransformType.Translate || transformType == TransformType.CopyMarker)
                    {
                        if (moveMethod == MoveMethod.Curved)
                        {
                            transform.localPosition = Vector3.Slerp(startPosition, endPosition, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                        }
                        else
                        {
                            transform.localPosition = AdvGame.Lerp(startPosition, endPosition, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                        }
                    }

                    if (transformType == TransformType.Rotate || transformType == TransformType.CopyMarker)
                    {
                        if (doEulerRotation)
                        {
                            if (moveMethod == MoveMethod.Curved)
                            {
                                transform.localEulerAngles = Vector3.Slerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                            }
                            else
                            {
                                transform.localEulerAngles = AdvGame.Lerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                            }
                        }
                        else
                        {
                            if (moveMethod == MoveMethod.Curved)
                            {
                                transform.localRotation = Quaternion.Slerp(startRotation, endRotation, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                            }
                            else
                            {
                                transform.localRotation = AdvGame.Lerp(startRotation, endRotation, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                            }
                        }
                    }

                    if (transformType == TransformType.Scale || transformType == TransformType.CopyMarker)
                    {
                        if (moveMethod == MoveMethod.Curved)
                        {
                            transform.localScale = Vector3.Slerp(startScale, endScale, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                        }
                        else
                        {
                            transform.localScale = AdvGame.Lerp(startScale, endScale, AdvGame.Interpolate(moveStartTime, moveChangeTime, moveMethod, timeCurve));
                        }
                    }
                }
                else
                {
                    EndMovement();
                }

                yield return(new WaitForFixedUpdate());
            }

            StopCoroutine("_UpdateMovement");
        }
Ejemplo n.º 3
0
        private void Update()
        {
            if (positionChangeTime > 0f)
            {
                if (Time.time < positionStartTime + positionChangeTime)
                {
                    if (positionMethod == MoveMethod.Curved)
                    {
                        transform.localPosition = Vector3.Slerp(startPosition, endPosition, AdvGame.Interpolate(positionStartTime, positionChangeTime, positionMethod, positionTimeCurve));
                    }
                    else
                    {
                        transform.localPosition = AdvGame.Lerp(startPosition, endPosition, AdvGame.Interpolate(positionStartTime, positionChangeTime, positionMethod, positionTimeCurve));
                    }
                }
                else
                {
                    transform.localPosition = endPosition;
                    positionChangeTime      = 0f;
                }
            }

            if (rotateChangeTime > 0f)
            {
                if (Time.time < rotateStartTime + rotateChangeTime)
                {
                    if (doEulerRotation)
                    {
                        if (rotateMethod == MoveMethod.Curved)
                        {
                            transform.localEulerAngles = Vector3.Slerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                        else
                        {
                            transform.localEulerAngles = AdvGame.Lerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                    }
                    else
                    {
                        if (rotateMethod == MoveMethod.Curved)
                        {
                            transform.localRotation = Quaternion.Slerp(startRotation, endRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                        else
                        {
                            transform.localRotation = AdvGame.Lerp(startRotation, endRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                    }
                }
                else
                {
                    if (doEulerRotation)
                    {
                        transform.localEulerAngles = endEulerRotation;
                    }
                    else
                    {
                        transform.rotation = endRotation;
                    }
                    rotateChangeTime = 0f;
                }
            }

            if (scaleChangeTime > 0f)
            {
                if (Time.time < scaleStartTime + scaleChangeTime)
                {
                    if (scaleMethod == MoveMethod.Curved)
                    {
                        transform.localScale = Vector3.Slerp(startScale, endScale, AdvGame.Interpolate(scaleStartTime, scaleChangeTime, scaleMethod, scaleTimeCurve));
                    }
                    else
                    {
                        transform.localScale = AdvGame.Lerp(startScale, endScale, AdvGame.Interpolate(scaleStartTime, scaleChangeTime, scaleMethod, scaleTimeCurve));
                    }
                }
                else
                {
                    transform.localScale = endScale;
                    scaleChangeTime      = 0f;
                }
            }
        }
Ejemplo n.º 4
0
        private void Update()
        {
            if (positionChangeTime > 0f)
            {
                if (Time.time < positionStartTime + positionChangeTime)
                {
                    if (inWorldSpace)
                    {
                        transform.position = (positionMethod == MoveMethod.Curved)
                                                        ? Vector3.Slerp(startPosition, endPosition, AdvGame.Interpolate(positionStartTime, positionChangeTime, positionMethod, positionTimeCurve))
                                                        :AdvGame.Lerp(startPosition, endPosition, AdvGame.Interpolate(positionStartTime, positionChangeTime, positionMethod, positionTimeCurve));
                    }
                    else
                    {
                        transform.localPosition = (positionMethod == MoveMethod.Curved)
                                                        ? Vector3.Slerp(startPosition, endPosition, AdvGame.Interpolate(positionStartTime, positionChangeTime, positionMethod, positionTimeCurve))
                                                        :AdvGame.Lerp(startPosition, endPosition, AdvGame.Interpolate(positionStartTime, positionChangeTime, positionMethod, positionTimeCurve));
                    }
                }
                else
                {
                    if (inWorldSpace)
                    {
                        transform.position = endPosition;
                    }
                    else
                    {
                        transform.localPosition = endPosition;
                    }

                    positionChangeTime = 0f;
                }
            }

            if (rotateChangeTime > 0f)
            {
                if (Time.time < rotateStartTime + rotateChangeTime)
                {
                    if (doEulerRotation)
                    {
                        if (inWorldSpace)
                        {
                            transform.eulerAngles = (rotateMethod == MoveMethod.Curved)
                                                                ? Vector3.Slerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve))
                                                                : AdvGame.Lerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                        else
                        {
                            transform.localEulerAngles = (rotateMethod == MoveMethod.Curved)
                                                        ? Vector3.Slerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve))
                                                        : AdvGame.Lerp(startEulerRotation, endEulerRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                    }
                    else
                    {
                        if (inWorldSpace)
                        {
                            transform.rotation = (rotateMethod == MoveMethod.Curved)
                                                                ? Quaternion.Slerp(startRotation, endRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve))
                                                                : AdvGame.Lerp(startRotation, endRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                        else
                        {
                            transform.localRotation = (rotateMethod == MoveMethod.Curved)
                                                                ? Quaternion.Slerp(startRotation, endRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve))
                                                                : AdvGame.Lerp(startRotation, endRotation, AdvGame.Interpolate(rotateStartTime, rotateChangeTime, rotateMethod, rotateTimeCurve));
                        }
                    }
                }
                else
                {
                    if (doEulerRotation)
                    {
                        if (inWorldSpace)
                        {
                            transform.eulerAngles = endEulerRotation;
                        }
                        else
                        {
                            transform.localEulerAngles = endEulerRotation;
                        }
                    }
                    else
                    {
                        if (inWorldSpace)
                        {
                            transform.rotation = endRotation;
                        }
                        else
                        {
                            transform.localRotation = endRotation;
                        }
                    }

                    if (character != null)
                    {
                        character.SetLookDirection(character.TransformRotation * Vector3.forward, true);
                        character.StopTurning();
                    }

                    rotateChangeTime = 0f;
                }
            }

            if (scaleChangeTime > 0f)
            {
                if (Time.time < scaleStartTime + scaleChangeTime)
                {
                    if (scaleMethod == MoveMethod.Curved)
                    {
                        transform.localScale = Vector3.Slerp(startScale, endScale, AdvGame.Interpolate(scaleStartTime, scaleChangeTime, scaleMethod, scaleTimeCurve));
                    }
                    else
                    {
                        transform.localScale = AdvGame.Lerp(startScale, endScale, AdvGame.Interpolate(scaleStartTime, scaleChangeTime, scaleMethod, scaleTimeCurve));
                    }
                }
                else
                {
                    transform.localScale = endScale;
                    scaleChangeTime      = 0f;
                }
            }
        }
Ejemplo n.º 5
0
        public void _LateUpdate()
        {
            if (KickStarter.settingsManager && KickStarter.settingsManager.IsInLoadingScene())
            {
                return;
            }

            if (KickStarter.stateHandler.gameState == GameState.Normal)
            {
                if (attachedCamera)
                {
                    if (lastNavCamera != attachedCamera)
                    {
                        lastNavCamera2 = lastNavCamera;
                    }

                    lastNavCamera = attachedCamera;
                }
            }

            if (attachedCamera && (!(attachedCamera is GameCamera25D)))
            {
                if (!isSmoothChanging)
                {
                    transform.rotation = attachedCamera.transform.rotation;
                    transform.position = attachedCamera.transform.position;
                    focalDistance      = attachedCamera.focalDistance;

                    if (attachedCamera is GameCamera2D)
                    {
                        GameCamera2D cam2D = (GameCamera2D)attachedCamera;
                        perspectiveOffset = cam2D.perspectiveOffset;
                        if (!_camera.orthographic)
                        {
                            _camera.projectionMatrix = AdvGame.SetVanishingPoint(_camera, perspectiveOffset);
                        }
                        else
                        {
                            _camera.orthographicSize = attachedCamera._camera.orthographicSize;
                        }
                    }

                    else
                    {
                        _camera.fieldOfView = attachedCamera._camera.fieldOfView;
                        if (cursorAffectsRotation)
                        {
                            SetlookAtTransformation();
                            transform.LookAt(lookAtTransform, attachedCamera.transform.up);
                        }
                    }
                }
                else
                {
                    // Move from one GameCamera to another
                    if (Time.time < startTime + changeTime)
                    {
                        if (attachedCamera is GameCamera2D)
                        {
                            GameCamera2D cam2D = (GameCamera2D)attachedCamera;

                            perspectiveOffset.x = AdvGame.Lerp(startPerspectiveOffset.x, cam2D.perspectiveOffset.x, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                            perspectiveOffset.y = AdvGame.Lerp(startPerspectiveOffset.y, cam2D.perspectiveOffset.y, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));

                            _camera.ResetProjectionMatrix();
                        }

                        if (moveMethod == MoveMethod.Curved)
                        {
                            // Don't slerp y position as this will create a "bump" effect
                            Vector3 newPosition = Vector3.Slerp(startPosition, attachedCamera.transform.position, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                            newPosition.y      = Mathf.Lerp(startPosition.y, attachedCamera.transform.position.y, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                            transform.position = newPosition;

                            transform.rotation = Quaternion.Slerp(startRotation, attachedCamera.transform.rotation, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                        }
                        else
                        {
                            transform.position = AdvGame.Lerp(startPosition, attachedCamera.transform.position, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                            transform.rotation = AdvGame.Lerp(startRotation, attachedCamera.transform.rotation, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                        }

                        focalDistance            = AdvGame.Lerp(startFocalDistance, attachedCamera.focalDistance, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                        _camera.fieldOfView      = AdvGame.Lerp(startFOV, attachedCamera._camera.fieldOfView, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));
                        _camera.orthographicSize = AdvGame.Lerp(startOrtho, attachedCamera._camera.orthographicSize, AdvGame.Interpolate(startTime, changeTime, moveMethod, timeCurve));

                        if (attachedCamera is GameCamera2D && !_camera.orthographic)
                        {
                            _camera.projectionMatrix = AdvGame.SetVanishingPoint(_camera, perspectiveOffset);
                        }
                    }
                    else
                    {
                        LookAtCentre();
                        isSmoothChanging = false;
                    }
                }

                if (cursorAffectsRotation)
                {
                    lookAtTransform.localPosition = Vector3.Lerp(lookAtTransform.localPosition, lookAtTarget, Time.deltaTime * 3f);
                }
            }

            else if (attachedCamera && (attachedCamera is GameCamera25D))
            {
                transform.position = attachedCamera.transform.position;
                transform.rotation = attachedCamera.transform.rotation;
            }

            // Shake
            if (shakeIntensity > 0f)
            {
                if (shakeMove)
                {
                    shakePosition = Random.insideUnitSphere * shakeIntensity * 0.5f;
                }

                shakeRotation = new Vector3
                                (
                    Random.Range(-shakeIntensity, shakeIntensity) * 0.2f,
                    Random.Range(-shakeIntensity, shakeIntensity) * 0.2f,
                    Random.Range(-shakeIntensity, shakeIntensity) * 0.2f
                                );

                shakeIntensity = Mathf.Lerp(shakeStartIntensity, 0f, AdvGame.Interpolate(shakeStartTime, shakeDuration, MoveMethod.Linear, null));

                transform.position         += shakePosition;
                transform.localEulerAngles += shakeRotation;
            }
            else if (shakeIntensity < 0f)
            {
                StopShaking();
            }
        }