public void update()
        {
            Vector2 cameraPos         = transform.position;
            Vector2 objectToFollowPos = ObjectToFollow.position;

            float halfWidth  = _camera.bounds.width / 2.0f;
            float halfHeight = _camera.bounds.height / 2.0f;

            if (!Deadzone.Contains(objectToFollowPos))
            {
                cameraPos = Lerps.ease(EaseType.QuadInOut, cameraPos, objectToFollowPos, SmoothTime, 1.0f);
                // cameraPos = Lerps.lerpDamp(cameraPos, objectToFollowPos, SmoothSpeed);
            }
            if (cameraPos.X - halfWidth < MapEdge.Min.X)
            {
                cameraPos.X = MapEdge.Min.X + halfWidth;
            }
            if (cameraPos.Y - halfHeight < MapEdge.Min.Y)
            {
                cameraPos.Y = MapEdge.Min.Y + halfHeight;
            }
            if (cameraPos.X + halfWidth > MapEdge.Max.X)
            {
                cameraPos.X = MapEdge.Max.X - halfWidth;
            }
            if (cameraPos.Y + halfHeight > MapEdge.Max.Y)
            {
                cameraPos.Y = MapEdge.Max.Y - halfHeight;
            }



            transform.position = cameraPos;
        }
示例#2
0
 public override void UpdateValue(float elapsedTime)
 {
     this.TweenTarget.TweenedValue = Lerps.Ease(
         this.EaseType,
         this.FromValue,
         this.ToValue,
         elapsedTime,
         this.Duration);
 }
        /// <summary>Gets the new (interpolated) camera orbit position.</summary>
        /// <param name="orbitAngles">Angle to orbit</param>
        /// <param name="deltaTime"></param>
        /// <returns></returns>
        public Vector3 GetOrbitPosition(Vector3 orbitAngles, float deltaTime)
        {
            //get new camera position (this can/will change the distance from the target, but it is interpolated seperately next anyway)
            Vector3 desiredPos = GetDesiredOrbitPositionFromAngles(orbitAngles);
            Vector3 newCamPos  = locomotion.MoveCameraInterpolated(desiredPos, camParams.orbitSpeed, deltaTime);

            //interpolate distance from target separately
            Vector3 newOffset   = newCamPos - followTarget.transform.position;                                                                                                                        //convert new cam position back to a world space offset from follow target
            float   newDistance = Lerps.Smootherstep((cam.transform.position - followTarget.transform.position).magnitude, camParams.desiredOrbitDistance, camParams.orbitSpeedDistance * deltaTime); //interpolate between current offset distance and desired distance

            return(followTarget.transform.position + newOffset.normalized * newDistance);                                                                                                             //scale normalised offset by new distance and convert back to world position
        }
        public Vector3 GetTargetFollowPosition(float deltaTime, float virtualCameraSphereRadius)
        {
            //get desired offset based on whether target is moving towards or away from camera. If we add more camera-target orientation states,
            //will need to do this a better way
            Vector3 desiredOffset;
            float   followSpeedHorz;
            float   followSpeedVert;
            float   followSpeedDistance;

            if (stateController.GetOrientationState() == CameraTargetOrientationState.TowardsCamera && camParams.allowMoveTowardsCamera)
            {
                desiredOffset       = camParams.desiredFrontOffset;
                followSpeedHorz     = camParams.frontFollowSpeedOrientation;
                followSpeedVert     = camParams.frontFollowSpeedHeight;
                followSpeedDistance = camParams.frontFollowSpeedDistance;
            }
            else //moving away from camera
            {
                desiredOffset       = camParams.desiredOffset;
                followSpeedHorz     = camParams.followSpeedOrientation;
                followSpeedVert     = camParams.followSpeedHeight;
                followSpeedDistance = camParams.followSpeedDistance;
            }

            //get desired height offset based on follow height mode
            if (camParams.followHeightMode == FollowHeightMode.AboveGround)
            {
                desiredOffset.y = GetDesiredHeightAboveGroundOffset(virtualCameraSphereRadius);
            }

            //get desired position from offset
            Vector3 desiredPos = GetDesiredFollowPositionWorld(desiredOffset);

            //shorten follow distance if necessary
            desiredPos = occlusionAvoidance.ShortenFollowDistanceToAvoidRearOcclusion(desiredPos, virtualCameraSphereRadius);

            //increase follow speed if avoiding occlusion
            if (camParams.avoidFollowTargetOcclusion)
            {
                float occlusionSpeedIncrease = occlusionAvoidance.GetOcclusionFollowSpeedIncrease();
                followSpeedHorz += occlusionSpeedIncrease;
                followSpeedVert += occlusionSpeedIncrease;
            }
            //interpolate between current and desired positions
            Vector3 newCamPos = locomotion.MoveCameraInterpolated(desiredPos, followSpeedHorz, followSpeedVert, deltaTime);

            //interpolate distance from target separately
            float   desiredDistance = desiredOffset.magnitude;
            Vector3 newOffset       = newCamPos - followTarget.transform.position;                                               //convert new cam position back to a world space offset from follow target
            float   newDistance     = Lerps.Smootherstep(newOffset.magnitude, desiredDistance, followSpeedDistance * deltaTime); //interpolate between current offset distance and desired distance

            return(followTarget.transform.position + (newOffset.normalized * newDistance));                                      //scale normalised offset by new distance and convert back to world position
        }
