Beispiel #1
0
        public void LoadBinds(string json)
        {
            if (mActionNames == null || mActionNames.Length == 0)
            {
                Debug.LogWarning("No action config loaded.  There will be no bindings!");
                return;
            }

            List <Bind> keys = BindList.FromJSON(json);

            if (mBinds == null || mBinds.Length == 0)
            {
                Dictionary <int, BindData> binds = new Dictionary <int, BindData>();

                foreach (Bind key in keys)
                {
                    if (key != null && key.keys != null)
                    {
                        binds.Add(key.action, new BindData(key));
                    }
                }

                //set bindings
                mBinds = new BindData[actionCount];
                foreach (KeyValuePair <int, BindData> pair in binds)
                {
                    mBinds[pair.Key] = pair.Value;
                }

                //register input actions to localizer
                for (int i = 0; i < actionCount; i++)
                {
                    Localize.instance.RegisterParam("input_" + i, OnTextParam);
                }
            }
            else
            {
                foreach (Bind key in keys)
                {
                    if (key != null && key.keys != null)
                    {
                        if (mBinds[key.action] != null)
                        {
                            BindData bindDat = mBinds[key.action];
                            bindDat.ApplyKeys(key);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Reverts bind settings to loaded configuration
        /// </summary>
        public void RevertBinds()
        {
            fastJSON.JSON.Parameters.UseExtensions = false;
            List <Bind> keys = fastJSON.JSON.ToObject <List <Bind> >(config.text);

            foreach (Bind key in keys)
            {
                if (key != null && key.keys != null)
                {
                    if (mBinds[key.action] != null)
                    {
                        BindData bindDat = mBinds[key.action];
                        bindDat.ApplyKeys(key);
                    }
                }
            }
        }