Beispiel #1
0
    // Camera movement update coroutine
    IEnumerator MoveCamera()
    {
        for (float t = 0.0f; t < 1.0f; t += Time.deltaTime * cameraSpeed)
        {
            var easing = EasingFunction.EaseInOutCubic(0.0f, 1.0f, t);

            if (target == null)
            {
                Debug.LogError("No camera target found!");
            }
            transform.position = Vector3.Lerp(startPos, target.transform.position, easing);
            if (!toLevel)
            {
                transform.rotation          = Quaternion.Slerp(startQuat, target.transform.rotation, easing);
                cameraComponent.fieldOfView = Mathf.Lerp(startFov, target.fov, easing);
            }
            cameraComponent.backgroundColor = Color.Lerp(startColor, target.backgroundColor, easing);

            yield return(null);
        }

        if (callback != null)
        {
            callback();
            callback = null;
        }

        toLevel        = false;
        isInTransition = false;
    }
Beispiel #2
0
    // Fake movement animation coroutine
    IEnumerator FalseMoveOrPushCoroutine(Direction dir, bool isPushing)
    {
        if (isPushing)
        {
            playerAnimator.SetFloat("MovePush", 1.0f);
        }
        else
        {
            playerAnimator.SetFloat("MovePush", 0.0f);
        }

        var startPos = transform.position;
        var target   = GetFacing(dir) - startPos;

        target.Normalize();
        target *= 0.25f;

        var falseMoveSpeed = isPushing ? 4.0f : 5.0f;

        for (float t = 0.0f; t < 1.0f; t += Time.deltaTime * falseMoveSpeed)
        {
            var easing = EasingFunction.EaseInOutCubic(0.0f, 1.0f, Mathf.Clamp(t, 0.0f, 1.0f));
            transform.position = Vector3.Lerp(startPos, target + startPos, easing);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target), rotationSpeed * Time.deltaTime);
            if (idleMove < 1.0f)
            {
                idleMove += Time.deltaTime * idleMoveSpeed;
            }

            playerAnimator.SetFloat("IdleMove", idleMoveCurve.Evaluate(idleMove));

            yield return(null);
        }

        for (float t = 0.0f; t < 1.0f; t += Time.deltaTime * falseMoveSpeed)
        {
            var easing = EasingFunction.EaseInOutCubic(0.0f, 1.0f, Mathf.Clamp(t, 0.0f, 1.0f));
            transform.position = Vector3.Lerp(target + startPos, startPos, easing);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target), rotationSpeed * Time.deltaTime);
            if (idleMove > 0.0f)
            {
                idleMove -= Time.deltaTime * idleMoveSpeed;
            }

            playerAnimator.SetFloat("IdleMove", idleMoveCurve.Evaluate(idleMove));

            yield return(null);
        }

        isFalseMovingOrPushing = false;
    }
    private Vector3 SmoothMove()
    {
        if (t <= 1.0)
        {
            t += Time.deltaTime / seconds;
            float newTime = t;
            if (newTime > 1)
            {
                newTime = 1;
            }
            float   easeFactor  = EasingFunction.EaseInOutCubic(0.0F, 1.0F, newTime);
            Vector3 newPosition = Vector3.Lerp(currentStartPos, currentEndpos, easeFactor);

            return(newPosition - transform.position);
        }
        else
        {
            if (transform.position == positionUp)
            {
                animator.SetBool("UP", false);
                animator.SetBool("TURN", true);
                moveUp = false;
            }
            else
            {
                animator.SetBool("UP", true);
                animator.SetBool("TURN", false);
                moveUp            = true;
                reachedBottomTime = Time.timeSinceLevelLoad;
                triggerMoveUp     = false;
            }

            t = 0F;

            Vector3 dummy = currentStartPos;
            currentStartPos   = currentEndpos;
            currentEndpos     = dummy;
            waterEffectPlayed = false;
        }
        return(Vector3.zero);
    }
