static public int constructor(IntPtr l) {
		try {
			UnityEngine.Input o;
			o=new UnityEngine.Input();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Example #2
0
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.Input o;
         o=new UnityEngine.Input();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
    static int _CreateUnityEngine_Input(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 0)
            {
                UnityEngine.Input obj = new UnityEngine.Input();
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: UnityEngine.Input.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Example #4
0
        /// <summary>
        /// Update controller.
        /// </summary>
        public void Update()
        {
            if (!UInput.mousePresent)
            {
                return;
            }

            // Bail early if our mouse isn't in our game window.
            if (UInput.mousePosition.x < 0 ||
                UInput.mousePosition.y < 0 ||
                UInput.mousePosition.x > Screen.width ||
                UInput.mousePosition.y > Screen.height)
            {
                return;
            }

            for (int i = 0; i < Interactions.Length; i++)
            {
                if (Interactions[i].InputType == DeviceInputType.SpatialPointer)
                {
                    // add mouse delta as rotation
                    var mouseDeltaRotation = Vector3.zero;
                    mouseDeltaRotation.x += -UInput.GetAxis("Mouse Y");
                    mouseDeltaRotation.y += UInput.GetAxis("Mouse X");

                    if (MouseInputProfile != null)
                    {
                        mouseDeltaRotation *= MouseInputProfile.MouseSpeed;
                    }

                    MixedRealityPose controllerPose = MixedRealityPose.ZeroIdentity;
                    controllerPose.Rotation  = Quaternion.Euler(mouseDeltaRotation);
                    Interactions[i].PoseData = controllerPose;

                    if (Interactions[i].Changed)
                    {
                        InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData);
                    }
                }


                if (Interactions[i].InputType == DeviceInputType.PointerPosition)
                {
                    Vector2 mouseDelta;
                    mouseDelta.x = -UInput.GetAxis("Mouse Y");
                    mouseDelta.y = UInput.GetAxis("Mouse X");
                    Interactions[i].Vector2Data = mouseDelta;

                    if (Interactions[i].Changed)
                    {
                        InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                    }
                }

                if (Interactions[i].AxisType == AxisType.Digital)
                {
                    var keyButton = UInput.GetKey(Interactions[i].KeyCode);

                    // Update the interaction data source
                    Interactions[i].BoolData = keyButton;

                    // If our value changed raise it.
                    if (Interactions[i].Changed)
                    {
                        // Raise input system Event if it enabled
                        if (Interactions[i].BoolData)
                        {
                            InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                }

                if (Interactions[i].InputType == DeviceInputType.Scroll)
                {
                    Interactions[i].Vector2Data = UInput.mouseScrollDelta;

                    if (Interactions[i].Changed)
                    {
                        InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                    }
                }
            }
        }
Example #5
0
 public override bool IsButtonPressed(MouseButton button)
 {
     return(UnityInput.GetKey((KeyCode)button));
 }
Example #6
0
    void Update()
    {
        if (testByKeyBoard)
        {
            if (Input.GetKey(KeyCode.A))
            {
                if (!disableMove)
                {
                    player.moveLeft();
                }
            }
            if (Input.GetKey(KeyCode.D))
            {
                if (!disableMove)
                {
                    player.moveRight();
                }
            }

            if (!Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.A))
            {
                player.idle();
            }

            if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.A))
            {
                player.idle();
            }

            // Space
            if (Input.GetKey(KeyCode.Space))
            {
                if (releaseSpace && !disableMove)
                {
                    player.jump();
                    releaseSpace = false;
                }
            }
            if (Input.GetKeyUp(KeyCode.Space))
            {
                releaseSpace = true;
            }

            // Shoot F
            if (Input.GetKeyDown(KeyCode.F))
            {
                player.shoot();
            }

            // Dash Control
            if (Input.GetKeyDown(KeyCode.LeftControl))
            {
                if (!disableMove)
                {
                    player.dash();
                }
            }

            // Charge Flame
            if (Input.GetKeyDown(KeyCode.F))
            {
                holdAttack = true;
            }
            if (holdAttack)
            {
                if (player.isGrounded && player.mana > 0)
                {
                    disableMove        = true;
                    timeAttackHolding += Time.deltaTime;
                    if (timeAttackHolding > (baseTimeAttackHolding / 4))
                    {
                        player.instanceFlameCharging();
                        player.setBool("ChargeFlame", true);
                    }
                }
            }
            if (Input.GetKeyUp(KeyCode.F))
            {
                disableMove = false;
                if (timeAttackHolding > baseTimeAttackHolding)
                {
                    player.chargeFlame();
                }
                else
                {
                    player.destroyFlameCharging();
                }
                player.setBool("ChargeFlame", false);
                timeAttackHolding = 0;
                holdAttack        = false;
            }
        }
        else
        {
            // Move Right
            // if (!moveLeft && !moveRight){
            //     player.idle();
            // }
            // if (moveLeft && moveRight){
            //     player.idle();
            // }
            // if (moveLeft){
            //     player.moveLeft();
            // }
            // if (moveRight){
            //     player.moveRight();
            // }

            if (joystick.Horizontal > 0)
            {
                if (!disableMove)
                {
                    moveLeft  = false;
                    moveRight = true;
                    player.moveRight();
                }
            }
            else if (joystick.Horizontal < 0)
            {
                if (!disableMove)
                {
                    moveRight = false;
                    moveLeft  = true;
                    player.moveLeft();
                }
            }
            else
            {
                moveRight = false;
                moveLeft  = false;
                player.idle();
            }

            // Charge Flame
            if (player.chargeFlameEnable)
            {
                if (player.mana > 0)
                {
                    if (holdAttack && player.isGrounded)
                    {
                        disableMove        = true;
                        timeAttackHolding += Time.deltaTime;
                        if (timeAttackHolding > (baseTimeAttackHolding / 4))
                        {
                            player.setBool("ChargeFlame", true);
                            player.runParticle.Stop();
                            player.instanceFlameCharging();
                        }
                    }
                    else if (!holdAttack)
                    {
                        disableMove = false;
                        player.setBool("ChargeFlame", false);
                        if (timeAttackHolding >= baseTimeAttackHolding)
                        {
                            player.chargeFlame();
                        }
                        else
                        {
                            player.destroyFlameCharging();
                        }
                        timeAttackHolding = 0;
                    }
                }
            }
        }
    }
Example #7
0
        /// <summary>
        /// Find all the pointers and fire raycaster events for them.
        /// </summary>
        public override void Process()
        {
            if (requestedMode != currentMode)
            {
                if (requestedMode == InputModes.Auto)
                {
                    requestedMode = SavedInputMode;
                }

                // Validate the InputModes that has been set
                var voice       = VoiceRequestApproved;
                var controllers = ControllersRequestApproved;
                var hands       = HandsRequestApproved;
                var mouse       = MouseRequestApproved;
                var gaze        = GazeRequestApproved;
                var touch       = TouchRequestApproved;

                // Enable a default device if no devices are enabled
                if (!controllers && !hands && !mouse && !touch && !gaze)
                {
                    if (ControllersAvailable)
                    {
                        controllers = true;
                    }
                    else if (HandsAvailable)
                    {
                        hands = true;
                    }
                    else if (MouseAvailable)
                    {
                        mouse = true;
                    }
                    else if (TouchAvailable)
                    {
                        touch = true;
                    }
                    else if (GazeAvailable)
                    {
                        gaze = true;
                    }
                }

                if (Voice != null)
                {
                    Voice.enabled = voice;
                }

                Gaze.SetActive(gaze);

                Mouse.SetActive(mouse);

                foreach (var touchPoint in Touches)
                {
                    touchPoint.SetActive(touch);
                }

                foreach (var handTracker in Hands)
                {
                    handTracker.SetActive(hands);
                }

                foreach (var motionController in Controllers)
                {
                    motionController.SetActive(controllers);
                }

                // record the actual input mode
                VoiceRequested       = voice;
                ControllersRequested = controllers;
                MouseRequested       = mouse;
                TouchRequested       = touch;
                HandsRequested       = hands;
                GazeRequested        = gaze;

                SavedInputMode = currentMode = requestedMode;
            }

            if (newDevices.Count > 0)
            {
                foreach (var device in newDevices)
                {
                    device.LaserPointerNormalMaterial   = laserPointerNormalMaterial;
                    device.LaserPointerEnabledMaterial  = laserPointerEnabledMaterial;
                    device.LaserPointerDisabledMaterial = laserPointerDisabledMaterial;
                }

                Devices.AddRange(newDevices);
                newDevices.Clear();
            }

            if (newKeyboardShortcuts.Count > 0)
            {
                keyboardShortcuts.AddRange(newKeyboardShortcuts);
                newKeyboardShortcuts.Clear();
            }

            keyPresses.Clear();
            toActivate.Clear();
            toRemove.Clear();

            foreach (var pointer in Devices)
            {
                if (pointer.ProcessInUpdate)
                {
                    ProcessPointer(pointer);
                }
            }

            foreach (var shortcut in keyboardShortcuts)
            {
                if (shortcut == null ||
                    !shortcut.gameObject.scene.isLoaded)
                {
                    toRemove.MaybeAdd(shortcut);
                }
                else if (shortcut.IsInteractable() &&
                         (UnityInput.GetKeyUp(shortcut.KeyCode) ||
                          keyPresses.Contains(shortcut.KeyCode)))
                {
                    toActivate.MaybeAdd(shortcut);
                }
            }

            foreach (var shortcut in toRemove)
            {
                keyboardShortcuts.Remove(shortcut);
            }

            if (!paused)
            {
                foreach (var shortcut in toActivate)
                {
                    shortcut.ActivateEvent();
                }
            }
        }
Example #8
0
    /// <summary>
    /// Perform logic to update mouse/pointing device
    /// </summary>
    void UpdateMouse()
    {
        basicMouseInfo.previousPosition = basicMouseInfo.currentPosition;
        basicMouseInfo.currentPosition  = UnityInput.mousePosition;
        basicMouseInfo.delta            = basicMouseInfo.currentPosition - basicMouseInfo.previousPosition;
        mouseMovedOnThisFrame           = basicMouseInfo.delta.sqrMagnitude >= Mathf.Epsilon;
        mouseButtonPressedThisFrame     = false;

        // Move event
        if (basicMouseInfo.delta.sqrMagnitude > Mathf.Epsilon)
        {
            if (mouseMoved != null)
            {
                mouseMoved(basicMouseInfo);
            }
        }
        // Button events
        for (int i = 0; i < trackMouseButtons; ++i)
        {
            MouseButtonInfo mouseButton = m_MouseInfo[i];
            mouseButton.delta            = basicMouseInfo.delta;
            mouseButton.previousPosition = basicMouseInfo.previousPosition;
            mouseButton.currentPosition  = basicMouseInfo.currentPosition;
            if (UnityInput.GetMouseButton(i))
            {
                if (!mouseButton.isDown)
                {
                    // First press
                    mouseButtonPressedThisFrame = true;
                    mouseButton.isDown          = true;
                    mouseButton.startPosition   = UnityInput.mousePosition;
                    mouseButton.startTime       = Time.realtimeSinceStartup;
                    mouseButton.startedOverUI   = EventSystem.current.IsPointerOverGameObject(-mouseButton.mouseButtonId - 1);

                    // Reset some stuff
                    mouseButton.totalMovement = 0;
                    mouseButton.isDrag        = false;
                    mouseButton.wasHold       = false;
                    mouseButton.isHold        = false;
                    mouseButton.flickVelocity = Vector2.zero;

                    if (pressed != null)
                    {
                        pressed(mouseButton);
                    }
                }
                else
                {
                    float moveDist = mouseButton.delta.magnitude;
                    // Dragging?
                    mouseButton.totalMovement += moveDist;
                    if (mouseButton.totalMovement > dragThresholdMouse)
                    {
                        bool wasDrag = mouseButton.isDrag;

                        mouseButton.isDrag = true;
                        if (mouseButton.isHold)
                        {
                            mouseButton.wasHold = mouseButton.isHold;
                            mouseButton.isHold  = false;
                        }

                        // Did it just start now?
                        if (!wasDrag)
                        {
                            if (startedDrag != null)
                            {
                                startedDrag(mouseButton);
                            }
                        }
                        if (dragged != null)
                        {
                            dragged(mouseButton);
                        }

                        // Flick?
                        if (moveDist > flickThreshold)
                        {
                            mouseButton.flickVelocity =
                                (mouseButton.flickVelocity * (1 - k_FlickAccumulationFactor)) +
                                (mouseButton.delta * k_FlickAccumulationFactor);
                        }
                        else
                        {
                            mouseButton.flickVelocity = Vector2.zero;
                        }
                    }
                    else
                    {
                        // Stationary?
                        if (!mouseButton.isHold &&
                            !mouseButton.isDrag &&
                            Time.realtimeSinceStartup - mouseButton.startTime >= holdTime)
                        {
                            mouseButton.isHold = true;
                            if (startedHold != null)
                            {
                                startedHold(mouseButton);
                            }
                        }
                    }
                }
            }
            else // Mouse button not up
            {
                if (mouseButton.isDown) // Released
                {
                    mouseButton.isDown = false;
                    // Quick enough (with no drift) to be a tap?
                    if (!mouseButton.isDrag &&
                        Time.realtimeSinceStartup - mouseButton.startTime < tapTime)
                    {
                        if (tapped != null)
                        {
                            tapped(mouseButton);
                        }
                    }
                    if (released != null)
                    {
                        released(mouseButton);
                    }
                }
            }
        }

        // Mouse wheel
        if (Mathf.Abs(UnityInput.GetAxis("Mouse ScrollWheel")) > Mathf.Epsilon)
        {
            if (spunWheel != null)
            {
                spunWheel(new WheelInfo
                {
                    scrollAmount = UnityInput.GetAxis("Mouse ScrollWheel") * mouseWheelSensitivity
                });
            }
        }
    }
Example #9
0
 /// <summary> ボタンが押されている間 </summary>
 public static bool GetButton(Button button, GPRawID rawID)
 => UInput.GetKey(GetKeycode(button, rawID));
Example #10
0
        /// <summary>
        /// Init this instance.
        /// </summary>
        protected virtual void Init()
        {
            // If the menu item is visible at start then it is active and accepting input
            AcceptingInput = visibleComponent.activeInHierarchy;

            menuItems = new List<UIMenuItem> ();
            UIMenuItem[] allMenuItems = GetComponentsInChildren<UIMenuItem> ();
            for (int i = 0; i < allMenuItems.Length; i++)
            {
                // Only collect direct children
                if (allMenuItems[i].transform.parent == transform)
                {
                    menuItems.Add(allMenuItems[i]);
                }
            }
            CreateUI ();
            currentlySelectedItem = -1;
            SetPointer (initialSelection);
            Select(initialSelection);
            Input[] inputs = FindObjectsOfType<Input> ();
            if (inputs.Length > 0)
            {
                // Use player 1 input if we can find it
                for (int i = 0; i < inputs.Length; i++)
                {
                    if (inputs[i] is StandardInput && ((StandardInput)inputs[i]).dataToLoad == "Player1")
                    {
                        input = inputs[i];
                    }
                }
                // Couldn't work out which input is player 1, use the first one we found
                if (input == null) input = inputs[0];
            }
            if (visibleComponent.activeInHierarchy) Show ();
        }
Example #11
0
        public EventModifiers GetRawEventModifiers()
        {
            EventModifiers eventModifiers = EventModifiers.None;

            if (UnityInput.GetKeyDown(KeyCode.LeftAlt) || UnityInput.GetKeyDown(KeyCode.RightAlt) || UnityInput.GetKey(KeyCode.LeftAlt) || UnityInput.GetKey(KeyCode.RightAlt))
            {
                eventModifiers |= EventModifiers.Alt;
            }

            if (UnityInput.GetKeyDown(KeyCode.LeftControl) || UnityInput.GetKeyDown(KeyCode.RightControl) || UnityInput.GetKey(KeyCode.LeftControl) || UnityInput.GetKey(KeyCode.RightControl))
            {
                eventModifiers |= EventModifiers.Control;
            }

            if (UnityInput.GetKeyDown(KeyCode.LeftShift) || UnityInput.GetKeyDown(KeyCode.RightShift) || UnityInput.GetKey(KeyCode.LeftShift) || UnityInput.GetKey(KeyCode.RightShift))
            {
                eventModifiers |= EventModifiers.Shift;
            }

            return(eventModifiers);
        }
Example #12
0
 public static float GetAxisRaw(string name)
 {
     return(UnityInput.GetAxisRaw(name));
 }
        void Update()
        {
            LastFrame = CurrentFrame;

            CurrentFrame.MouseLeftHeld = I.GetMouseButton(0);
            CurrentFrame.MouseLeftDown = I.GetMouseButtonDown(0);
            CurrentFrame.MouseLeftUp   = I.GetMouseButtonUp(0);

            CurrentFrame.MouseRightHeld = I.GetMouseButton(1);
            CurrentFrame.MouseRightDown = I.GetMouseButtonDown(1);
            CurrentFrame.MouseRightUp   = I.GetMouseButtonUp(1);

            CurrentFrame.MouseMiddleHeld = I.GetMouseButton(2);
            CurrentFrame.MouseMiddleDown = I.GetMouseButtonDown(2);
            CurrentFrame.MouseMiddleUp   = I.GetMouseButtonUp(2);

            CurrentFrame.MouseScreenPosition = UnityEngine.Input.mousePosition;
            CurrentFrame.MouseScreenDelta    = CurrentFrame.MouseScreenPosition - LastFrame.MouseScreenPosition;

            CurrentFrame.MouseLeftDragging    = CurrentFrame.MouseLeftHeld;
            CurrentFrame.MouseLeftDragStarted = CurrentFrame.MouseLeftDragging && !LastFrame.MouseLeftDragging;
            CurrentFrame.MouseLeftDragStopped = !CurrentFrame.MouseLeftDragging && LastFrame.MouseLeftDragging;

            CurrentFrame.MouseRightDragging    = CurrentFrame.MouseRightHeld;
            CurrentFrame.MouseRightDragStarted = CurrentFrame.MouseRightDragging && !LastFrame.MouseRightDragging;
            CurrentFrame.MouseRightDragStopped = !CurrentFrame.MouseRightDragging && LastFrame.MouseRightDragging;

            var mainCamera = CameraController.Instance;
            var ray        = mainCamera.MainCamera.ScreenPointToRay(CurrentFrame.MouseScreenPosition);

            CurrentFrame.MouseScreenPositionLeftDown   = CurrentFrame.MouseLeftDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionLeftDown;
            CurrentFrame.MouseScreenPositionRightDown  = CurrentFrame.MouseRightDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionRightDown;
            CurrentFrame.MouseScreenPositionMiddleDown = CurrentFrame.MouseMiddleDown ? CurrentFrame.MouseScreenPosition : LastFrame.MouseScreenPositionMiddleDown;

            if (Physics.RaycastNonAlloc(ray, m_Results) > 0)
            {
                CurrentFrame.MouseLocalPosition = m_Results[0].point / mainCamera.Data.Units;
                CurrentFrame.MouseLocalDelta    = CurrentFrame.MouseLeftDragStarted ? float3.zero : CurrentFrame.MouseLocalPosition - LastFrame.MouseLocalPosition;

                CurrentFrame.MouseWorldPosition = mainCamera.Data.LookAtPosition + CurrentFrame.MouseLocalPosition;
                CurrentFrame.MouseWorldDelta    = CurrentFrame.MouseLeftDragStarted ? double3.zero : CurrentFrame.MouseWorldPosition - LastFrame.MouseWorldPosition;
            }
            else
            {
                CurrentFrame.MouseLocalPosition = LastFrame.MouseLocalPosition;
                CurrentFrame.MouseLocalDelta    = LastFrame.MouseLocalDelta;
                CurrentFrame.MouseWorldPosition = LastFrame.MouseWorldPosition;
                CurrentFrame.MouseWorldDelta    = LastFrame.MouseWorldDelta;
            }

            var topLeft = mainCamera.MainCamera.ScreenPointToRay(new Vector3(Screen.width, Screen.height, 0f));

            if (Physics.RaycastNonAlloc(topLeft, m_Results) > 0)
            {
                CurrentFrame.TopLeftLocalPosition = m_Results[0].point / mainCamera.Data.Units;
                CurrentFrame.TopLeftWorldPosition = mainCamera.Data.LookAtPosition + CurrentFrame.TopLeftLocalPosition;
            }
            else
            {
                CurrentFrame.TopLeftLocalPosition = LastFrame.TopLeftLocalPosition;
                CurrentFrame.TopLeftWorldPosition = LastFrame.TopLeftWorldPosition;
            }

            CurrentFrame.PrimaryAxis   = new float2(I.GetAxis("Horizontal"), I.GetAxis("Vertical"));
            CurrentFrame.SecondaryAxis = new float2(I.GetAxis("Mouse ScrollWheel"), 0f);

            CurrentFrame.MouseLeftClicked = CurrentFrame.MouseLeftUp && LastFrame.MouseLeftHeld &&
                                            math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionLeftDown) < 2;

            CurrentFrame.MouseRightClicked = CurrentFrame.MouseRightUp && LastFrame.MouseRightHeld &&
                                             math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionRightDown) < 2;

            CurrentFrame.MouseMiddleClicked = CurrentFrame.MouseMiddleUp && LastFrame.MouseMiddleHeld &&
                                              math.lengthsq(CurrentFrame.MouseScreenPosition - CurrentFrame.MouseScreenPositionMiddleDown) < 2;

            CurrentFrame.PrimaryAction    = I.GetAxis("Fire1") > 0f;
            CurrentFrame.SecondaryAction  = I.GetAxis("Fire2") > 0f;
            CurrentFrame.TertiaryAction   = I.GetAxis("Fire3") > 0f;
            CurrentFrame.QuaternaryAction = I.GetAxis("Jump") > 0f;

            CurrentFrame.CycleForwardAction  = I.GetKeyUp(KeyCode.Equals);
            CurrentFrame.CycleBackwardAction = I.GetKeyUp(KeyCode.Minus);

            CurrentFrame.CancelAction = I.GetKeyUp(KeyCode.Escape);

            CurrentFrame.SubActions[0]  = I.GetKeyUp(KeyCode.F1);
            CurrentFrame.SubActions[1]  = I.GetKeyUp(KeyCode.F2);
            CurrentFrame.SubActions[2]  = I.GetKeyUp(KeyCode.F3);
            CurrentFrame.SubActions[3]  = I.GetKeyUp(KeyCode.F4);
            CurrentFrame.SubActions[4]  = I.GetKeyUp(KeyCode.F5);
            CurrentFrame.SubActions[5]  = I.GetKeyUp(KeyCode.F6);
            CurrentFrame.SubActions[6]  = I.GetKeyUp(KeyCode.F7);
            CurrentFrame.SubActions[7]  = I.GetKeyUp(KeyCode.F8);
            CurrentFrame.SubActions[8]  = I.GetKeyUp(KeyCode.F9);
            CurrentFrame.SubActions[9]  = I.GetKeyUp(KeyCode.F10);
            CurrentFrame.SubActions[10] = I.GetKeyUp(KeyCode.F11);
            CurrentFrame.SubActions[11] = I.GetKeyUp(KeyCode.F12);
        }
