Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //Do the Pause
        if (InputManager.controllers.Count > 0 && !lockPause)
        {
            InputDevice controller = InputManager.controllers[0];

            if (!isAnimating && !isSaving)
            {
                if (controller.GetButtonWithLock("Pause"))
                {
                    isAnimating = true;
                    isPaused    = !isPaused;

                    //Freeze Time
                    if (isPaused)
                    {
                        StartCoroutine(ShowPauseMenu());
                        pastPlayerMovements  = FindObjectOfType <PlayerMovement>().lockMovements;
                        pastPlayerIsThinking = FindObjectOfType <PlayerMovement>().isThinking;

                        if (!pastPlayerMovements)
                        {
                            FindObjectOfType <PlayerMovement>().lockMovements = true;
                        }
                        if (pastPlayerIsThinking)
                        {
                            FindObjectOfType <BuildingModeManager>().isLocked = true;
                        }

                        FindObjectOfType <IsoCam>().lockCamera = true;
                    }
                    else
                    {
                        StartCoroutine(HidePauseMenu());

                        FindObjectOfType <PlayerMovement>().lockMovements = pastPlayerMovements;
                        FindObjectOfType <PlayerMovement>().isThinking    = pastPlayerIsThinking;

                        if (pastPlayerIsThinking)
                        {
                            FindObjectOfType <BuildingModeManager>().isLocked = false;
                        }

                        FindObjectOfType <IsoCam>().lockCamera = false;
                    }
                }
            }
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (inputField.isActiveAndEnabled && inputField.isFocused)
        {
            LockKeyboard(0);
        }

        //Do the Pause
        if (InputManager.controllers.Count > 0)
        {
            InputDevice controller = InputManager.controllers[0];

            if (controller.GetButtonWithLock("Pause"))
            {
                ReturnToPause();
            }
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (target)
        {
            if (InputManager.controllers.Count > 0)
            {
                InputDevice inputDevice = InputManager.controllers[0];

                if (inputDevice.inputType == InputType.Keyboard)
                {
                    float xInput = Input.GetAxis("Mouse X") * mouseScale;
                    float yInput = Input.GetAxis("Mouse Y") * mouseScale;

                    xyValues.x += xInput * xSpeed * Time.deltaTime * (invertHorizontal ? -1f : 1f);
                    xyValues.y += yInput * ySpeed * Time.deltaTime * (invertVertical ? -1f : 1f);
                }
                else if (InputManager.controllers[0].inputType == InputType.Xbox360)
                {
                    xyValues.x -= InputManager.controllers[0].GetInput("CameraHorizontal") * ySpeed * controllerScale * Time.deltaTime * (invertHorizontal ? -1f : 1f);
                    xyValues.y += InputManager.controllers[0].GetInput("CameraVertical") * xSpeed * controllerScale * Time.deltaTime * (invertVertical ? -1f : 1f);
                }

                if (inputDevice.GetButtonWithLock("Focus"))
                {
                    focused = !focused;
                }
            }

            xyValues.y = Mathf.Clamp(xyValues.y, 0f, 90f);

            radius = focused ? focusedRadius : unfocusedRadius;

            actualXYValues = Vector2.Lerp(actualXYValues, xyValues, Time.deltaTime * lerpSpeed);
            actualRadius   = Mathf.Lerp(actualRadius, radius, Time.deltaTime * lerpSpeed);

            Quaternion rotation = Quaternion.Euler(actualXYValues.y, actualXYValues.x, 0f);

            Vector3 negDistance = new Vector3(0.0f, 0.0f, -actualRadius);
            Vector3 position    = rotation * negDistance + target.position;

            transform.rotation = rotation;
            transform.position = position + Vector3.up;
        }
    }
Ejemplo n.º 4
0
    private void Update()
    {
        cameraTarget.GetComponent <FluidCursor>().isLocked = isLocked;

        //User Inputs
        if (!isLocked && InputManager.controllers.Count > 0 && !PauseMenu.isPaused)
        {
            InputDevice inputDevice = InputManager.controllers[0];

            if (!isAnimating && inputDevice.GetButtonWithLock("BuildMode"))
            {
                //Stop Any Hiding
                if (buildHideCoroutine != null)
                {
                    StopCoroutine(buildHideCoroutine);
                    StopCoroutine(playHideCoroutine);
                }

                if (isActivated)
                {
                    EndBuildMode();
                }
                else
                {
                    StartBuildMode();
                }

                hideTimer = 5f;
                isHiding  = false;
            }

            if (isActivated)
            {
                //Map Cursor to Grid
                Vector3 mousePos;

                if (inputDevice.inputType == InputType.Keyboard)
                {
                    mousePos = fluidCursor.transform.position;
                }
                else
                {
                    mousePos = cameraTarget.transform.position;
                }

                mousePos.y = cameraTarget.GetComponent <FluidCursor>().GetActualPos().y;

                WorldChunk insideChunk = worldStateManager.IsInsideWorldChunk(mousePos);
                bool       validCursor = insideChunk != null;
                if (validCursor)
                {
                    actualCursorPos           = worldStateManager.ChunkToWorld(insideChunk, worldStateManager.WorldToChunk(insideChunk, mousePos));
                    cursor.transform.position = actualCursorPos;
                }

                //Move the Cursor
                mousePos.y = cameraTarget.transform.position.y;
                fluidCursor.transform.position = mousePos;

                bool build = false, delete = false;
                int  rotate = 0;

                //Build Controls
                build  = inputDevice.GetButton("Create");
                delete = inputDevice.GetButton("Delete");

                //Rotation
                rotate = inputDevice.GetIntInputWithDelay("Rotate", 0.3f, Time.deltaTime);

                //Item Swapping
                int maxKeys = 10;
                if (inputDevice.inputType == InputType.Keyboard)
                {
                    for (int i = 1; i < maxKeys; i++)
                    {
                        if (inputDevice.GetButtonWithLock("Item" + i))
                        {
                            ChangeSelection(i);
                        }
                    }
                }
                else
                {
                    int itemSwitch = inputDevice.GetIntInputWithDelay("ItemSwitch", 0.25f, Time.deltaTime);

                    if (itemSwitch != 0)
                    {
                        int max = FindObjectOfType <BuildingPartDatabaseManager>().GetBuildingPartCount() + 1;
                        ChangeSelection(MathHelper.NumClamp(currentSelection + itemSwitch, 1, Mathf.Min(max, maxKeys)));
                    }
                }

                IsoCam isoCam = playerMovement.playerCamera.GetComponent <IsoCam>();

                //Mouse Controls
                if (inputDevice.inputType == InputType.Keyboard)
                {
                    Ray   ray = playerMovement.playerCamera.ScreenPointToRay(Input.mousePosition);
                    float hit;

                    Plane plane = new Plane(Vector3.up, -fluidCursor.transform.position.y);

                    if (plane.Raycast(ray, out hit))
                    {
                        Vector3 hitPoint = ray.GetPoint(hit);
                        hitPoint.y = fluidCursor.transform.position.y;
                        fluidCursor.transform.position = hitPoint;
                    }

                    Debug.DrawRay(ray.origin, ray.direction, Color.red);
                }

                if (validCursor && inputDevice.inputType == InputType.Keyboard)
                {
                    if (!RectTransformUtility.RectangleContainsScreenPoint(itemsPanel.GetComponent <RectTransform>(), Input.mousePosition, Camera.main))
                    {
                        build  = InputManager.GetClickHold(0);
                        delete = InputManager.GetClickHold(1);
                    }
                }

                grid.transform.position = Vector3.Scale(grid.transform.position, new Vector3(1f, 0f, 1f)) + Vector3.Scale(actualCursorPos, new Vector3(0f, 1f, 0f)) + new Vector3(0f, 0.06f, 0f);

                //Do Build Inputs
                if (build)
                {
                    worldStateManager.CreateItem(currentSelection, actualCursorPos, rotationAmount);
                }
                else
                {
                    worldStateManager.buildLock = false;
                }

                if (delete)
                {
                    worldStateManager.DeleteItem(actualCursorPos);
                }

                //Do Rotating
                if (rotate != 0)
                {
                    rotationAmount -= rotate * 90f;
                }

                lerpingRotationAmount     = Mathf.Lerp(lerpingRotationAmount, rotationAmount, Time.deltaTime * lerpAmount);
                cursor.transform.rotation = Quaternion.identity * Quaternion.AngleAxis(lerpingRotationAmount, Vector3.up);
            }
        }

        if (cursorObject != null)
        {
            if (worldStateManager.CanPlace(currentSelection, actualCursorPos))
            {
                currentCursorMaterial.color = validCursor;
            }
            else
            {
                currentCursorMaterial.color = invalidCursor;
            }
        }

        if (hideTimer > 0f)
        {
            hideTimer -= Time.deltaTime;
        }
        else if (!isHiding)
        {
            isHiding           = true;
            buildHideCoroutine = StartCoroutine(FlipFade(buildModeImage, 0f));
            playHideCoroutine  = StartCoroutine(FlipFade(playModeImage, 0f));
        }

        cursor.SetActive(isActivated);
        fluidCursor.SetActive(isActivated);
        grid.SetActive(isActivated);
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Rigidbody rigidbody = GetComponent <Rigidbody>();

        //Get Correct Camera Transform
        Vector3    cameraFoward = Vector3.Scale(playerCamera.transform.forward, new Vector3(1.0f, 0.0f, 1.0f)).normalized;
        Quaternion cameraQuat   = Quaternion.LookRotation(cameraFoward, Vector3.up);

        if (InputManager.controllers.Count > 0)
        {
            InputDevice inputDevice = InputManager.controllers[0];

            //Get Inputs
            float hori = inputDevice.GetInput("MovementHorizontal");
            float verti = inputDevice.GetInput("MovementVertical");
            bool  jump = false;
            bool  sneakInput = false, walkInput = false;

            if (!lockMovements)
            {
                jump       = inputDevice.GetButtonWithLock("Jump");
                sneakInput = inputDevice.GetButtonWithLock("Sneak");
                walkInput  = inputDevice.GetButtonWithLock("Walk");

                if (sneakInput)
                {
                    sneakMode = !sneakMode;
                    walkMode  = false;
                }

                if (walkInput)
                {
                    walkMode  = !walkMode;
                    sneakMode = false;
                }
            }

            //Move the character in the direction of the camera
            float maxInput = Mathf.Max(Mathf.Abs(hori), Mathf.Abs(verti));

            Vector3 input = new Vector3(hori, 0f, -verti).normalized;

            Vector2 inputAmount = new Vector2(hori, verti);
            float   moveAmount  = Mathf.Clamp(inputAmount.magnitude, 0f, 1f);

            if (moveAmount == 0 || lockMovements)
            {
                float cacceleration = -expectedSpeed / brakeTime;
                expectedSpeed += (cacceleration * Time.fixedDeltaTime);

                if (Mathf.Abs(expectedSpeed) <= 0.1f)
                {
                    expectedSpeed = 0;
                }

                input          = lastDirection;
                animationSpeed = 0;
            }
            else
            {
                //Get Max Movement Speed
                float maxSpeed = moveSpeed;
                animationSpeed = 3;

                if (inWater)
                {
                    maxSpeed       = swimSpeed;
                    animationSpeed = 1;
                }
                else if (walkMode || maxInput < walkPercent)
                {
                    maxSpeed      *= walkSpeedPercent;
                    animationSpeed = 2;
                }
                else if (sneakMode)
                {
                    maxSpeed      *= tiptoeSpeedPercent;
                    animationSpeed = 1;
                }

                expectedSpeed += (moveAmount * acceleration) * Time.fixedDeltaTime;
                expectedSpeed  = Mathf.Clamp(expectedSpeed, 0f, maxSpeed);

                if (maxInput > 0.01f)
                {
                    lastDirection  = input;
                    lastCameraQuat = cameraQuat;
                }
            }

            Vector3 finalInput = cameraQuat * input * expectedSpeed;

            pointDirection = (cameraQuat * input).normalized;

            Vector3 accelerationVec = (Vector3.Scale(finalInput, new Vector3(1f, 0f, 1f)) - Vector3.Scale(rigidbody.velocity, new Vector3(1f, 0f, 1f))) / Time.fixedDeltaTime;
            rigidbody.AddForce(accelerationVec, ForceMode.Acceleration);

            //Do Jump
            if (jump && (!isFalling || inWater) && !jumpLock)
            {
                if (inWater)
                {
                    animator.SetTrigger("DoDolphinDive");
                    doneSplash = false;
                    DoSplash();
                }

                StartCoroutine(JumpOffset());
            }
        }

        RaycastHit hit;

        isFalling = !Physics.Raycast(transform.position, Vector3.down, out hit, isFallCheck, ~(LayerMask.GetMask("Water") | LayerMask.GetMask("Ignore Raycast")), QueryTriggerInteraction.UseGlobal);
        bool canLand = !Physics.Raycast(transform.position, Vector3.down, out hit, isLandedCheck, ~(LayerMask.GetMask("Water") | LayerMask.GetMask("Ignore Raycast")), QueryTriggerInteraction.UseGlobal);

        if (rigidbody.velocity.y <= 0f && jumpLock)
        {
            jumpLock  = false;
            isJumping = false;
            GetComponent <FootSteps>().DoJump();
        }

        RaycastHit waterHit;

        Physics.Raycast(transform.position + (Vector3.up * 5f), Vector3.down, out waterHit, Mathf.Infinity, LayerMask.GetMask("Water"), QueryTriggerInteraction.Collide);
        RaycastHit groundHit = new RaycastHit();

        Physics.Raycast(transform.position + (Vector3.up * 5f), Vector3.down, out groundHit, Mathf.Infinity, ~(LayerMask.GetMask("Water") | LayerMask.GetMask("Ignore Raycast")), QueryTriggerInteraction.Collide);

        overWater = (waterHit.point.y - groundHit.point.y > 0.6f);

        //Turn to Face Look Direction
        if (lastDirection != Vector3.zero)
        {
            //Do a bunch of angle checks, if we're moving alot presume we're spinning
            Quaternion finalRot = Quaternion.LookRotation(lastCameraQuat * lastDirection, Vector3.up);
            float      angle = Quaternion.Angle(transform.rotation, finalRot), averageAngle = 0f;
            float      currentTurnSpeed = turnSpeed;

            if (lastRotAngles.Count >= 40f)
            {
                lastRotAngles.Dequeue();
            }
            lastRotAngles.Enqueue(angle);

            foreach (float value in lastRotAngles)
            {
                averageAngle += value;
            }
            averageAngle /= lastRotAngles.Count;

            if (averageAngle > 50f)
            {
                currentTurnSpeed *= 3f;
            }

            transform.rotation = Quaternion.Lerp(transform.rotation, finalRot, Time.fixedDeltaTime * currentTurnSpeed);
        }

        // -- Do Animation --
        animator.SetInteger("Speed", animationSpeed);
        animator.SetBool("IsJumping", isJumping);
        animator.SetBool("HasJumped", jumpLock);
        animator.SetBool("IsRising", rigidbody.velocity.y > 0.5f);
        animator.SetBool("IsFalling", rigidbody.velocity.y < -0.1f && canLand);
        animator.SetBool("IsSwimming", inWater);
        animator.SetBool("IsThinking", isThinking);
        animator.SetBool("IsOverWater", overWater);

        //Do Particles
        if (!inWater && inWater != waterCheck)
        {
            waterTime = 5f;
            waterMaker.Stop();
            GetComponent <AudioSource>().PlayOneShot(splashExit);
        }

        if (inWater)
        {
            if (!movingWave.isPlaying)
            {
                movingWave.Play();
            }

            if (animationSpeed == 0)
            {
                if (waterMaker.clip != treadingSoundEffect)
                {
                    waterMaker.clip = treadingSoundEffect;
                    waterMaker.Play();
                }

                var emission = movingWave.emission;
                emission.rateOverTime = 1f;
            }
            else
            {
                if (waterMaker.clip != swimmingSoundEffect)
                {
                    waterMaker.clip = swimmingSoundEffect;
                    waterMaker.Play();
                }

                var emission = movingWave.emission;
                emission.rateOverTime = 4f;
            }
        }
        else
        {
            movingWave.Stop(true, ParticleSystemStopBehavior.StopEmitting);
        }

        waterCheck = inWater;

        if (!inWater && doneSplash)
        {
            doneSplash = false;
        }

        if (inWater && waterTime > 0f)
        {
            waterTime = 0f;
        }

        if (waterTime > 0f)
        {
            if (!waterDrops.isPlaying)
            {
                waterDrops.Play();
            }

            waterTime -= Time.fixedDeltaTime;
        }
        else
        {
            waterDrops.Stop(true, ParticleSystemStopBehavior.StopEmittingAndClear);
        }
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (target)
        {
            //Snap Round
            if (xyValues.y > 360f && actualXYValues.y > 180f)
            {
                actualXYValues.y -= 360f;
            }
            else if (xyValues.y < 0f && actualXYValues.y < 180f)
            {
                actualXYValues.y += 360f;
            }

            xyValues.y     = MathHelper.NumClamp(xyValues.y, 0f, 360f);
            actualXYValues = Vector2.Lerp(actualXYValues, xyValues, Time.deltaTime * lerpSpeed);

            Quaternion rotation = Quaternion.Euler(actualXYValues.x, actualXYValues.y, 0f);
            transform.rotation = rotation;

            //Set Forward
            Vector3 localForward = rotation * Vector3.forward;

            //Do Sizing
            size       = focusToggleDepths[currentDepth];
            actualSize = Mathf.Lerp(actualSize, size, Time.deltaTime * lerpSpeed);

            transform.position = target.position - (localForward * actualSize);

            //myCamera.orthographicSize = actualSize;

            //User Inputs
            if (!lockCamera && InputManager.controllers.Count > 0)
            {
                InputDevice inputDevice = InputManager.controllers[0];

                if (inputDevice.GetButtonWithDelay("RotateLeft", 0.5f, Time.deltaTime))
                {
                    xyValues.y += 90f;
                }

                if (inputDevice.GetButtonWithDelay("RotateRight", 0.5f, Time.deltaTime))
                {
                    xyValues.y -= 90f;
                }

                float focus = inputDevice.GetInputWithDelay("FocusDir", 0.5f, Time.deltaTime, 0.25f);

                if (focus == 0)
                {
                    focus = Input.GetAxis("Mouse Scrollwheel");
                }

                if (Mathf.Abs(focus) >= 0.25f)
                {
                    currentDepth = Mathf.Clamp(currentDepth + MathHelper.Sign(focus), 0, focusToggleDepths.Length - 1);
                }

                if (inputDevice.GetButtonWithLock("Focus"))
                {
                    currentDepth = MathHelper.NumClamp(currentDepth + 1, 0, focusToggleDepths.Length);
                }
            }
        }
    }