示例#1
0
        public static void SetState(InputState state, bool enabled)
        {
            if (!Input.States.ContainsKey(InputState.World))
            {
                Input.States.Add(InputState.World, false);
            }
            if (Input.GetState(state) == enabled)
            {
                return;
            }
            if (!Input.States.ContainsKey(state))
            {
                Input.States.Add(state, false);
            }
            Input.States[state] = enabled;
            if (!Input.GetState(InputState.World))
            {
                bool flag = false;
                foreach (KeyValuePair <InputState, bool> keyValuePair in Input.States)
                {
                    if (keyValuePair.Value)
                    {
                        flag = true;
                    }
                }
                if (!flag)
                {
                    Input.States[InputState.World] = true;
                }
            }
            string text = "Input States: ";

            foreach (KeyValuePair <InputState, bool> keyValuePair2 in Input.States)
            {
                string text2 = text;
                text = string.Concat(new object[]
                {
                    text2,
                    keyValuePair2.Key,
                    " : ",
                    keyValuePair2.Value,
                    "\n"
                });
            }
            Debug.Log(text);
            Input.ForceRefreshState();
        }
示例#2
0
        public void LoadAllMaps()
        {
            Debug.Log("Reloading Input Mapping");
            if (!ReInput.isReady)
            {
                return;
            }
            if (ReInput.players == null || ReInput.players.AllPlayers == null)
            {
                return;
            }
            IList <Player> allPlayers = ReInput.players.AllPlayers;

            for (int i = 0; i < allPlayers.Count; i++)
            {
                Player player = allPlayers[i];
                IList <InputBehavior> inputBehaviors = ReInput.mapping.GetInputBehaviors(player.id);
                for (int j = 0; j < inputBehaviors.Count; j++)
                {
                    string inputBehaviorXml = this.GetInputBehaviorXml(player, inputBehaviors[j].id);
                    if (inputBehaviorXml != null && !(inputBehaviorXml == string.Empty))
                    {
                        inputBehaviors[j].ImportXmlString(inputBehaviorXml);
                    }
                }
                List <string>         allControllerMapsXml  = this.GetAllControllerMapsXml(player, true, ControllerType.Keyboard, ReInput.controllers.Keyboard);
                List <string>         allControllerMapsXml2 = this.GetAllControllerMapsXml(player, true, ControllerType.Mouse, ReInput.controllers.Mouse);
                bool                  flag = false;
                List <List <string> > list = new List <List <string> >();
                Debug.Log("Joystick count= " + player.controllers.Joysticks.Count);
                foreach (Rewired.Joystick controller in player.controllers.Joysticks)
                {
                    List <string> allControllerMapsXml3 = this.GetAllControllerMapsXml(player, true, ControllerType.Joystick, controller);
                    list.Add(allControllerMapsXml3);
                    if (allControllerMapsXml3.Count > 0)
                    {
                        flag = true;
                    }
                }
                if (allControllerMapsXml.Count > 0)
                {
                    if (!allControllerMapsXml[0].Contains("<actionId>48</actionId>"))
                    {
                        allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>48</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>49</keyboardKeyCode></ActionElementMap></buttonMaps>");
                    }
                    if (!allControllerMapsXml[0].Contains("<actionId>49</actionId>"))
                    {
                        allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>49</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>50</keyboardKeyCode></ActionElementMap></buttonMaps>");
                    }
                    if (!allControllerMapsXml[0].Contains("<actionId>50</actionId>"))
                    {
                        allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>50</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>51</keyboardKeyCode></ActionElementMap></buttonMaps>");
                    }
                    if (!allControllerMapsXml[0].Contains("<actionId>51</actionId>"))
                    {
                        allControllerMapsXml[0] = allControllerMapsXml[0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>51</actionId><elementType>1</elementType><elementIdentifierId>-1</elementIdentifierId><keyboardKeyCode>52</keyboardKeyCode></ActionElementMap></buttonMaps>");
                    }
                }
                if (allControllerMapsXml.Count > 0)
                {
                    InputMapCategory mapCategory = ReInput.mapping.GetMapCategory(0);
                    Dictionary <int[], List <ActionElementMap> > elementSourceActionLinks;
                    Dictionary <int, ActionElementMap>           storedElementMaps;
                    InputMapping.CaptureExistingActionElementRelationships(mapCategory, player, out elementSourceActionLinks, out storedElementMaps);
                    player.controllers.maps.ClearMaps(ControllerType.Keyboard, true);
                    player.controllers.maps.AddMapsFromXml(ControllerType.Keyboard, 0, allControllerMapsXml);
                    InputMapping.UpdateActionElementRelationships(elementSourceActionLinks, storedElementMaps, mapCategory, player);
                }
                if (flag)
                {
                    player.controllers.maps.ClearMaps(ControllerType.Joystick, true);
                }
                int num = 0;
                foreach (Rewired.Joystick joystick in player.controllers.Joysticks)
                {
                    bool flag2 = joystick.name.Contains("DualShock") || joystick.GetExtension <DualShock4Extension>() != null;
                    if (list[num].Count > 0)
                    {
                        if (flag2)
                        {
                            if (!list[num][0].Contains("<actionId>48</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>48</actionId><elementType>1</elementType><elementIdentifierId>21</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>49</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>49</actionId><elementType>1</elementType><elementIdentifierId>20</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>50</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>50</actionId><elementType>1</elementType><elementIdentifierId>19</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>51</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>51</actionId><elementType>1</elementType><elementIdentifierId>18</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>53</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>53</actionId><elementType>1</elementType><elementIdentifierId>4</elementIdentifierId><axisRange>0</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>54</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>54</actionId><elementType>1</elementType><elementIdentifierId>6</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                        }
                        else
                        {
                            if (!list[num][0].Contains("<actionId>48</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>48</actionId><elementType>1</elementType><elementIdentifierId>19</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>49</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>49</actionId><elementType>1</elementType><elementIdentifierId>18</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>50</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>50</actionId><elementType>1</elementType><elementIdentifierId>17</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>51</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>0</actionCategoryId><actionId>51</actionId><elementType>1</elementType><elementIdentifierId>16</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>53</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>53</actionId><elementType>1</elementType><elementIdentifierId>4</elementIdentifierId><axisRange>0</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                            if (!list[num][0].Contains("<actionId>54</actionId>"))
                            {
                                list[num][0] = list[num][0].Replace("</buttonMaps>", "<ActionElementMap><actionCategoryId>2</actionCategoryId><actionId>54</actionId><elementType>1</elementType><elementIdentifierId>6</elementIdentifierId><axisRange>1</axisRange><axisContribution>0</axisContribution><keyboardKeyCode>0</keyboardKeyCode></ActionElementMap></buttonMaps>");
                            }
                        }
                    }
                    player.controllers.maps.AddMapsFromXml(ControllerType.Joystick, joystick.id, list[num]);
                    num++;
                }
                if (allControllerMapsXml2.Count > 0)
                {
                    player.controllers.maps.ClearMaps(ControllerType.Mouse, true);
                }
                player.controllers.maps.AddMapsFromXml(ControllerType.Mouse, 0, allControllerMapsXml2);
                if (ForestVR.Enabled)
                {
                    this.ProcessVRInputMappings(player);
                }
            }
            foreach (Rewired.Joystick joystick2 in ReInput.controllers.Joysticks)
            {
                joystick2.ImportCalibrationMapFromXmlString(this.GetJoystickCalibrationMapXml(joystick2));
            }
            Input.ForceRefreshState();
            InputMappingIcons.RefreshMappings();
        }