// Start is called before the first frame update
    void Start()
    {
        inputCommands   = new Dictionary <string, KeyCode>();
        inputAxis       = new Dictionary <string, string>();
        inputDirections = new Dictionary <string, char>();
        // Clear commands
        ClearCommands();

        // TODO: name check
        //var names = Input.GetJoystickNames();
        //foreach (var name in names)
        //{
        //    Debug.Log(name);
        //}

        var joypadConfigurationLines = joypadConfiguration.text.Split('\n');

        foreach (string line in joypadConfigurationLines)
        {
            var joypadConfigurationWords = line.Split('_', '=');
            if (joypadConfigurationWords.Length != 3)
            {
                continue;
            }

            var p = joypadConfigurationWords[0].Trim();
            var c = joypadConfigurationWords[1].Trim();
            var i = joypadConfigurationWords[2].Trim();
            if (p != StaticConstants.PLAYER1_ID ||
                !inputCommands.ContainsKey(c))
            {
                continue;
            }

            inputCommands[c] = StaticConstants.StringToKey(i);
            if (inputCommands[c] == KeyCode.None)
            {
                inputAxis[c]       = i.Substring(0, i.Length - 1);
                inputDirections[c] = i[i.Length - 1];
            }
        }
    }
Esempio n. 2
0
    void ReoloadCommands()
    {
        StreamReader reader = new StreamReader(path);
        var          joypadConfiguration = reader.ReadToEnd();

        reader.Close();

        foreach (string command in StaticConstants.CMD_LIST)
        {
            inputTexts[command].text = "None";
        }

        var joypadConfigurationLines = joypadConfiguration.Split('\n');

        foreach (string line in joypadConfigurationLines)
        {
            var joypadConfigurationWords = line.Split('_', '=');
            if (joypadConfigurationWords.Length != 3 ||
                joypadConfigurationWords[0] != StaticConstants.PLAYER_LIST[currentPlayer] ||
                !inputTexts.ContainsKey(joypadConfigurationWords[1]))
            {
                continue;
            }
            string key = joypadConfigurationWords[2].Trim();
            try {
                var keyCode = StaticConstants.StringToKey(key);
                if (keyCode == KeyCode.None)
                {
                    Input.GetAxis(key.Substring(0, key.Length - 1));
                }
            } catch (ArgumentException) {
                key = "None";
            }
            inputTexts[joypadConfigurationWords[1]].text = key;
        }
    }