Exemple #1
0
    ///Loads controls from the config file to ControlList.
    public void LoadControls(string filePath)
    {
        string[] keys = File.ReadAllLines(filePath);
        controlList.Reset();
        foreach (string key in keys)
        {
            if (key.Length > 0 && !key.Contains("#"))
            {
                if (key.Contains("AXIS"))
                {
                    axisList.AddAxis(key);
                }
                else
                {
                    controlList.AddKeybind(key);
                }
            }
        }

        // Debug.Log(controlList);
    }
Exemple #2
0
    public ConfigFileIO()
    {
        axisList     = new AxisList(controlList);
        configPath   = Application.dataPath + "/CustomInputManager/Config/controls.cfg";
        defaultsPath = Application.dataPath + "/CustomInputManager/Config/defaultcontrols.cfg";

        if (!Directory.Exists(Application.dataPath + "/CustomInputManager/Config"))
        {
            Debug.Log("Creating Config folder...");
            AssetDatabase.CreateFolder("Assets/CustomInputManager", "Config");
        }

        //validate controls file
        try {
            LoadControls(configPath);
            Debug.Log("Successfully loaded controls file");
        } catch {
            Debug.Log("Controls file is nonexistent or corrupted. Generating new one...");
            if (File.Exists(defaultsPath))
            {
                LoadControls(defaultsPath);
                Debug.Log("Loaded controls from defaultcontrols.cfg");
            }
            else
            {
                Debug.Log("Default Controls are nonexistent or corrupted. Generating new one...");
                ///Default sample config
                controlList.AddKeybind("SampleKey", "Space", "A");
                controlList.AddKeybind("SampleKeyTwo", "W", "X");
                axisList.AddAxis("SampleAxis", "SampleKey", "SampleKeyTwo", "LeftStickX");
                WriteControls(defaultsPath);
            }

            ResetControls();
        }
    }