Пример #1
0
 private static bool AnyInput(ControlScheme scheme, int playerID)
 {
     if (scheme != null)
     {
         return(scheme.AnyInput(playerID));
     }
     return(false);
 }
Пример #2
0
 static InputAction GetAction(int playerID, int actionKey, out ControlScheme playerUsesScheme)
 {
     playerUsesScheme = playerSchemes[playerID];
     if (playerUsesScheme == null)
     {
         return(null);
     }
     return(playerUsesScheme.GetAction(actionKey));
 }
        ControlScheme ReadControlScheme(XmlNode controlSchemeNode)
        {
            ControlScheme scheme = new ControlScheme(XMLTools.ReadAttribute(controlSchemeNode, "name", "Unnamed Control Scheme"));

            foreach (XmlNode inputActionNode in XMLTools.SelectSubNodesByName(controlSchemeNode, "Action"))
            {
                ReadInputAction(scheme, inputActionNode);
            }
            return(scheme);
        }
        void ReadInputAction(ControlScheme scheme, XmlNode inputActionNode)
        {
            string      name   = XMLTools.ReadAttribute(inputActionNode, "name", "Unnamed Action");
            InputAction action = scheme.CreateNewAction(name, XMLTools.ReadAttribute(inputActionNode, "displayName", name));

            foreach (XmlNode inputBindingNode in XMLTools.SelectSubNodesByName(inputActionNode, "Binding"))
            {
                ReadInputBinding(action, inputBindingNode);
            }
        }
Пример #5
0
        public static ControlScheme GetControlScheme(string name)
        {
            ControlScheme scheme = null;

            if (m_instance.m_schemeLookup.TryGetValue(name, out scheme))
            {
                return(scheme);
            }

            return(null);
        }
Пример #6
0
        private void WriteControlScheme(ControlScheme scheme, XmlWriter writer)
        {
            writer.WriteStartElement("ControlScheme");
            writer.WriteAttributeString("name", scheme.Name);
            // writer.WriteAttributeString("id", scheme.UniqueID);
            foreach (var action in scheme.Actions)
            {
                WriteInputAction(action, writer);
            }

            writer.WriteEndElement();
        }
 void WriteControlScheme(ControlScheme scheme, XmlWriter writer)
 {
     XMLTools.WriteSection(
         "ControlScheme", writer,
         (w) => { foreach (var action in scheme.Actions)
                  {
                      WriteInputAction(action, writer);
                  }
         },
         new string[] { "name" }, new string[] { scheme.Name }
         );
 }
Пример #8
0
        public static bool DeleteAction(string controlSchemeName, string actionName)
        {
            ControlScheme scheme = GetControlScheme(controlSchemeName);
            InputAction   action = GetAction(controlSchemeName, actionName);

            if (scheme != null && action != null)
            {
                m_instance.m_actionLookup[scheme.Name].Remove(action.Name);
                scheme.DeleteAction(action);
                return(true);
            }
            return(false);
        }
        private void ReadInputAction_V2(ControlScheme scheme, XmlNode node)
        {
            string name        = ReadAttribute(node, "name", "Unnamed Action");
            string displayName = ReadAttribute(node, "displayName", name);

            InputAction action       = scheme.CreateNewAction(name, displayName);      //, rebindable);
            var         bindingNodes = SelectNodes(node, "Binding");

            foreach (XmlNode child in bindingNodes)
            {
                ReadInputBinding_V2(action, child);
            }
        }
Пример #10
0
        public static ControlScheme Duplicate(string name, ControlScheme source)
        {
            ControlScheme duplicate = new ControlScheme();

            duplicate.m_name     = name;
            duplicate.m_uniqueID = GenerateUniqueID();
            duplicate.m_actions  = new List <InputAction>();
            foreach (var action in source.m_actions)
            {
                duplicate.m_actions.Add(InputAction.Duplicate(action));
            }
            return(duplicate);
        }
        private ControlScheme ReadControlScheme_V2(XmlNode node)
        {
            string        name   = ReadAttribute(node, "name", "Unnamed Control Scheme");
            string        id     = ReadAttribute(node, "id", null);
            ControlScheme scheme = new ControlScheme(name);
            // scheme.UniqueID = id ?? ControlScheme.GenerateUniqueID();

            var actionNodes = SelectNodes(node, "Action");

            foreach (XmlNode child in actionNodes)
            {
                ReadInputAction_V2(scheme, child);
            }
            return(scheme);
        }
Пример #12
0
        public static ControlScheme CreateControlScheme(string name)
        {
            if (m_instance.m_schemeLookup.ContainsKey(name))
            {
                Debug.LogError(string.Format("A control scheme named \'{0}\' already exists", name));
                return(null);
            }

            ControlScheme scheme = new ControlScheme(name);

            m_instance.m_controlSchemes.Add(scheme);
            m_instance.m_schemeLookup[name] = scheme;
            m_instance.m_actionLookup[name] = new Dictionary <string, InputAction>();

            return(scheme);
        }
Пример #13
0
        protected override void Awake()
        {
            base.Awake();

            m_schemeLookup = new Dictionary <string, ControlScheme>();
            playerSchemes  = new ControlScheme[numPlayers];
            ScanService.OnAwake();
            GamepadHandler.OnAwake();

            // try and load custom runtime bindings
            if (!LoadCustomSchemes())
            {
                Debug.Log("Couldnt find custom control bindings, loading defaults...");
                LoadDefaultSchemes();
            }
        }
        private ControlScheme Load_V2(XmlDocument doc, string schemeName)
        {
            if (string.IsNullOrEmpty(schemeName))
            {
                return(null);
            }

            ControlScheme scheme      = null;
            var           schemeNodes = SelectNodes(doc.DocumentElement, "ControlScheme");

            foreach (XmlNode node in schemeNodes)
            {
                if (ReadAttribute(node, "name") == schemeName)
                {
                    scheme = ReadControlScheme_V2(node);
                    break;
                }
            }

            return(scheme);
        }
Пример #15
0
        /// <summary>
        /// Deletes the specified control scheme. If the speficied control scheme is
        /// active for any player then the active control scheme for the respective player will be set to null.
        /// </summary>
        public static bool DeleteControlScheme(string name)
        {
            ControlScheme scheme = GetControlScheme(name);

            if (scheme == null)
            {
                return(false);
            }

            m_instance.m_actionLookup.Remove(name);
            m_instance.m_schemeLookup.Remove(name);
            m_instance.m_controlSchemes.Remove(scheme);

            for (int i = 0; i < maxPlayers; i++)
            {
                if (m_instance.playerSchemes[i].Name == scheme.Name)
                {
                    m_instance.playerSchemes[i] = null;
                }
            }

            return(true);
        }
Пример #16
0
 public static ControlScheme Duplicate(ControlScheme source)
 {
     return(Duplicate(source.Name, source));
 }