Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        float xVelocity = input.GetXAxis();
        float yVelocity = input.GetYAxis();

        if (input.GetButton(1))
        {
            xVelocity *= 2;
            yVelocity *= 2;
        }

        physicsBody.velocity = new Vector3(xVelocity, yVelocity, 0);
    }
    void Update()
    {
        Controller = AttachedPlayer.InputDevice;
        if (Controller && GetComponent <SpriteRenderer>().sprite == null)
        {
            GetComponent <SpriteRenderer>().sprite = GetSpriteFromPrompt(Prompts[0]);
        }

        if (Controller && Prompts[0].MappedButton != MappedButton.None)
        {
            if (Controller.GetButton(Prompts[0].MappedButton))
            {
                OnPromtNext();
            }
        }

        if (Controller && Prompts[0].MappedAxis != MappedAxis.None)
        {
            if (Controller.GetIsAxisTapped(Prompts[0].MappedAxis))
            {
                OnPromtNext();
            }
        }
    }
    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);
    }
Beispiel #4
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        InputDevice device = (InputDevice)target;

        GUILayout.Label("Type: " + device.GetType().ToString());

        GUILayout.Label("Mapped Axes", EditorStyles.boldLabel);
        for (int i = 0; i < InputDevice.allMappedAxisTypes.Count; i++)
        {
            GUILayout.Label(string.Format("{0} ({1}): {2}", InputDevice.allMappedAxisTypes[i], device.GetAxisName(InputDevice.allMappedAxisTypes[i]), device.GetAxis(InputDevice.allMappedAxisTypes[i])));
        }

        GUILayout.Space(10);

        GUILayout.Label("Mapped Buttons", EditorStyles.boldLabel);

        for (int i = 0; i < InputDevice.allMappedButtonTypes.Count; i++)
        {
            GUILayout.Label(string.Format("{0} ({1}): {2}", InputDevice.allMappedButtonTypes[i], device.GetButtonName(InputDevice.allMappedButtonTypes[i]), device.GetButton(InputDevice.allMappedButtonTypes[i])));
        }
    }