Example #14
0
 public static bool IsNewMouseButtonRelease(MouseButton mouseButton)
 {
     return(UnityInput.GetMouseButtonUp((int)mouseButton));
 }
Example #15
0
 public static bool IsNewMouseButtonPress(MouseButton mouseButton)
 {
     return(UnityInput.GetMouseButtonDown((int)mouseButton));
 }
Example #16
0
 public static bool IsMouseButtonReleased(MouseButton mouseButton)
 {
     return(!UnityInput.GetMouseButton((int)mouseButton));
 }
Example #17
0
 public static bool IsMouseButtonPressed(MouseButton mouseButton)
 {
     return(UnityInput.GetMouseButton((int)mouseButton));
 }
Example #18
0
 public static bool IsNewButtonRelease(string name)
 {
     return(UnityInput.GetButtonUp(name));
 }
 private void Update()
 {
     m_jump           = UnityInput.GetButtonDown("Jump");
     m_crouch         = UnityInput.GetButton("Crouch");
     m_horizontalMove = UnityInput.GetAxis("Horizontal");
 }
Example #20
0
 public override bool IsButtonUp(MouseButton button)
 {
     return(UnityInput.GetKeyUp((KeyCode)button));
 }
Example #21
0
 public override bool GetUp(GPButton button) => m_keys.ContainsKey(button) && UInput.GetKeyUp(m_keys[button]);
        partial void DrawDebug()
        {
            if (Input.GetKeyDown(KeyCode.F1))
            {
                Vector3?eyepos = GetEyePosition();
                if (eyepos.HasValue)
                {
                    CastMeteor(new Vector3(eyepos.Value.x, eyepos.Value.y + 100, eyepos.Value.z));
                }
            }
            GUI.Label(new Rect(10, 10, 500, 30), $"Player position X = {LocalPlayer.Transform.position.x} Y = {LocalPlayer.Transform.position.y} Z = {LocalPlayer.Transform.position.z}");
            if (Physics.Raycast(Camera.main.transform.position + (Vector3.forward * 2), Camera.main.transform.forward, out var raycastInfo, 1000, ~0))
            {
                LayerMask layermasks = GetCollisionMaskOf(raycastInfo.transform.gameObject);
                GUI.Label(new Rect(10, 30, 500, 30), $"Tag = {raycastInfo.transform.gameObject.tag} Name = {raycastInfo.transform.gameObject.name} LayerMask = {layermasks.value.ToString("X")} Layer = {raycastInfo.transform.gameObject.layer}");
            }

            //Ruler

            if (rulerObj == null)
            {
                rulerObj = new GameObject();
                rulerObj.AddComponent <LineRenderer>();
            }

            if (Input.GetKeyDown(KeyCode.F7))
            {
                rulerStart = LocalPlayer.Transform.position;
            }
            if (Input.GetKeyDown(KeyCode.F8))
            {
                rulerEnd = LocalPlayer.Transform.position;
            }
            if (Input.GetKeyDown(KeyCode.F9))
            {
                rulerStart = Vector3.zero;
                rulerEnd   = Vector3.zero;
            }

            if (rulerStart != Vector3.zero && rulerEnd != Vector3.zero)
            {
                rulerHue++;
                Color rulerColor = Color.HSVToRGB((rulerHue % 360) / 360f, 1f, 1f);
                rulerObj.transform.position = rulerStart;

                LineRenderer lr = rulerObj.GetComponent <LineRenderer>();
                lr.material = new Material(Shader.Find("Particles/Alpha Blended Premultiply"));
                lr.SetColors(rulerColor, rulerColor);
                lr.SetWidth(0.1f, 0.1f);
                lr.SetPosition(0, rulerStart);
                lr.SetPosition(1, rulerEnd);
                Vector3 firstCameraPoint = Camera.main.WorldToScreenPoint(rulerStart);
                Vector3 lastCameraPoint  = Camera.main.WorldToScreenPoint(rulerEnd);
                if (firstCameraPoint.z > 0f)
                {
                    firstCameraPoint.y = Screen.height - firstCameraPoint.y;
                    float size = Mathf.Clamp(600 / Vector3.Distance(rulerStart, LocalPlayer.Transform.position), 10, 50);
                    size *= screenScale;
                    Rect r = new Rect(0, 0, 400, size)
                    {
                        center = firstCameraPoint
                    };
                    GUI.Label(r, $"Client distance = {Vector3.Distance(rulerStart, LocalPlayer.Transform.position)}");
                }
                if (lastCameraPoint.z > 0f)
                {
                    lastCameraPoint.y = Screen.height - lastCameraPoint.y;
                    float size = Mathf.Clamp(600 / Vector3.Distance(rulerEnd, LocalPlayer.Transform.position), 10, 50);
                    size *= screenScale;
                    Rect r = new Rect(0, 0, 400, size)
                    {
                        center = lastCameraPoint
                    };
                    GUI.Label(r, $"Client distance = {Vector3.Distance(rulerEnd, LocalPlayer.Transform.position)}\nLineLen = {Vector3.Distance(rulerStart, rulerEnd)}");
                }
            }
            if (PlayerInventoryMod.EquippedModel != BaseItem.WeaponModelType.None)
            {
                GUI.Label(new Rect(600, 300, 500, 30), "Offset");
                GUI.Label(new Rect(600, 330, 100, 30), PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].offset.x.ToString());
                GUI.Label(new Rect(700, 330, 100, 30), PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].offset.y.ToString());
                GUI.Label(new Rect(800, 330, 100, 30), PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].offset.z.ToString());

                posX = GUI.TextField(new Rect(600, 360, 100, 30), posX);
                posY = GUI.TextField(new Rect(700, 360, 100, 30), posY);
                posZ = GUI.TextField(new Rect(800, 360, 100, 30), posZ);

                GUI.Label(new Rect(600, 400, 500, 30), "Rotation");
                GUI.Label(new Rect(600, 430, 100, 30), PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].rotation.x.ToString());
                GUI.Label(new Rect(700, 430, 100, 30), PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].rotation.y.ToString());
                GUI.Label(new Rect(800, 430, 100, 30), PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].rotation.z.ToString());

                rotX = GUI.TextField(new Rect(600, 460, 100, 30), rotX);
                rotY = GUI.TextField(new Rect(700, 460, 100, 30), rotY);
                rotZ = GUI.TextField(new Rect(800, 460, 100, 30), rotZ);

                if (GUI.Button(new Rect(600, 500, 300, 40), "Apply"))
                {
                    if (float.TryParse(posX, out float x))
                    {
                        if (float.TryParse(posY, out float y))
                        {
                            if (float.TryParse(posZ, out float z))
                            {
                                Vector3 v = new Vector3(x, y, z);
                                PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].obj.transform.localPosition = v;
                                PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].offset = v;
                            }
                        }
                    }
                    if (float.TryParse(rotX, out float x1))
                    {
                        if (float.TryParse(rotY, out float y))
                        {
                            if (float.TryParse(rotZ, out float z))
                            {
                                Vector3 v = new Vector3(x1, y, z);
                                PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].obj.transform.localRotation = Quaternion.Euler(v);
                                PlayerInventoryMod.customWeapons[PlayerInventoryMod.EquippedModel].rotation = v;
                            }
                        }
                    }
                }
            }
        }
