상세 컨텐츠

본문 제목

[Unity] 유니티 streamingAssetsPath , UnityWebRequest(...)파일 복사시 유의점 관련(아이폰IOS)

게임엔진관련/유니티 엔진

by AlrepondTech 2020. 1. 14. 01:56

본문

반응형

 

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

 

 

 

예제로보는 CTest 클래스이다. 

기존의 유니티에서 streamingAssetsPath 에서 UnityWebRequest 로 파일을 읽어들이고 로컬에 저장할때 다른 플랫폼은

잘되지만 IOS에서 읽어들이지 못하는 경우가 있다 그런경우 UnityWebRequest 에서 Path를 설정하여 넣을때 "file://"

구문을 path 앞부분에 넣어주어야 한다. 아래 클래스의 함수 DownloadFile(..)를 보고 참고하면 된다.

(유니티 버전 업그레이드가 되면 또 다를수가 있으니 유의하자)

 

class CTest

{

    public void TestCode() 
    {

        string DATZIP_PATH   = Application.streamingAssetsPath + "/"+ "Test1"+ "/";

        string DAT_PATHTMP  = Application.persistentDataPath + "/"+  "Test1"+ "/tmp/";

        string zipDatFilePath    = DATZIP_PATH + "file.zip";
        string cpzipDatFilePath = DAT_PATHTMP + "file.zip"; 

     

        StartCoroutine(DownloadFile(zipDatFilePath, cpzipDatFilePath,
           (object obj) =>
           {
           
           }));

    }

  

    public static IEnumerator DownloadFile(string filePath, string savePath, DGEventHandler fEvt = null) 
    { 
        //-------------------------------------
        //{IOS Path Add "file://" 

#if UNITY_IOS //IOS 인경우"file://"이 들어가야 읽어줄수 있다. 
        filePath = "file://"+filePath; 
#endif 
        //} 
        //-----------------------------------
        
        UnityWebRequest uwr = new UnityWebRequest(filePath); 
         
        uwr.downloadHandler = new DownloadHandlerFile(savePath); 
        yield return uwr.SendWebRequest(); 

        if (fEvt != null) 
        { 
            fEvt(null); 
        } 
    }

 

}

 

 

 

=================================

=================================

=================================

 

 

 

 

반응형


관련글 더보기

댓글 영역