示例#5
0
文件: Walk.cs 项目: toyboot4e/Rot
        protected override void UpdateValue()
        {
            var next = Lerps.Ease(_easeType, _fromValue, _toValue, _elapsedTime, _duration);

            // XXX: hack for rounding
            // var delta = _toValue - next;
            // if (Math.Abs(delta.X) < 1f && Math.Abs(delta.Y) < 1f) {
            // next = _toValue;
            // }

            _target.SetTweenedValue(next);
        }
    private void ValueChange()
    {
        //if(ScaleRef.Value < 20)
        //{
        //	tween?.Complete();
        //	tween            = transform.DOPunchScale(Vector3.one * ScaleRef.Value.Clamp(0.5f, 20), ScaleSpeed, 7);
        //	tween.onComplete -= OnComplete;
        //	tween.onComplete += OnComplete;
        //}
        //else
        {
            tween?.Complete();
            tween = transform.DOScale(Vector3.one * ScaleRef.Value.Clamp(0.5f, 20), 1);
        }

        WorldSettings.GameRadius = Lerps.Lerp(35f, 60f, ScaleRef.Value.Clamp(0, 2));
    }
示例#7
0
        /// <summary>
        /// the most common type of transition seems to be one that ticks progress from 0 - 1. This method takes care of that for you
        /// if your transition needs to have a _progress property ticked after the scene loads.
        /// </summary>
        /// <param name="duration">duration</param>
        /// <param name="reverseDirection">if true, _progress will go from 1 to 0. If false, it goes form 0 to 1</param>
        public IEnumerator tickEffectProgressProperty(Effect effect, float duration, EaseType easeType = EaseType.ExpoOut, bool reverseDirection = false)
        {
            var start         = reverseDirection ? 1f : 0f;
            var end           = reverseDirection ? 0f : 1f;
            var progressParam = effect.Parameters["_progress"];

            var elapsed = 0f;

            while (elapsed < duration)
            {
                elapsed += Time.deltaTime;
                var step = Lerps.ease(easeType, start, end, elapsed, duration);
                progressParam.SetValue(step);

                yield return(null);
            }
        }
        public override IEnumerator onBeginTransition()
        {
            yield return(null);

            var elapsed = 0f;

            while (elapsed < duration)
            {
                elapsed        += Time.deltaTime;
                _renderScale    = Lerps.ease(scaleEaseType, maxScale, minScale, elapsed, duration);
                _renderRotation = Lerps.ease(rotationEaseType, minRotation, maxRotation, elapsed, duration);

                yield return(null);
            }

            // load up the new Scene
            yield return(Core.startCoroutine(loadNextScene()));

            // dispose of our previousSceneRender. We dont need it anymore.
            previousSceneRender.Dispose();
            previousSceneRender = null;

            yield return(Coroutine.waitForSeconds(delayBeforeMaskOut));

            elapsed = 0f;
            while (elapsed < duration)
            {
                elapsed     += Time.deltaTime;
                _renderScale = Lerps.ease(
                    EaseHelper.oppositeEaseType(scaleEaseType),
                    minScale,
                    maxScale,
                    elapsed,
                    duration);
                _renderRotation = Lerps.ease(
                    EaseHelper.oppositeEaseType(rotationEaseType),
                    maxRotation,
                    minRotation,
                    elapsed,
                    duration);

                yield return(null);
            }

            transitionComplete();
        }
