2016-10-06 7 views
1

UnityゲームのためにiOSデバイスにローカルにデータを保存する必要があります。ユニティ提供Directory.createDirectoryは、iOSのディレクトリの代わりにファイルを作成します。

Application.persistentDataPath 

パブリックディレクトリを取得してデータを保存する。これをコンソールに表示すると、iOSで返されたパスが正しいことがわかります。/ Users/userName/Library/Developer/CoreSimulator/Devices/******** - **** - **** - *** * - ************/data/Containers/Data/Application/******** - **** - **** - **** - *** *********/Documents/

ディレクトリが存在するかどうかを調べるには、パスを返します。存在しない場合は、ディレクトリを作成する必要がありますが、拡張子なしでFILEを作成します。

:ここに私のコード

void savePose(Pose pose){ 

     if (!Directory.Exists(PoseManager.poseDirectoryPath())){ 
      Directory.CreateDirectory(PoseManager.poseDirectoryPath()); 
      //Above line creates a file 
      //by the name of "SavedPoses" without any extension 
     } 
     // rest of the code goes here 
    } 

    static string poseDirectoryPath() { 
     return Path.Combine(Application.persistentDataPath,"SavedPoses"); 
    } 

答えて

1

可能sloutionsです。 Path.Combine(Application.persistentDataPath,"SavedPoses");savedPosesの前にスラッシュを追加し、スラッシュはスラッシュです。おそらく、これが原因でiOSに問題が発生する可能性があります。 Path.Combine機能を使用せずに連結した生の文字列を試してください。 Directoryクラス.IF

static string poseDirectoryPath() { 
    return Application.persistentDataPath + "/" + "SavedPoses"; 
} 

正常に動作し、DirectoryInfoクラスを使用していません。

private void savePose(Pose pose) 
{ 
    DirectoryInfo posePath = new DirectoryInfo(PoseManager.poseDirectoryPath()); 

    if (!posePath.Exists) 
    { 
     posePath.Create(); 
     Debug.Log("Directory created!"); 
    } 
} 

static string poseDirectoryPath() 
{ 
    return Path.Combine(Application.persistentDataPath, "SavedPoses"); 
} 

EDIT

そうなiOSのアクセス許可の問題。

StreamingAssetsディレクトリにフォルダを作成することができます。このディレクトリに読み書きする権限があります。

これにアクセスする一般的な方法は、Application.streamingAssetsPath/です。

iOSでは、Application.dataPath + "/Raw"でアクセスすることもできます。

Androidでは、"jar:file://" + Application.dataPath + "!/assets/";、WindowsとMacの場合はApplication.dataPath + "/StreamingAssets";でアクセスすることもできます。ただあなたのために働くものを使用してください。

ご質問の場合は、Application.dataPath + "/Raw"+"/SavedPoses";とする必要があります。

+0

** 1 **これは私のオリジナルコードで、他の質問を確認した後に変更されました。そして、私は、生成されたパスが両方の場合(生の文字列とPath.Combine)のスラッシュで正しかったと述べたので、これも同じ問題を生成します。 – ibnetariq

+0

これはUnityバージョンとは何ですか?これをテストしているiOSバージョンは何ですか? – Programmer

+0

ユニティ= 5.4.1f1、Xcode = 7.3.1、シミュレータ= iPhone 5S、iOS = 9.3。デバイスにも同じ問題が発生します。私はシミュレータを使用しているので、Finderからドキュメントディレクトリを見ることができます – ibnetariq

関連する問題