Beispiel #1
0
 public void ReplaceKeyBind(VirtualKey key, KeyProperty val)
 {
     if (_map.ContainsKey(key))
     {
         _map[key].Clear();
         _map[key].Add(val);
     }
 }
Beispiel #2
0
 public void AddKeyBind(VirtualKey key, KeyProperty val)
 {
     if (!_map.ContainsKey(key))
     {
         List <KeyProperty> newList = new List <KeyProperty>();
         _map[key] = newList;
     }
     _map[key].Add(val);
 }
Beispiel #3
0
 public void SetKeyBind(VirtualKey key, KeyProperty val)
 {
     if (_map.ContainsKey(key))
     {
         ReplaceKeyBind(key, val);
     }
     else
     {
         AddKeyBind(key, val);
     }
 }
Beispiel #4
0
        public static KeyMap JsonToKeyMap(string jsonString)
        {
            //Debug.Log(jsonString);
            JSONNode config = JSON.Parse(jsonString);

            KeyMap deviceMap = new KeyMap();

            //iterate through all virtualkeys
            foreach (string virtualKeyName in config.AsObject.Keys)
            {
                IEnumerable <JSONNode> hardKeys = config[virtualKeyName].Children;

                VirtualKey vKey = VirtualKey.NONE;
                try {
                    vKey = (VirtualKey)Enum.Parse(typeof(VirtualKey), virtualKeyName);
                }
                catch (ArgumentException) { return(null); }

                //iterate all hardkeys assigned to a virtual key
                foreach (JSONNode hardKey in hardKeys)
                {
                    string keyName     = hardKey["KeyName"].Value;
                    bool   isAxis      = hardKey["IsAxis"] != null ? hardKey["IsAxis"].AsBool : false;
                    bool   invert      = hardKey["Inverted"] != null ? hardKey["Inverted"].AsBool : false;
                    string condValue   = hardKey["KeyTriggerCondition"];
                    string orientValue = hardKey["AxisOrientation"];

                    KeyTriggerCondition condition = KeyTriggerCondition.NON_ZERO;
                    if (condValue != null)
                    {
                        try {
                            condition = (KeyTriggerCondition)Enum.Parse(typeof(KeyTriggerCondition), condValue);
                        }
                        catch (ArgumentException) {}
                    }

                    AxisOrientation orientation = AxisOrientation.NONE;
                    if (orientValue != null)
                    {
                        try {
                            orientation = (AxisOrientation)Enum.Parse(typeof(AxisOrientation), orientValue);
                        }
                        catch (ArgumentException) {}
                    }

                    KeyProperty property = new KeyProperty(keyName, isAxis, invert, condition, orientation);
                    deviceMap.AddKeyBind(vKey, property);
                }
            }
            return(deviceMap);
        }