Example #23
0
        private void OnDroppedFiles(List <string> aFiles, POINT aPos)
        {
            var import = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);

            Logger.Log(BepInEx.Logging.LogLevel.Debug, import ? "Importing" : "Overwriting");

            if (aFiles.Count == 0)
            {
                return;
            }

            if (!Singleton <Scene> .IsInstance())
            {
                return;
            }

            var goodFiles = aFiles.Where(f =>
            {
                if (string.IsNullOrEmpty(f))
                {
                    return(false);
                }

                var extension = Path.GetExtension(f).ToLower();
                if (extension == ".png")
                {
                    return(true);
                }

                Logger.Log(BepInEx.Logging.LogLevel.Message, $"Unsupported file type {extension}. Only .png files are supported.");
                return(false);
            }).ToList();

            if (goodFiles.Count == 0)
            {
                PlaySound(SystemSE.ok_l);
                return;
            }

            PngType GetType(string path)
            {
                var pngType = GetPngType(path);

                if (pngType == PngType.Unknown)
                {
                    Logger.Log(BepInEx.Logging.LogLevel.Message, "Unknown file format.");
                    PlaySound(SystemSE.ok_l);
                }

                return(pngType);
            }

            try
            {
                if (Singleton <Scene> .Instance.NowSceneNames.Any(sceneName => sceneName == "CharaCustom"))
                {
                    if (Singleton <CustomBase> .IsInstance())
                    {
                        if (goodFiles.Count > 1)
                        {
                            Logger.Log(BepInEx.Logging.LogLevel.Message, "Warning: Only the first card will be loaded.");
                        }

                        var path    = goodFiles.First();
                        var pngType = GetType(path);

                        if (pngType == PngType.AIS_Chara)
                        {
                            LoadMakerCharacter(path);
                            PlaySound(SystemSE.ok_s);
                        }
                        else if (pngType == PngType.KStudio)
                        {
                            Logger.Log(BepInEx.Logging.LogLevel.Message, "Scene files cannot be loaded in the character maker.");
                            PlaySound(SystemSE.ok_l);
                        }
                    }
                }
                else if (Singleton <Scene> .Instance.NowSceneNames.Any(sceneName => sceneName == "Map"))
                {
                    if (FindObjectsOfType <UICtrl>().Any(i => i.IsInit))
                    {
                        if (goodFiles.Count > 1)
                        {
                            Logger.Log(BepInEx.Logging.LogLevel.Message, "Warning: Only the first card will be loaded.");
                        }

                        var path    = goodFiles.First();
                        var pngType = GetType(path);

                        if (pngType == PngType.AIS_Housing)
                        {
                            LoadHousing(path);
                            PlaySound(SystemSE.ok_s);
                        }
                    }
                }
                else if (Singleton <Scene> .Instance.NowSceneNames.Any(sceneName => sceneName == "Studio"))
                {
                    var goodFiles2 = goodFiles
                                     .Select(x => new KeyValuePair <string, PngType>(x, GetType(x))).ToList();
                    var scenes = goodFiles2.Where(x => x.Value == PngType.KStudio).ToList();
                    var cards  = goodFiles2.Where(x => x.Value == PngType.AIS_Chara).ToList();

                    StartCoroutine(StudioLoadCoroutine(scenes, cards, import));
                }
            }
            catch (Exception ex)
            {
                PrintError(ex);
                PlaySound(SystemSE.ok_l);
            }
        }
