Example #1
0
    void Update()
    {
        // Get the input vector from kayboard or analog stick
        Vector3 directionVector = new Vector3(InputProxy.GetAxis("Horizontal"), 0, InputProxy.GetAxis("Vertical"));

        if (directionVector != Vector3.zero)
        {
            // Get the length of the directon vector and then normalize it
            // Dividing by the length is cheaper than normalizing when we already have the length anyway
            float directionLength = directionVector.magnitude;
            directionVector = directionVector / directionLength;

            // Make sure the length is no bigger than 1
            directionLength = Mathf.Min(1, directionLength);

            // Make the input vector more sensitive towards the extremes and less sensitive in the middle
            // This makes it easier to control slow speeds when using analog sticks
            directionLength = directionLength * directionLength;

            // Multiply the normalized direction vector by the modified length
            directionVector = directionVector * directionLength;
        }

        // Apply the direction to the CharacterMotor
        motor.inputMoveDirection = transform.rotation * directionVector;
        motor.inputJump          = InputProxy.GetButton("Jump");
    }
Example #2
0
 public CurrentPageContainer(IInput input, IRenderer renderer, IUrhoScheduler scheduler)
 {
     _input      = new InputDispatcher();
     _inputProxy = new InputProxy(input, _input);
     _renderer   = renderer;
     _scheduler  = scheduler;
 }
 private void ProcessHotkeys(string _)
 {
     if (InputProxy.GetKeyDown(KeyCode.Return) || InputProxy.GetKeyDown(KeyCode.KeypadEnter))
     {
         RequestSearch();
     }
     else if (InputProxy.GetKeyDown(KeyCode.Escape))
     {
         ClearSearch();
     }
 }
Example #4
0
    public void Start()
    {
        input = GetComponent <InputProxy>();


        if (NetworkHelper.IsServerSide())
        {
            // Link proximity field
            ProximityHandler proximityField = GetComponentInChildren <ProximityHandler>();
            proximityField.EventOnProximityEnter += proximityField_EventOnProximityEnter;
        }
    }
        IEnumerator SomeHotkeyCoroutine()
        {
            while (true)
            {
                yield return(new WaitForSeconds(_timeout));

                yield return(new WaitUntil(() => InputProxy.GetKeyDown(_keyCode)));

                if (!m_isLocked)
                {
                    KeyPressedEvent?.Invoke();
                }
            }
        }
Example #6
0
    void Update()
    {
        if (axes == RotationAxes.MouseXAndY)
        {
            float rotationX = transform.localEulerAngles.y + InputProxy.GetAxis("Mouse X") * sensitivityX;

            rotationY += InputProxy.GetAxis("Mouse Y") * sensitivityY;
            rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

            transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
        }
        else if (axes == RotationAxes.MouseX)
        {
            transform.Rotate(0, InputProxy.GetAxis("Mouse X") * sensitivityX, 0);
        }
        else
        {
            rotationY += InputProxy.GetAxis("Mouse Y") * sensitivityY;
            rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

            transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
        }
    }
Example #7
0
        private void Update()
        {
            if (InputProxy.GetKeyUp(KeyCode.Escape))
            {
                EscapePressed?.Invoke();
            }

            foreach (var pair in ModificationKeys)
            {
                if (InputProxy.GetKeyDown(pair.Key))
                {
                    keyboardInput.KeyDown(pair.Value);
                }

                if (InputProxy.GetKeyUp(pair.Key))
                {
                    keyboardInput.KeyUp(pair.Value);
                }
            }

            foreach (var pair in NumpadKeys)
            {
                if (InputProxy.GetKeyDown(pair.Key))
                {
                    keyboardInput.PressKey(pair.Value);
                }
            }

            AllKeyCodes.ForEach(code =>
            {
                if (InputProxy.GetKeyDown(code))
                {
                    var key = KeysConverter.Convert(code);
                    keyboardInput.PressKey(key);
                }
            });
        }
Example #8
0
 void OnDestroy()
 {
     Instance = null;
 }
Example #9
0
 void Start()
 {
     Instance = this;
 }
Example #10
0
 void Awake()
 {
     instance = this;
 }
Example #11
0
 // Use this for initialization
 void Start()
 {
     FloatingBody = this.GetComponent <FloatingObject>();
     inputProxy   = this.GetComponent <InputProxy>();
 }
Example #12
0
    void Update()
    {
        // capture cursor
        if (Screen.lockCursor != lockCursor)
        {
            if (lockCursor && Input.GetMouseButton(0))
            {
                Screen.lockCursor = true;
            }
            else if (!lockCursor)
            {
                Screen.lockCursor = false;
            }
        }

        // interact with the world
        Ray        ray = new Ray(cameraObject.transform.position, cameraObject.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, reach))
        {
            // did hit
            targetCube.transform.position = WorldInterface.GetHitPositionIn(hit);
            targetCube.SetActive(true);

            ushort block = WorldInterface.GetBlock(world, hit);
            blockIndicator.text = Block.GetInstance(block).name;

            if (InputProxy.GetButtonDown("Dig"))
            {
                if (!Block.GetInstance(block).indestructable)
                {
                    WorldInterface.ReplaceBlock(world, hit, Block.AIR);
                    GetComponent <CollideWithTerrain>().collisionMaker.UpdateColliders();
                }
            }

            if (InputProxy.GetButtonDown("Use"))
            {
                WorldInterface.AddBlock(world, hit, held);
                GetComponent <CollideWithTerrain>().collisionMaker.UpdateColliders();
            }

            if (InputProxy.GetButtonDown("Equip"))
            {
                held = WorldInterface.GetBlock(world, hit);
            }
        }
        else
        {
            // did not hit
            blockIndicator.text = "";
            targetCube.SetActive(false);
        }

        // set fog based on camera position
        ushort headBlock = WorldInterface.GetBlock(world, Camera.main.transform.position);

        fog.water = false;
        foreach (ushort water in Block.WATER)
        {
            if (headBlock == water)
            {
                fog.water = true;
                break;
            }
        }
    }