あなたが求めているファイルパスは、有効なファイルパスではありません。 Application.dataPath
をルートディレクトリとして使用し、ファイルを追加する前に/
で終わることを確認する必要があります。 も\
を/
(自分のコードを参照)に置き換える必要があります。
これは、寄せ集めの一種であるが、私は、ファイルIOのためのアプリケーションディレクトリを決定するために、これを使用します。
public static class Configuration {
public static string currentBaseDirectory = "";
public static string currentDirectory = "";
public static void loadCurrentDirectory()
{
currentDirectory = Application.dataPath;
currentDirectory = currentDirectory.Replace(@"\", "/");
bool hasFoundMatch = false;
if (!currentDirectory.EndsWith("/"))
currentDirectory += "/";
switch (Application.platform) {
case RuntimePlatform.OSXEditor: //<path to project folder>/Assets
case RuntimePlatform.WindowsEditor:
if(currentDirectory.EndsWith("Assets/")) {
currentDirectory = currentDirectory.Substring(0, currentDirectory.LastIndexOf("Assets/"));
currentDirectory += "RuntimeData/";
hasFoundMatch = true;
}
break;
case RuntimePlatform.WindowsPlayer: //<path to executablename_Data folder>
break;
case RuntimePlatform.OSXPlayer: //<path to player app bundle>/Contents
if(currentDirectory.EndsWith(".app/Contents/")) {
currentDirectory = currentDirectory.Substring(0, currentDirectory.LastIndexOf(".app/Contents/"));
currentDirectory += "RuntimeData/";
hasFoundMatch = true;
}
break;
case RuntimePlatform.OSXDashboardPlayer: //<path to the dashboard widget bundle>
case RuntimePlatform.WindowsWebPlayer: //not supported
case RuntimePlatform.OSXWebPlayer:
default:
hasFoundMatch = false;
break;
}
if (!hasFoundMatch) {
currentDirectory = Path.GetFullPath("RuntimeData/");
currentDirectory = currentDirectory.Replace(@"\", "/");
}
if (!Directory.Exists(currentDirectory)) {
for (int i = 0; i < 3; i++)
currentDirectory = currentDirectory.Substring(0, currentDirectory.LastIndexOf("/"));
currentDirectory += "/RuntimeData/";
}
currentBaseDirectory = currentDirectory.Replace("/RuntimeData", "");
}
}
これは私は次の私は、ファイルの保存のようなものを置くことができる資産への可能RuntimeDataディレクトリを持つことができますこのフォルダには、公開時に実行可能ファイルが添付されています(ただし、クリーンコピーが必要な場合もありますが、開発者のテスト保存は無料です)。あなたは `System.IOで文字列を組み合わせることにより、すべての「それは/を持っていない、私は/または\使用する必要があります」と、将来的にあなたの自己トラブルの多くを保存し、すべてのことができ
.Path.Combine(string、string) '' + = 'を使用する代わりに、' Path.Combine'関数はあなたのために働きます。 –
ありがとう@ScottChamberlain私は、何年か前に他の人が書いたコードで始めました。自分のニーズに合うようにいくつか手書きしました。私が知っていたのは、私が働いていたものでした。 :) – Draco18s