示例#9
0
        /// <summary>
        /// animates the letterbox in
        /// </summary>
        /// <returns>The in.</returns>
        /// <param name="letterboxSize">Letterbox size.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="easeType">Ease type.</param>
        public IEnumerator animateIn(float letterboxSize, float duration = 2, EaseType easeType = EaseType.ExpoOut)
        {
            // wait for any current animations to complete
            while (_isAnimating)
            {
                yield return(null);
            }

            _isAnimating = true;
            var elapsedTime = 0f;

            while (elapsedTime < duration)
            {
                elapsedTime       += Time.deltaTime;
                this.letterboxSize = Lerps.ease(easeType, 0, letterboxSize, elapsedTime, duration);
                yield return(null);
            }
            _isAnimating = false;
        }
示例#10
0
        public override IEnumerator OnBeginTransition()
        {
            yield return(null);

            // load up the new Scene
            yield return(Core.StartCoroutine(LoadNextScene()));

            var elapsed = 0f;

            while (elapsed < FadeDuration)
            {
                elapsed += Time.DeltaTime;
                _color   = Lerps.Ease(FadeEaseType, ref _fromColor, ref _toColor, elapsed, FadeDuration);

                yield return(null);
            }

            TransitionComplete();
        }
示例#11
0
        public override IEnumerator onBeginTransition()
        {
            yield return(null);

            // load up the new Scene
            yield return(Core.startCoroutine(loadNextScene()));

            var elapsed = 0f;

            while (elapsed < duration)
            {
                elapsed         += Time.deltaTime;
                _destinationRect = Lerps.ease(transitionEaseType, ref _textureBounds, ref _finalRenderRect, elapsed, duration);

                yield return(null);
            }

            transitionComplete();
        }
示例#12
0
        public IEnumerator TickEffectProgressProperty(
            IProgressEffect effect,
            float duration,
            EaseType easeType     = EaseType.ExpoOut,
            bool reverseDirection = false)
        {
            var start = reverseDirection ? 1f : 0f;
            var end   = reverseDirection ? 0f : 1f;

            var startAt = DateTime.Now;

            while ((DateTime.Now - startAt).TotalSeconds < duration)
            {
                var elapsed = (float)(DateTime.Now - startAt).TotalSeconds;
                var step    = Lerps.Ease(easeType, start, end, elapsed, duration);
                effect.Progress = step;

                yield return(null);
            }
        }
示例#13
0
        public override IEnumerator onBeginTransition()
        {
            // create a single pixel texture of our fadeToColor
            _overlayTexture = Graphics.createSingleColorTexture(1, 1, fadeToColor);

            var elapsed = 0f;

            while (elapsed < fadeOutDuration)
            {
                elapsed += Time.deltaTime;
                _color   = Lerps.ease(fadeEaseType, ref _toColor, ref _fromColor, elapsed, fadeOutDuration);

                yield return(null);
            }

            // load up the new Scene
            yield return(Core.startCoroutine(loadNextScene()));

            // dispose of our previousSceneRender. We dont need it anymore.
            previousSceneRender.Dispose();
            previousSceneRender = null;

            yield return(Coroutine.waitForSeconds(delayBeforeFadeInDuration));

            elapsed = 0f;
            while (elapsed < fadeInDuration)
            {
                elapsed += Time.deltaTime;
                _color   = Lerps.ease(
                    EaseHelper.oppositeEaseType(fadeEaseType),
                    ref _fromColor,
                    ref _toColor,
                    elapsed,
                    fadeInDuration);

                yield return(null);
            }

            transitionComplete();
            _overlayTexture.Dispose();
        }
