예제 #1
0
	// Use this for initialization
	void Start ()
	{
	    eventSystem = FindObjectOfType<EventSystem>();
	    rewiredEventSystem = FindObjectOfType<RewiredStandaloneInputModule>();
	    controller = Rewired.ReInput.players.GetPlayer(controllerNumber);

	    GetComponentInChildren<Text>().text = (controllerNumber+1).ToString();
	}
예제 #2
0
        private void ProcessMouseEvent()
        {
            PointerInputModule.MouseState mousePointerEventData = this.GetMousePointerEventData(-1);
            bool pressed  = mousePointerEventData.AnyPressesThisFrame();
            bool released = mousePointerEventData.AnyReleasesThisFrame();

            PointerInputModule.MouseButtonEventData eventData = mousePointerEventData.GetButtonState(PointerEventData.InputButton.Left).eventData;
            if (!RewiredStandaloneInputModule.UseMouse(pressed, released, eventData.buttonData))
            {
                return;
            }
            this.ProcessMousePress(eventData);
            this.ProcessMove(eventData.buttonData);
            this.ProcessDrag(eventData.buttonData);
            this.ProcessMousePress(mousePointerEventData.GetButtonState(PointerEventData.InputButton.Right).eventData);
            this.ProcessDrag(mousePointerEventData.GetButtonState(PointerEventData.InputButton.Right).eventData.buttonData);
            this.ProcessMousePress(mousePointerEventData.GetButtonState(PointerEventData.InputButton.Middle).eventData);
            this.ProcessDrag(mousePointerEventData.GetButtonState(PointerEventData.InputButton.Middle).eventData.buttonData);
            if (!Mathf.Approximately(eventData.buttonData.scrollDelta.sqrMagnitude, 0f))
            {
                GameObject eventHandler = ExecuteEvents.GetEventHandler <IScrollHandler>(eventData.buttonData.pointerCurrentRaycast.gameObject);
                ExecuteEvents.ExecuteHierarchy <IScrollHandler>(eventHandler, eventData.buttonData, ExecuteEvents.scrollHandler);
            }
        }
        public void SetJoystick(int playerId, Joystick joystick) {
            if(!initialized) return;

            this.playerId = playerId;
            this.joystick = joystick;

            if(joystick == null) {
                Debug.LogError("Rewired Control Mapper: Joystick cannot be null!");
                return;
            }

            // Create axis list
            float buttonHeight = 0.0f;
            for(int i = 0; i < joystick.axisCount; i++) {
                int index = i;
                GameObject instance = UITools.InstantiateGUIObject<Button>(axisButtonPrefab, axisScrollAreaContent, "Axis" + i);
                Button button = instance.GetComponent<Button>();
                button.onClick.AddListener(() => { OnAxisSelected(index, button); });
                Text text = UnityTools.GetComponentInSelfOrChildren<Text>(instance);
                if(text != null) text.text = joystick.AxisElementIdentifiers[i].name;
                if(buttonHeight == 0.0f) buttonHeight = UnityTools.GetComponentInSelfOrChildren<LayoutElement>(instance).minHeight;
                axisButtons.Add(button);
            }

            // set axis list height
            float vSpacing = axisScrollAreaContent.GetComponent<VerticalLayoutGroup>().spacing;
            axisScrollAreaContent.sizeDelta = new Vector2(axisScrollAreaContent.sizeDelta.x, Mathf.Max((joystick.axisCount * (buttonHeight + vSpacing) - vSpacing), axisScrollAreaContent.sizeDelta.y));

            // Store the original calibration data so we can revert
            origCalibrationData = joystick.calibrationMap.ToXmlString();

            // Record info
            displayAreaWidth = rightContentContainer.sizeDelta.x;

            // Try to get the UI control axis deadzone from the RewiredStandaloneInputModule if it exists in the hierarchy
            // This is used to prevent users from rendering menu navigation axes unusable by changing the axis sensitivity
            rewiredStandaloneInputModule = gameObject.transform.root.GetComponentInChildren<RewiredStandaloneInputModule>();
            if(rewiredStandaloneInputModule != null) {
                menuHorizActionId = ReInput.mapping.GetActionId(rewiredStandaloneInputModule.horizontalAxis);
                menuVertActionId = ReInput.mapping.GetActionId(rewiredStandaloneInputModule.verticalAxis);
            }

            // Select first axis
            if(joystick.axisCount > 0) {
                SelectAxis(0);
            }

            // Set default UI element
            defaultUIElement = doneButton.gameObject;

            // Draw window
            RefreshControls();
            Redraw();
        }