본문 바로가기
개발/Unity

코드)Unity) 플랫폼별 로컬 파일 저장 경로

by 테샤르 2022. 9. 25.

 

플랫폼별 로컬 파일 저장 경로 및 저장

플랫폼 별로 로컬 파일 경로를 설정하는 코드이다.

간단하게 참고하면 되는데 저장되는 위치가 플랫폼별로 다르기 때문에 구분이 필요하다.

 

반응형
void LoadLocalizedText (string fileName) {
        localizedTextDictionary = new Dictionary<string, string> ();
        string dataAsJson;
 
        #if UNITY_EDITOR
        string filePath = Path.Combine (Application.streamingAssetsPath, fileName);
 
        #elif UNITY_IOS
        string filePath = Path.Combine (Application.persistentDataPath, fileName);
 
        #elif UNITY_ANDROID
        string filePath = Path.Combine (Application.persistentDataPath, fileName);
 
        #endif
 
        if (File.Exists (filePath)) {
 
            #if  UNITY_EDITOR || UNITY_IOS
            dataAsJson = File.ReadAllText (filePath);
 
            #elif UNITY_ANDROID
            WWW reader = new WWW (filePath);
            while (!reader.isDone) {
            }
            dataAsJson = reader.text;
            #endif
 
            LocalizationData loadedData = JsonUtility.FromJson<LocalizationData> (dataAsJson);
 
            for (int i = 0; i < loadedData.items.Length; i++) {
                localizedTextDictionary.Add (loadedData.items [i].key, loadedData.items [i].value);
            }
            Debug.Log ("Data loaded, dictionary contains: " + localizedTextDictionary.Count + " entries");
        } else {
            Debug.LogError ("Cannot find file!");
        }
        isReady = true;
    }

 

 

<실제 파일 경로>

플랫폼   실제 경로
UNITY_EDITOR Application.streamingAssetsPath <Project Root>/Assets/StreamingAssets
UNITY_ANDROID
Application.persistentDataPath
/* 외부 저장소 */
"/storage/emulated/0/Android/data/<packagename>/files"

/* 내부 저장소 */
"/data/data/<packagename>/files"


UNITY_IOS Application.persistentDataPath /var/mobile/Containers/Data/Application/<guid>/

 

Unity Application.streamingAssetsPath : [링크]

Unity Application.perststentDataPath : [링크]

 

Unity - Scripting API: Application.persistentDataPath

This value is a directory path where you can store data that you want to be kept between runs. When you publish on iOS and Android, persistentDataPath points to a public directory on the device. Files in this location are not erased by app updates. The fil

docs.unity3d.com

 

 

★☆☆☆☆

 

반응형

댓글