Example #24
0
 /// <summary>
 /// キーボードによる入力はあくまでデバッグ用とみなす
 /// </summary>
 public static bool DebugKeyDown(KeyCode code) => UInput.GetKeyDown(code);
        /// <summary>
        /// Handle camera panning behaviour
        /// </summary>
        protected void Update()
        {
            // Escape handling
            if (UnityInput.GetKeyDown(KeyCode.Escape))
            {
                switch (m_GameUI.state)
                {
                case State.Normal:
                    if (m_GameUI.isTowerSelected)
                    {
                        m_GameUI.DeselectTower();
                    }
                    else
                    {
                        m_GameUI.Pause();
                    }
                    break;

                case State.BuildingWithDrag:
                case State.Building:
                    m_GameUI.CancelGhostPlacement();
                    break;
                }
            }

            // place towers with keyboard numbers
            if (LevelManager.instanceExists)
            {
                int towerLibraryCount = LevelManager.instance.towerLibrary.Count;

                // find the lowest value between 9 (keyboard numbers)
                // and the amount of towers in the library
                int     count      = Mathf.Min(9, towerLibraryCount);
                KeyCode highestKey = KeyCode.Alpha1 + count;

                for (var key = KeyCode.Alpha1; key < highestKey; key++)
                {
                    // add offset for the KeyCode Alpha 1 index to find correct keycodes
                    if (UnityInput.GetKeyDown(key))
                    {
                        Tower controller = LevelManager.instance.towerLibrary[key - KeyCode.Alpha1];
                        if (LevelManager.instance.currency.CanAfford(controller.purchaseCost))
                        {
                            if (m_GameUI.isBuilding)
                            {
                                m_GameUI.CancelGhostPlacement();
                            }
                            GameUI.instance.SetToBuildMode(controller);
                            GameUI.instance.TryMoveGhost(InputController.instance.BasicGazeInfo);
                        }
                        break;
                    }
                }

                // special case for 0 mapping to index 9
                if (count < 10 && UnityInput.GetKeyDown(KeyCode.Alpha0))
                {
                    Tower controller = LevelManager.instance.towerLibrary[9];
                    GameUI.instance.SetToBuildMode(controller);
                    GameUI.instance.TryMoveGhost(InputController.instance.BasicGazeInfo);
                }
            }
        }
        private void OnGUI()
        {
            if (!_xr || _xr.InSession)
            {
                return;
            }

            if (UInput.mouseScrollDelta.y != 0)
            {
                _lastScrollTime = Time.time;
            }

            var wheelScroll = (Time.time - _lastScrollTime) < 1;


            var txt = new StringBuilder();

            txt.Append("    <b>Help</b>\r\nMove camera with arrows : ");
            Append(txt, "LEFT", UInput.GetKey(KeyCode.LeftArrow));
            txt.Append(", ");
            Append(txt, "RIGHT", UInput.GetKey(KeyCode.RightArrow));
            txt.Append(", ");
            Append(txt, "UP", UInput.GetKey(KeyCode.UpArrow));
            txt.Append(", ");
            Append(txt, "DOWN", UInput.GetKey(KeyCode.DownArrow));

            txt.Append("\r\nRotate camera : ");
            Append(txt, "Right Mouse Button", UInput.GetMouseButton(1));

            txt.Append("\r\nMove hands : ");
            Append(txt, "Left Shift", UInput.GetKey(KeyCode.LeftShift));
            txt.Append(", ");
            Append(txt, "Space Bar", UInput.GetKey(KeyCode.Space));

            txt.Append("\r\nToggle hands : ");
            Append(txt, "T ", UInput.GetKey(KeyCode.T));
            txt.Append(", ");
            Append(txt, "Y", UInput.GetKey(KeyCode.Y));

            txt.Append("\r\nMove hand : ");
            Append(txt, "Left Shift + Wheel", UInput.GetKey(KeyCode.LeftShift) && wheelScroll);

            txt.Append("\r\nRotate hand : ");
            Append(txt, "Left Shift + Left CTRL + Wheel", UInput.GetKey(KeyCode.LeftShift) && UInput.GetKey(KeyCode.LeftControl) && wheelScroll);

            txt.Append("\r\nPinch / Select : ");
            Append(txt, "Left Mouse Button", UInput.GetMouseButton(0));

            GUI.Label(new Rect(0, 0, Screen.width, Screen.height), txt.ToString());
        }