示例#14
0
        /// <summary>
        /// animates the flash
        /// </summary>
        /// <returns>The in.</returns>
        /// <param name="letterboxSize">Letterbox size.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="easeType">Ease type.</param>
        public IEnumerator animate(float fadeDuration, EaseType easeType = EaseType.SineOut)
        {
            // wait for any current animations to complete
            while (_isAnimating)
            {
                yield return(null);
            }

            flashIntensity = 1.0f;

            _isAnimating = true;
            var elapsedTime = 0f;

            while (elapsedTime < fadeDuration)
            {
                elapsedTime   += Time.deltaTime;
                flashIntensity = Lerps.ease(easeType, 1, 0, elapsedTime, fadeDuration);
                yield return(null);
            }
            _isAnimating = false;
        }
示例#15
0
        public override IEnumerator OnBeginTransition()
        {
            yield return(null);

            var elapsed = 0f;

            while (elapsed < Duration)
            {
                elapsed        += Time.DeltaTime;
                _renderScale    = Lerps.Ease(ScaleEaseType, MaxScale, MinScale, elapsed, Duration);
                _renderRotation = Lerps.Ease(RotationEaseType, MinRotation, MaxRotation, elapsed, Duration);

                yield return(null);
            }

            // load up the new Scene
            yield return(Core.StartCoroutine(LoadNextScene()));

            // dispose of our previousSceneRender. We dont need it anymore.
            PreviousSceneRender.Dispose();
            PreviousSceneRender = null;

            yield return(Coroutine.WaitForSeconds(DelayBeforeMaskOut));

            elapsed = 0f;
            while (elapsed < Duration)
            {
                elapsed     += Time.DeltaTime;
                _renderScale = Lerps.Ease(EaseHelper.OppositeEaseType(ScaleEaseType), MinScale, MaxScale, elapsed,
                                          Duration);
                _renderRotation = Lerps.Ease(EaseHelper.OppositeEaseType(RotationEaseType), MaxRotation, MinRotation,
                                             elapsed, Duration);

                yield return(null);
            }

            TransitionComplete();
        }
示例#16
0
        public override IEnumerator OnBeginTransition()
        {
            var startAt = DateTime.Now;

            while ((DateTime.Now - startAt).TotalSeconds < this.FadeOutDuration)
            {
                var elapsed = (float)(DateTime.Now - startAt).TotalSeconds;
                this.color = Lerps.Ease(
                    this.FadeEaseType,
                    ref this.fromColor,
                    ref this.toColor,
                    elapsed,
                    this.FadeOutDuration);

                yield return(null);
            }

            this.SetNextScene();

            yield return(DefaultCoroutines.Wait(this.DelayBeforeFadeInDuration));

            startAt = DateTime.Now;
            while ((DateTime.Now - startAt).TotalSeconds < this.FadeInDuration)
            {
                var elapsed = (float)(DateTime.Now - startAt).TotalSeconds;
                this.color = Lerps.Ease(
                    EaseHelper.OppositeEaseType(this.FadeEaseType),
                    ref this.toColor,
                    ref this.fromColor,
                    elapsed,
                    this.FadeInDuration);

                yield return(null);
            }

            this.TransitionComplete();
        }
示例#17
0
        public override IEnumerator OnBeginTransition()
        {
            yield return(null);

            var startAt = DateTime.Now;

            while ((DateTime.Now - startAt).TotalSeconds < this.Duration)
            {
                var elapsed = (float)(DateTime.Now - startAt).TotalSeconds;
                this.destinationRect = Lerps.Ease(
                    this.TransitionEaseType,
                    this.PreviousSceneRender.Bounds,
                    this.finalRenderRect,
                    elapsed,
                    this.Duration);

                yield return(null);
            }

            this.SetNextScene();

            startAt = DateTime.Now;
            while ((DateTime.Now - startAt).TotalSeconds < this.Duration)
            {
                var elapsed = (float)(DateTime.Now - startAt).TotalSeconds;
                this.destinationRect = Lerps.Ease(
                    this.TransitionEaseType,
                    this.finalRenderRect,
                    this.PreviousSceneRender.Bounds,
                    elapsed,
                    this.Duration);

                yield return(null);
            }

            this.TransitionComplete();
        }
