Exemplo n.º 1
0
        private void OnConflictFound(InputMapper.ConflictFoundEventData data)
        {
            conflictData = data;

            if (data.isProtected)
            {
                conflictData.responseCallback(InputMapper.ConflictResponse.Cancel);
            }
            else
            {
                conflictResolveButtons.SetActive(true);
            }
        }
Exemplo n.º 2
0
 // Token: 0x06001852 RID: 6226 RVA: 0x00073E78 File Offset: 0x00072078
 private void InputMapperOnConflictFoundEvent(InputMapper.ConflictFoundEventData conflictFoundEventData)
 {
     Debug.Log("InputMapperOnConflictFoundEvent");
     InputMapper.ConflictResponse obj;
     if (conflictFoundEventData.conflicts.Any((ElementAssignmentConflictInfo elementAssignmentConflictInfo) => InputMapperHelper.forbiddenElements.Contains(elementAssignmentConflictInfo.elementIdentifier.name)))
     {
         obj = InputMapper.ConflictResponse.Ignore;
     }
     else
     {
         obj = InputMapper.ConflictResponse.Add;
     }
     conflictFoundEventData.responseCallback(obj);
 }
Exemplo n.º 3
0
        protected override void Awake()
        {
            base.Awake();

            ReInput.userDataStore.Load();
            playerInput = ReInput.players.GetPlayer(0);

            restoreDefaultButton.onClick.AddListener(() => {
                PlayerPrefs.DeleteAll();
                ReInput.userDataStore.Load();

                GameObject inputManager = GameObject.Find("Rewired Input Manager");
                inputManager.SetActive(false);
                inputManager.SetActive(true);

                LoadButtonList();
                // Close();
            });

            yesButton.onClick.AddListener(() => {
                SaveChange();
                Close();
                yesHandle?.Invoke();
            });

            noButton.onClick.AddListener(() => {
                ReInput.userDataStore.Load();
                Close();
            });

            // ---- Step 1 ----
            // InputMapper 是核心,用于监听改键事件
            mapper = new InputMapper();
            mapper.ConflictFoundEvent += data => {
                conflictFoundEventData = data;
                bool isConflict = false;

                ControllerMap map = handleKeybinding.map;

                // 外置键盘 / 笔记本内置键盘冲突
                if (map.controllerType == ControllerType.Keyboard || map.controllerType == ControllerType.Custom)
                {
                    foreach (ActionElementMap action in map.AllMaps)
                    {
                        if (action.keyCode == data.assignment.keyCode)
                        {
                            // print("键盘内部发生冲突,不变");
                            isConflict = true;
                            break;
                        }
                    }

                    // 手柄冲突
                }
                else if (map.controllerType == ControllerType.Joystick)
                {
                    foreach (ActionElementMap action in map.AllMaps)
                    {
                        if (action.controllerMap.categoryId == data.assignment.action.categoryId)
                        {
                            if (action.elementIdentifierId == data.assignment.elementIdentifier.id)
                            {
                                // print("手柄内部发生冲突,不变");
                                isConflict = true;
                                break;
                            }
                        }
                    }

                    // 笔记本键盘冲突
                }
                else
                {
                }

                if (!isConflict)
                {
                    // print("外部发生冲突,添加");
                    data.responseCallback(InputMapper.ConflictResponse.Add);
                }
                handleKeybinding = null;

                LoadButtonList();
            };
            mapper.InputMappedEvent += inputEventData => { // 改键完成时,触发 InputMappedEvent
                LoadButtonList();
            };
            mapper.TimedOutEvent += timoutData => {
                handleKeybinding.RenderKey();
            };
            mapper.StoppedEvent += stopEventData => {
                handleKeybinding = null;
                uiInput.controllers.maps.SetMapsEnabled(true, "UI");
            };
            mapper.options.timeout          = 10f; // 设置监听总时长,超过之后就会触发 TimeoutEvent
            mapper.options.ignoreMouseXAxis = true;
            mapper.options.ignoreMouseYAxis = true;
        }