Example #27
0
        /// <summary>
        /// returns a specified axis
        /// </summary>
        /// <param name="axis">One of the analogue sticks, or the dpad</param>
        /// <param name="rawID">The controller number</param>
        /// <param name="raw">if raw is false then the controlIndex will be returned with a deadspot</param>
        /// <returns></returns>

        public static Vector2 GetAxis(Axis axis, GPRawID rawID, bool raw = false)
        {
            IList <AxisName> axisNameList = new List <AxisName>();
            string           xName = "", yName = "";


            switch (axis)
            {
            case Axis.Dpad:
                xName = "DPad_XAxis_" + (int)rawID;
                yName = "DPad_YAxis_" + (int)rawID;
                axisNameList.Add(new AxisName(xName, yName));
                break;

            case Axis.LeftStick:
                xName = "L_XAxis_" + (int)rawID;
                yName = "L_YAxis_" + (int)rawID;
                axisNameList.Add(new AxisName(xName, yName));
                break;

            case Axis.RightStick:
                xName = "R_XAxis_" + (int)rawID;
                yName = "R_YAxis_" + (int)rawID;
                axisNameList.Add(new AxisName(xName, yName));
                break;

            case Axis.Any:
                xName = "DPad_XAxis_" + (int)rawID;
                yName = "DPad_YAxis_" + (int)rawID;
                axisNameList.Add(new AxisName(xName, yName));
                xName = "L_XAxis_" + (int)rawID;
                yName = "L_YAxis_" + (int)rawID;
                axisNameList.Add(new AxisName(xName, yName));
                xName = "R_XAxis_" + (int)rawID;
                yName = "R_YAxis_" + (int)rawID;
                axisNameList.Add(new AxisName(xName, yName));
                break;
            }

            Vector2 axisXY = Vector3.zero;

            try {
                foreach (AxisName elem in axisNameList)
                {
                    float x, y;

                    if (raw == false)
                    {
                        x = UInput.GetAxis(elem.xName);
                        y = UInput.GetAxis(elem.yName);
                    }
                    else
                    {
                        x = UInput.GetAxisRaw(elem.xName);
                        y = UInput.GetAxisRaw(elem.yName);
                    }

                    Vector2 vec = new Vector2(x, y);
                    float   mag = vec.magnitude;

                    if (mag > 0f)
                    {
                        axisXY.x = x;
                        axisXY.y = y;
                    }
                }
            }
            catch (System.Exception e) {
                Debug.LogError(e);
                Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input");
            }
            return(axisXY);
        }
        /// <summary>
        /// Update controller.
        /// </summary>
        public void Update()
        {
            if (!UInput.mousePresent)
            {
                return;
            }

            // Bail early if our mouse isn't in our game window.
            if (UInput.mousePosition.x < 0 ||
                UInput.mousePosition.y < 0 ||
                UInput.mousePosition.x > Screen.width ||
                UInput.mousePosition.y > Screen.height)
            {
                return;
            }

            // Capture new position
            var newScreenPosition = UInput.mousePosition;

            newScreenPosition.z = 1.0f;

            // Update delta
            mouseDelta.x        = this.screenPosition.x - newScreenPosition.x;
            mouseDelta.y        = this.screenPosition.y - newScreenPosition.y;
            this.screenPosition = newScreenPosition;

            var camera = CameraCache.Main;
            var lookAt = (camera.ScreenToWorldPoint(this.screenPosition) - camera.transform.position).normalized;

            controllerPose.Position = camera.transform.position;
            controllerPose.Rotation = Quaternion.LookRotation(lookAt, camera.transform.up);

            CoreServices.InputSystem?.RaiseSourcePositionChanged(InputSource, this, mouseDelta);
            CoreServices.InputSystem?.RaiseSourcePoseChanged(InputSource, this, controllerPose);
            CoreServices.InputSystem?.RaiseSourcePositionChanged(InputSource, this, UInput.mouseScrollDelta);

            foreach (var interaction in Interactions)
            {
                if (interaction.InputType == DeviceInputType.SpatialPointer)
                {
                    interaction.PoseData = controllerPose;

                    if (interaction.Changed)
                    {
                        CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, interaction.MixedRealityInputAction, interaction.PoseData);
                    }
                }

                if (interaction.InputType == DeviceInputType.PointerPosition)
                {
                    interaction.Vector2Data = mouseDelta;

                    if (interaction.Changed)
                    {
                        CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interaction.MixedRealityInputAction, interaction.Vector2Data);
                    }
                }

                if (interaction.InputType == DeviceInputType.Scroll)
                {
                    interaction.Vector2Data = UInput.mouseScrollDelta;

                    if (interaction.Changed)
                    {
                        CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, interaction.MixedRealityInputAction, interaction.Vector2Data);
                    }
                }

                if (interaction.AxisType == AxisType.Digital)
                {
                    var keyButton = UInput.GetKey(interaction.KeyCode);

                    // Update the interaction data source
                    interaction.BoolData = keyButton;

                    // If our value changed raise it.
                    if (interaction.Changed)
                    {
                        // Raise input system Event if it enabled
                        if (interaction.BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interaction.MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interaction.MixedRealityInputAction);
                        }
                    }
                }
            }
        }