示例#18
0
 public Vector3 MoveCameraInterpolated(Vector3 desiredPos, float horizontalMoveSpeed, float verticalMoveSpeed, float deltaTime)
 {
     return(Lerps.Smootherstep(cam.transform.position, desiredPos, horizontalMoveSpeed * deltaTime, verticalMoveSpeed * deltaTime));
 }
示例#19
0
 public static float Lerp(this float start, float end, float time, bool clamp = false) => Lerps.Lerp(start, end, time, clamp);
示例#20
0
    private void OffsetFromTarget(ref Vector3 newPos)
    {
        Vector3 desiredPos;

        //Get desired camera position based on state
        switch (state)
        {
        case State.TargetMovingTowardsCamera:
            Vector3 frontOffset = new Vector3(desiredOffset.x, desiredOffset.y, Mathf.Abs(desiredOffset.z));
            desiredPos = followTargetPos + (worldSpaceOffset ? frontOffset : followTarget.transform.TransformDirection(frontOffset));
            break;

        case State.FollowingTarget:
        default:
            if (worldSpaceOffset)
            {
                desiredPos = AvoidCollision(followTargetPos + desiredOffset);
            }
            else
            {
                desiredPos = AvoidCollision(followTargetPos + followTarget.transform.TransformDirection(desiredOffset));
            }

            break;
        }

        //Add cam whisker offset, if using
        if (useCamWhiskers)
        {
            desiredPos += CamWhiskersFromTarget();
        }

        //do not move camera if target is within desired distance and within screen deadzones

        /*
         * float camTargetDistance = Vector3.Distance(camPos, followTargetPos);
         * if (camTargetDistance > minDistanceFromTarget && camTargetDistance < desiredOffsetDistance
         *  && cam.IsWithinDeadzone(followTargetPos, followDeadzoneX, followDeadzoneX, followDeadzonePlusY, followDeadzoneNegativeY))
         * {
         *  Debug.Log("target within desired distance and screen deadzones!");
         *  desiredPos = camPos;
         * }
         */

        //Interpolate between current camera position and desired position to find new position; clamp if outside min/max distances
        if (camPos != desiredPos)
        {
            //newPos = lerpOffset ? Vector3.SmoothDamp(camPos, desiredPos, ref smoothdampVelocity, 1f / offsetLerpSpeed) : desiredPos;
            float smoothTime = 1 / offsetLerpSpeed;
            newPos = lerpOffset ? Lerps.SmoothDampSeparateAxisSeparateY(camPos, desiredPos, ref smoothdampVelocity, smoothTime, smoothTime * 5, smoothTime, smoothTime, Time.deltaTime) : desiredPos;

            //Clamp newPos to min and max distances.
            //This causes camera to orbit around target at min distance, which is cool
            float   newPosTargetSqrDist = (followTargetPos - newPos).sqrMagnitude;
            Vector3 targetToNewPosUnit  = (newPos - followTargetPos).normalized;
            if (newPosTargetSqrDist < sqrMinDistanceFromTarget)
            {
                newPos = followTargetPos + (targetToNewPosUnit * minDistanceFromTarget);
            }
            else if (newPosTargetSqrDist > sqrMaxDistanceFromTarget)
            {
                newPos = followTargetPos + (targetToNewPosUnit * maxDistanceFromTarget);
            }
        }
    }
示例#21
0
 protected override void UpdateValue()
 {
     (this as ITweenTarget <float>).SetTweenedValue((float)Lerps.Ease(_easeType, _fromValue, _toValue, _elapsedTime, _duration));
 }