Beispiel #4
0
    private void Update()
    {
        // Exit game
        if (Input.GetKey("escape"))
        {
            Application.Quit();
        }

        // Increase or decrease the animationT depending on ViewMode
        bool animating = false;

        if (_currentViewMode == ViewMode.ScaleCompare)
        {
            if (animationT > 0)
            {
                animating   = true;
                animationT -= Time.deltaTime * 0.5f;
            }
        }
        else
        {
            if (animationT < 1)
            {
                animating   = true;
                animationT += Time.deltaTime * 0.5f;
            }
        }

        // Add an easing to the transition
        float t = EasingFunction.EaseInOutCubic(0, 1, animationT);

        // Only run if animating or if we are in editor so we can see changes live
        if (animating || Application.isEditor)
        {
            cameraController.LerpBetweenViewModes(t);
            solarSystem.LerpBetweenViewModes(t);
        }

        uiHandler.UpdateButtonPositions(t);
    }
    private Vector3 SmoothMove()
    {
        if (t <= 1.0)
        {
            t += Time.deltaTime / currentSeconds;
            float newTime = t;
            if (newTime > 1)
            {
                newTime = 1;
            }
            float easeFactor = newTime;



            if (easing == EASING_FUNCTION.INOUTCUBIC)
            {
                easeFactor = EasingFunction.EaseInOutCubic(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.BOUNCE)
            {
                easeFactor = EasingFunction.EaseOutBounce(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.ELASTIC)
            {
                easeFactor = EasingFunction.EaseOutElastic(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.EXPO)
            {
                easeFactor = EasingFunction.EaseInExpo(0.0F, 1.0F, newTime);
            }

            Vector3 newPosition            = Vector3.Lerp(currentStartPos, currentEndpos, easeFactor);
            Vector3 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);
            return(pixelPerfectMoveAmount - transform.position);
        }
        isMoving = false;
        return(Vector3.zero);
    }
Beispiel #6
0
    private void UpdateHandLighting()
    {
        var wasFullPowerLight = Math.Abs(currentLightFactor - 1) < 0.001f;

        isMakingLight = isClicking; // && !isDragging;

        // increase light level
        if (isMakingLight && currentLightFactor < 1)
        {
            currentLightFactor += Time.deltaTime * 0.5f;
            if (currentLightFactor > 1)
            {
                currentLightFactor = 1;
            }
        }

        // decrease light level
        if (!isMakingLight && currentLightFactor > 0)
        {
            currentLightFactor -= Time.deltaTime * 0.5f;
            if (currentLightFactor < 0)
            {
                currentLightFactor = 0;
            }
        }

        // update actual light
        handPointLight.range     = EasingFunction.EaseOutCubic(6, 15, currentLightFactor);
        handPointLight.intensity = EasingFunction.EaseOutCubic(1, 2, currentLightFactor);

        // update sphere height/size
        handSphere.localScale =
            Vector3.one * (sphereBaseScale * EasingFunction.EaseInOutCubic(1f, 1.5f, currentLightFactor));
        // bonusHeight = EasingFunction.EaseInOutCubic(0f, 1f, currentLightFactor);

        // update particle emission rate
        var emissionModule = handLightParticleSystem.emission;

        emissionModule.rateOverTime = EasingFunction.EaseInOutCubic(0f, 15, currentLightFactor);


        var fullPowerLight = Math.Abs(currentLightFactor - 1) < 0.001f;

        if (isMakingLight && fullPowerLight && !wasFullPowerLight && !IsOutOfInfluenceZone())
        {
            var size = Physics.OverlapSphereNonAlloc(hand.position, fieldReachRadius, fieldsInReachResult,
                                                     Masks.FIELDS, QueryTriggerInteraction.Collide);
            for (int i = 0; i < size; i++)
            {
                var field      = fieldsInReachResult[i];
                var wheatField = field.GetComponent <WheatField>();
                if (wheatField && wheatField.island.connected)
                {
                    growingFields.Add(wheatField);
                    wheatField.StartGrowing();
                }
            }
        }

        if (wasFullPowerLight && !fullPowerLight)
        {
            foreach (var field in growingFields)
            {
                field.StopGrowing();
            }

            growingFields.Clear();
        }
    }
Beispiel #7
0
    private void Move()
    {
        if (isDragging && Input.GetButtonUp("Fire1"))
        {
            isDragging   = false;
            handCoords.x = hand.position.x;
            handCoords.z = hand.position.z;
            return;
        }

        if (Input.GetButtonDown("Fire1"))
        {
            dragStartCoords = handCoords;
        }

        if (isClicking && !isDragging)
        {
            var dragVec = dragStartCoords - handCoords;
            if (dragVec.magnitude > 0.5f)
            {
                isDragging = true;
                if (island && !island.connected)
                {
                    currentDragSpeed = dragSpeedIsland;
                }
                else
                {
                    currentDragSpeed = dragSpeedBase;
                }
            }
        }

        if (isDragging && (!island || island.connected) && mouseMove.sqrMagnitude > 0)
        {
            // move player/camera
            var tr         = transform;
            var position   = tr.position;
            var dragDist   = (dragStartCoords - handCoords).magnitude;
            var distFactor = Mathf.Clamp(dragDist * 0.02f, 0, 1);
            var move       = -mouseMove *EasingFunction.EaseInOutCubic(currentDragSpeed, 0, distFactor);

            position   += move;
            tr.position = position;

            TutoManager.INSTANCE.dstMoved += move.magnitude;
        }

        if (isDragging && island && !island.connected && mouseMove.sqrMagnitude > 0)
        {
            var dragDist   = (dragStartCoords - handCoords).magnitude;
            var distFactor = Mathf.Clamp(dragDist * 0.025f, 0, 1);
            var move       = mouseMove * EasingFunction.EaseInOutCirc(currentDragSpeed, 0, distFactor);

            // move island
            var tr       = island.transform;
            var position = tr.position;
            position   += move;
            tr.position = position;

            // also move hand
            hand.position += move;

            TutoManager.INSTANCE.islandDstMoved += move.magnitude;
        }
    }
    private Vector3 SmoothMove()
    {
        if (t <= 1.0)
        {
            t += Time.deltaTime / GetCurrentSeconds();
            float newTime = t;
            if (newTime > 1)
            {
                newTime = 1;
            }
            float easeFactor = newTime;

            EASING_FUNCTION easing = GetCurrentEasing();

            if (easing == EASING_FUNCTION.INOUTCUBIC)
            {
                easeFactor = EasingFunction.EaseInOutCubic(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.BOUNCE)
            {
                easeFactor = EasingFunction.EaseOutBounce(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.ELASTIC)
            {
                easeFactor = EasingFunction.EaseOutElastic(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.INEXPO)
            {
                easeFactor = EasingFunction.EaseInExpo(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.OUTEXPO)
            {
                easeFactor = EasingFunction.EaseOutExpo(0.0F, 1.0F, newTime);
            }

            Vector3 newPosition            = Vector3.Lerp(currentStartPos, currentEndpos, easeFactor);
            Vector3 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);


            return(pixelPerfectMoveAmount - transform.position);
        }

        if (currentEndpos == endpos && myRenderer.isVisible)
        {
            ActionCompleteEffect();
        }

        isMoving        = false;
        isMovingAction  = false;
        isMovingPrewarm = false;

        if (currentEndpos == endpos)
        {
            waitUntil       = Time.timeSinceLevelLoad + waitTimeActionPosition;
            currentStartPos = endpos;
            currentEndpos   = startPos;
        }
        else
        {
            if (currentEndpos == prewarmPos)
            {
                PrewarmEffect();
                isMovingAction  = true;
                waitUntil       = Time.timeSinceLevelLoad + waitTimePrewarmPosition;
                currentStartPos = prewarmPos;
                currentEndpos   = endpos;
            }
            else
            {
                isMovingPrewarm = true;
                waitUntil       = Time.timeSinceLevelLoad + waitTimeBasePosition;
                currentStartPos = startPos;
                currentEndpos   = prewarmPos;
            }
        }

        return(Vector3.zero);
    }
Beispiel #9
0
    private Vector3 SmoothMove()
    {
        if (t <= 1.0)
        {
            t += Time.deltaTime / GetCurrentSeconds();
            float newTime = t;
            if (newTime > 1)
            {
                newTime = 1;
            }
            float easeFactor = newTime;

            EASING_FUNCTION easing = GetCurrentEasing();

            if (easing == EASING_FUNCTION.INOUTCUBIC)
            {
                easeFactor = EasingFunction.EaseInOutCubic(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.BOUNCE)
            {
                easeFactor = EasingFunction.EaseOutBounce(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.ELASTIC)
            {
                easeFactor = EasingFunction.EaseOutElastic(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.INEXPO)
            {
                easeFactor = EasingFunction.EaseInExpo(0.0F, 1.0F, newTime);
            }
            if (easing == EASING_FUNCTION.OUTEXPO)
            {
                easeFactor = EasingFunction.EaseOutExpo(0.0F, 1.0F, newTime);
            }

            if (isMovingAction && Time.frameCount % 2 == 0)
            {
                InstantiateEffect(fallingEffect, transform.position);
            }

            Vector3 newPosition            = Vector3.Lerp(currentStartPos, currentEndpos, easeFactor);
            Vector3 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);

            if (!actionCompleteEffectPlayed &&
                ((easing != EASING_FUNCTION.BOUNCE && newPosition == endpos) || (easing == EASING_FUNCTION.BOUNCE && (newPosition.y > transform.position.y))))
            {
                ActionCompleteEffect();
            }

            return(pixelPerfectMoveAmount - transform.position);
        }



        isMoving        = false;
        isMovingAction  = false;
        isMovingPrewarm = false;

        if (currentEndpos == endpos)
        {
            waitUntil                  = waitUntil + secondsAction + waitTimeActionPosition;
            currentStartPos            = endpos;
            currentEndpos              = startPos;
            actionCompleteEffectPlayed = false;
        }
        else
        {
            isMovingPrewarm = true;
            waitUntil       = waitUntil + secondsBase + waitTimeBasePosition;
            currentStartPos = startPos;
            currentEndpos   = endpos;
        }

        return(Vector3.zero);
    }