Example #29
0
        /// <summary>
        /// Update controller.
        /// </summary>
        public void Update()
        {
            using (UpdatePerfMarker.Auto())
            {
                if (!UInput.mousePresent)
                {
                    return;
                }

                if (mouseDeviceManager == null)
                {
                    mouseDeviceManager = CoreServices.GetInputSystemDataProvider <IMixedRealityMouseDeviceManager>();
                }

                // Bail early if our mouse isn't in our game window.
                if (UInput.mousePosition.x < 0 ||
                    UInput.mousePosition.y < 0 ||
                    UInput.mousePosition.x > Screen.width ||
                    UInput.mousePosition.y > Screen.height)
                {
                    return;
                }

                for (int i = 0; i < Interactions.Length; i++)
                {
                    if ((Interactions[i].InputType == DeviceInputType.SpatialPointer) ||
                        (Interactions[i].InputType == DeviceInputType.PointerPosition))
                    {
                        Vector3 mouseDelta = Vector3.zero;
                        mouseDelta.x = -UInput.GetAxis("Mouse Y");
                        mouseDelta.y = UInput.GetAxis("Mouse X");
                        if (mouseDeviceManager != null)
                        {
                            // Apply cursor speed.
                            mouseDelta *= mouseDeviceManager.CursorSpeed;
                        }

                        if (Interactions[i].InputType == DeviceInputType.SpatialPointer)
                        {
                            // Spatial pointer raises Pose events
                            controllerPose           = MixedRealityPose.ZeroIdentity;
                            controllerPose.Rotation  = Quaternion.Euler(mouseDelta);
                            Interactions[i].PoseData = controllerPose;

                            if (Interactions[i].Changed)
                            {
                                CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData);
                            }
                        }
                        else
                        {
                            // Pointer position raises position events
                            Interactions[i].Vector2Data = mouseDelta;

                            if (Interactions[i].Changed)
                            {
                                CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                            }
                        }
                    }

                    if (Interactions[i].AxisType == AxisType.Digital)
                    {
                        var keyButton = UInput.GetKey(Interactions[i].KeyCode);

                        // Update the interaction data source
                        Interactions[i].BoolData = keyButton;

                        // If our value changed raise it.
                        if (Interactions[i].Changed)
                        {
                            // Raise input system event if it's enabled
                            if (Interactions[i].BoolData)
                            {
                                CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                            }
                            else
                            {
                                CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                            }
                        }
                    }

                    if (Interactions[i].InputType == DeviceInputType.Scroll)
                    {
                        Vector2 wheelDelta = UInput.mouseScrollDelta;
                        if (mouseDeviceManager != null)
                        {
                            // Apply wheel speed.
                            wheelDelta *= mouseDeviceManager.WheelSpeed;
                        }

                        Interactions[i].Vector2Data = wheelDelta;

                        if (Interactions[i].Changed)
                        {
                            CoreServices.InputSystem?.RaisePositionInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                        }
                    }
                }
            }
        }
