Reputation: 13
How do i load a file (json in this case) in the same directory as the .dll file that uses it?
Programfolder/Plugins
In my case, the executable is in Programfolder and the dll and json in /plugins.
I tried this:
[System.Serializable]
public class KeyCodes
{
public string RandomizeAllKey;
public string RandomizeFaceKey;
public string RandomizeBodyKey;
public string RandomizeFaceBodyKey;
public string RandomizeClothesKey;
}
string configFilename = "Randomizer.json";
var configPath = $"{UserData.Path}..\\Plugins\\{configFilename}";
var keys = JsonUtility.FromJson<KeyCodes>(System.IO.File.ReadAllText(configPath));
but it doesn't seem to work.
Upvotes: 1
Views: 1052
Reputation: 3038
To find the path where your dll is running, use this:
// GetExecutingAssembly finds the path where THIS code is running
var dllPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string configFilename = "Randomizer.json";
var configPath = Path.Combine(dllPath, configFilename);
Upvotes: 1