43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
namespace Ironspore
|
|
{
|
|
public static class GameDataPaths
|
|
{
|
|
public static string DirectoryPath
|
|
{
|
|
get
|
|
{
|
|
string isolated = CommandLineDirectory();
|
|
if (isolated != null)
|
|
return isolated;
|
|
#if UNITY_EDITOR
|
|
return Path.GetFullPath(Path.Combine(Application.dataPath, "../UserSettings/Ironspore"));
|
|
#else
|
|
return Path.Combine(Application.persistentDataPath, "Ironspore");
|
|
#endif
|
|
}
|
|
}
|
|
|
|
public static string PreferenceKey(string key)
|
|
{
|
|
string isolated = CommandLineDirectory();
|
|
#if UNITY_EDITOR
|
|
isolated = isolated ?? DirectoryPath;
|
|
#endif
|
|
return isolated == null ? key : "ironspore." + Hash128.Compute(isolated.ToLowerInvariant()) + "." + key;
|
|
}
|
|
|
|
static string CommandLineDirectory()
|
|
{
|
|
string[] args = Environment.GetCommandLineArgs();
|
|
for (int i = 0; i + 1 < args.Length; i++)
|
|
if (args[i] == "-ironspore-data-path" && Path.IsPathRooted(args[i + 1]))
|
|
return Path.GetFullPath(args[i + 1]);
|
|
return null;
|
|
}
|
|
}
|
|
}
|