Example #30
0
        private void Update()
        {
            if (EditorMode && EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            var leftDown   = Input.GetMouseButtonDown(0);
            var rightDown  = Input.GetMouseButtonDown(1);
            var rightHold  = Input.GetMouseButton(1);
            var middleDown = Input.GetMouseButtonDown(2);
            var middleHold = Input.GetMouseButton(2);
            var delDown    = Input.GetKeyDown(KeyCode.Delete);

            if (!(leftDown || rightHold || rightDown || middleDown || middleHold || delDown))
            {
                return;
            }

            var        ray = _camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit unitHit;
            var        unitRaycastHit = Physics.Raycast(ray, out unitHit, Mathf.Infinity, LayerMask.GetMask("Units"));
            RaycastHit terrainHit;
            var        terrainRaycastHit = Physics.Raycast(ray, out terrainHit, Mathf.Infinity, LayerMask.GetMask("Terrain"));

            if (EditorMode)
            {
                if (leftDown)
                {
                    if (unitRaycastHit && IsUnit(unitHit.collider))
                    {
                        _selection = unitHit.transform.parent;
                        ShowHandle(_selection);
                    }
                    else if (terrainRaycastHit)
                    {
                        _selection = Instantiate(
                            _activeUnitPrefab,
                            terrainHit.point,
                            Quaternion.identity,
                            _unitWrapper).transform;
                        ShowHandle(_selection);
                    }
                }
                else if (rightHold)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    if (terrainRaycastHit)
                    {
                        _selection.position = terrainHit.point;
                    }
                }
                else if (middleDown)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    _startRotation      = _selection.rotation;
                    _startMousePosition = Input.mousePosition;
                }
                else if (middleHold)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    _selection.rotation = _startRotation * Quaternion.AngleAxis(_startMousePosition.x - Input.mousePosition.x, Vector3.up);
                }
                else if (delDown)
                {
                    if (_selection == null)
                    {
                        return;
                    }

                    Destroy(_selection.gameObject);
                }
            }
            else
            {
                if (leftDown)
                {
                    _activeAgent = unitRaycastHit ? unitHit.collider.GetComponentInParent <NavMeshAgent>() : null;
                }
                else if (rightDown)
                {
                    if (_activeAgent != null)
                    {
                        _activeAgent.SetDestination(terrainHit.point);
                    }
                }
            }
        }
