예제 #1
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();
        }
    }