Ejemplo n.º 1
0
    void Update()
    {
        //userMain.ToggleReticles(true)

        if (!userMain.CursorOverUI())
        {
            if (inputControl.GetZoom() != 0 &&
                cameraView == CameraView.Isometric)
            {
                float updatedZoom = cameraViewController.GetZoom() - inputControl.GetZoom();
                cameraViewController.SetZoom(Mathf.Max(0, updatedZoom));
            }

            //if(userMain.KeyLock)
            if (inputControl.GetButtonDown("MoveCamera") && editMain.GetCameraFollowingActor())
            {
                editMain.SetCameraFollowingActor(false);
            }

            if (inputControl.GetButton("RotateCamera") && cameraView == CameraView.Isometric)
            {
                isometricCameraViewController.RotateView(inputControl.GetMouseAxes().x *ISO_ROTATE_MOD);
            }
        }

        cameraViewController.ControllerUpdate(fixedUpdatesSinceLastUpdate);
        fixedUpdatesSinceLastUpdate = 0;

        // Temporary band-aid guard, since this userBody assumption is pretty wide-spread.
        if (userBody != null)
        {
            if (MoveActive())
            {
                userBody?.SetSprint(IsSprinting());
                // userBody?.SetCrouch(inputControl.GetButton("Crouch"));
            }
            else
            {
                userBody?.SetSprint(false);
                userBody?.SetCrouch(false);
            }
        }
    }
Ejemplo n.º 2
0
    void PrepareInputForScript(ControllerInput input)
    {
        if (input == null)
        {
            return;
        }

        if (userMain == null)
        {
            // Not ready yet.
            return;
        }

        inputStateForScript = new InputStateForScript();

        if (input.GetKeyDown(PlayerBody.VKEY_JUMP))
        {
            // V1 name:
            voosActor.EnqueueMessage("JumpTriggered");
            // V2 name:
            voosActor.EnqueueMessage("Jump");
        }

        if (input.GetKeyDown(PlayerBody.VKEY_PRIMARY_ACTION))
        {
            // V1 name:
            voosActor.EnqueueMessage("Action1Triggered");
            // V2 name:
            voosActor.EnqueueMessage("PrimaryAction");
        }

        if (input.GetKeyDown(PlayerBody.VKEY_SECONDARY_ACTION))
        {
            // V1 name:
            voosActor.EnqueueMessage("Action2Triggered");
            // V2 name:
            voosActor.EnqueueMessage("SecondaryAction");
        }

        List <string> keysHeld         = new List <string>();
        List <string> keysJustPressed  = new List <string>();
        List <string> keysJustReleased = new List <string>();

        foreach (string key in ScriptableKeyNames)
        {
            bool isDown = input.GetKeyDown(key) && !keysHeldAsReportedToScript.Contains(key);
            bool isUp   = !input.GetKeyHeld(key) && keysHeldAsReportedToScript.Contains(key);
            bool isHeld = input.GetKeyHeld(key);

            if (isHeld)
            {
                keysHeldAsReportedToScript.Add(key);
            }
            else
            {
                keysHeldAsReportedToScript.Remove(key);
            }

            if (isDown)
            {
                voosActor.EnqueueMessage("KeyDown", $"{{\"keyName\": \"{key}\"}}");
                keysJustPressed.Add(key);
            }
            if (isHeld)
            {
                voosActor.EnqueueMessage("KeyHeld", $"{{\"keyName\": \"{key}\"}}");
                keysHeld.Add(key);
            }
            if (isUp)
            {
                voosActor.EnqueueMessage("KeyUp", $"{{\"keyName\": \"{key}\"}}");
                keysJustReleased.Add(key);
            }
        }

        bool mouseIsDown = Input.GetMouseButton(0) && !userMain.CursorOverUI() && !userMain.InEditMode();

        if (mouseIsDown && !reportedMouseDown)
        {
            voosActor.EnqueueMessage("MouseDown");
            reportedMouseDown = true;
            inputStateForScript.mouseButtonJustPressed = true;
        }
        if (reportedMouseDown)
        {
            voosActor.EnqueueMessage("MouseHeld");
            inputStateForScript.mouseButtonIsPressed = true;
        }
        if (!mouseIsDown && reportedMouseDown)
        {
            voosActor.EnqueueMessage("MouseUp");
            reportedMouseDown = false;
            inputStateForScript.mouseButtonJustReleased = true;
        }

        Vector2 mousePosUiCoords;
        Vector3 mousePosRaw = Input.mousePosition;

        mousePosUiCoords = gameUiMain.UnityScreenPointToGameUiPoint(mousePosRaw);

        inputStateForScript.mouseX           = mousePosUiCoords.x;
        inputStateForScript.mouseY           = mousePosUiCoords.y;
        inputStateForScript.keysHeld         = keysHeld.ToArray();
        inputStateForScript.keysJustPressed  = keysJustPressed.ToArray();
        inputStateForScript.keysJustReleased = keysJustReleased.ToArray();

        Ray mouseRay = userMain.GetCamera().ScreenPointToRay(mousePosRaw);

        inputStateForScript.mouseRayOrigin    = mouseRay.origin;
        inputStateForScript.mouseRayDirection = mouseRay.direction;

        if (inputStateForScript.mouseButtonJustPressed)
        {
            RaycastHit hit;
            if (Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit, 1000, VoosActor.LayerMaskValue, QueryTriggerInteraction.Collide))
            {
                VoosActor clickedActor = hit.collider.GetComponentInParent <VoosActor>();
                if (clickedActor != null)
                {
                    clickedActor.GetEngine().EnqueueMessage(new VoosEngine.ActorMessage
                    {
                        name        = "ActorClicked",
                        targetActor = clickedActor.GetName(),
                        argsJson    = "{}"
                    });
                }
            }
        }

        inputStateForScript.mouseWheelRaw = Input.GetAxis("Mouse ScrollWheel");
        inputStateForScript.mouseWheel    = inputStateForScript.mouseWheelRaw * MOUSEWHEEL_FACTOR;
    }
Ejemplo n.º 3
0
 public bool CursorOverUI()
 {
     return(userMain.CursorOverUI());
 }