Example #31
0
        private void Update()
        {
#if UNITY_EDITOR
            if (UInput.GetMouseButtonDown(0))
            {
                _lastMousePosition = UInput.mousePosition;
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos   = _lastMousePosition,
                    touchDelta = Vector3.zero
                };
                OnTouchStart?.Invoke(tie);
            }
            else if (UInput.GetMouseButton(0))
            {
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos = UInput.mousePosition
                };
                tie.touchDelta     = tie.touchPos - _lastMousePosition;
                _lastMousePosition = tie.touchPos;
                OnTouchStay?.Invoke(tie);
            }
            else if (UInput.GetMouseButtonUp(0))
            {
                TouchInputEvent tie = new TouchInputEvent()
                {
                    touchPos   = UInput.mousePosition,
                    touchDelta = Vector3.zero
                };
                OnTouchRelease?.Invoke(tie);
            }
#elif UNITY_ANDROID
            if (UInput.touchCount > 0)
            {
                // Only polling touch 0
                Touch           touch = UInput.GetTouch(0);
                TouchInputEvent tie   = new TouchInputEvent()
                {
                    touchPos   = touch.position,
                    touchDelta = touch.deltaPosition
                };

                // Send the respective event depending on touch phase state
                switch (touch.phase)
                {
                case TouchPhase.Began:
                    OnTouchStart?.Invoke(tie);
                    break;

                case TouchPhase.Moved:
                case TouchPhase.Stationary:
                    OnTouchStay?.Invoke(tie);
                    break;

                case TouchPhase.Canceled:
                case TouchPhase.Ended:
                    OnTouchRelease?.Invoke(tie);
                    break;
                }
            }
#endif
        }
        /// <summary>
        /// Update controller.
        /// </summary>
        public void Update()
        {
            if (!UInput.mousePresent)
            {
                return;
            }

            // Bail early if our mouse isn't in our game window.
            if (UInput.mousePosition.x < 0 ||
                UInput.mousePosition.y < 0 ||
                UInput.mousePosition.x > Screen.width ||
                UInput.mousePosition.y > Screen.height)
            {
                return;
            }

            if (InputSource.Pointers[0].BaseCursor != null)
            {
                controllerPose.Position = InputSource.Pointers[0].BaseCursor.Position;
                controllerPose.Rotation = InputSource.Pointers[0].BaseCursor.Rotation;
            }

            mouseDelta.x = -UInput.GetAxis("Mouse Y");
            mouseDelta.y = UInput.GetAxis("Mouse X");
            MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, mouseDelta);
            MixedRealityToolkit.InputSystem?.RaiseSourcePoseChanged(InputSource, this, controllerPose);
            MixedRealityToolkit.InputSystem?.RaiseSourcePositionChanged(InputSource, this, UInput.mouseScrollDelta);

            for (int i = 0; i < Interactions.Length; i++)
            {
                if (Interactions[i].InputType == DeviceInputType.SpatialPointer)
                {
                    Interactions[i].PoseData = controllerPose;

                    if (Interactions[i].Changed)
                    {
                        MixedRealityToolkit.InputSystem?.RaisePoseInputChanged(InputSource, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData);
                    }
                }

                if (Interactions[i].InputType == DeviceInputType.PointerPosition)
                {
                    Interactions[i].Vector2Data = mouseDelta;

                    if (Interactions[i].Changed)
                    {
                        MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                    }
                }

                if (Interactions[i].InputType == DeviceInputType.Scroll)
                {
                    Interactions[i].Vector2Data = UInput.mouseScrollDelta;

                    if (Interactions[i].Changed)
                    {
                        MixedRealityToolkit.InputSystem?.RaisePositionInputChanged(InputSource, Interactions[i].MixedRealityInputAction, Interactions[i].Vector2Data);
                    }
                }

                if (Interactions[i].AxisType == AxisType.Digital)
                {
                    var keyButton = UInput.GetKey(Interactions[i].KeyCode);

                    // Update the interaction data source
                    Interactions[i].BoolData = keyButton;

                    // If our value changed raise it.
                    if (Interactions[i].Changed)
                    {
                        // Raise input system Event if it enabled
                        if (Interactions[i].BoolData)
                        {
                            MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                    else
                    {
                        if (Interactions[i].BoolData)
                        {
                            MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                }
            }
        }
Example #33
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            // Close any open UI screens
            if (openUIScreen != null)
            {
                openUIScreen.gameObject.SetActive(false);
                CloseMenu();
            }
            // Open a menu
            else if (GameController.HighlightedTile != null)
            {
                // Create new building menu
                if (GameController.CanBuildOnHighlightedTile())
                {
                    pnlCreateNewBuilding.gameObject.SetActive(true);
                    openUIScreen       = pnlCreateNewBuilding;
                    controller.enabled = false;
                    CanInteract        = false;
                    Cursor.lockState   = CursorLockMode.None;
                    Cursor.visible     = true;
                    pnlGameHUD.gameObject.SetActive(false);
                }
                else if (GameController.HighlightedTileIsGenerator())
                {
                    pnlUpgradeGenerator.gameObject.SetActive(true);
                    openUIScreen       = pnlUpgradeGenerator;
                    controller.enabled = false;
                    CanInteract        = false;
                    Cursor.lockState   = CursorLockMode.None;
                    Cursor.visible     = true;
                    pnlGameHUD.gameObject.SetActive(false);
                }
                else if (GameController.CanUpgradeHighlightedTile())
                {
                    UIUpgradeBuilding.CurrentBuilding = GameController.HighlightedTile.CurrentBuilding;
                    pnlUpgradeBuilding.gameObject.SetActive(true);
                    openUIScreen       = pnlUpgradeBuilding;
                    controller.enabled = false;
                    CanInteract        = false;
                    Cursor.lockState   = CursorLockMode.None;
                    Cursor.visible     = true;
                    pnlGameHUD.gameObject.SetActive(false);
                }
            }
        }
        // Escape menu is special
        if (Input.GetKeyDown(KeyCode.Escape) && openUIScreen == null)
        {
            pnlEscapeMenu.gameObject.SetActive(true);
            openUIScreen       = pnlEscapeMenu;
            controller.enabled = false;
            CanInteract        = false;
            Cursor.lockState   = CursorLockMode.None;
            Cursor.visible     = true;
            pnlGameHUD.gameObject.SetActive(false);
        }


        // Night triggers.
        if (Input.GetKeyDown(KeyCode.K) && !GameController.IsNight)
        {
            GameController.NightTriggered();
        }
    }
Example #34
0
 /// <summary>
 /// Unity start hook.
 /// </summary>
 protected virtual void Init()
 {
     if (input == null)
     {
         Character character = (Character) FindObjectOfType(typeof(Character));
         if (character != null)
         {
             input = character.Input;
         }
         else
         {
             input = (Input) FindObjectOfType<Input>();
         }
         if (input == null) Debug.LogWarning("UIDialogType could not find input");
     }
     text = GetComponent<Text> ();
     dialogString = text.text;
     text.text = "";
     initialised = true;
 }