sdf
public static string streamingAssetsPath;
Description
Contains the path to the StreamingAssets folder (Read Only).
If you have a "StreamingAssets" folder in the Assets folder of your project, it will be copied to your player builds and be present in the path given by Application.streamingAssetsPath.
Note that on some platforms it is not possible to directly access the StreamingAssets folder because there is no file system access in the web platforms, and because it is compressed into the .apk file on Android. On those platforms, a url will be returned, which can be used using the UnityWebRequest class.
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "MyFile"); public string result = ""; IEnumerator Example() { if (filePath.Contains("://")) { Networking.UnityWebRequest www = Networking.UnityWebRequest.Get(filePath); yield return www.SendWebRequest(); result = www.downloadHandler.text; } else result = System.IO.File.ReadAllText(filePath); } }
ref :
http://answers.unity3d.com/questions/1308831/reading-file-from-streamingassets-android.html
https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html
반응형
'게임엔진(GameEngine) > Unity3D' 카테고리의 다른 글
How to get multiple files with different extension? C# unity (0) | 2017.10.12 |
---|---|
Does DirectoryInfo GetFiles work on Android? => Don't but! (0) | 2017.10.11 |
이미지 로딩 WWW 과 ReadAllBytes 의 성능차이 (0) | 2017.10.09 |
Texture2D를 Sprite로 변경 <SpriteRenderer> (0) | 2017.10.09 |
ScriptableObject [시리얼라이즈] (0) | 2017.10.03 |
That's true. But persistantDataPath is for saving some data after the build and reading it afterwards. What I want to do is to save information about game levels themselves, not the player progress in them. This means that I have to have pre-written info files that I have to be able to read when I want to load level. Even if I manage to copy level files into persistantDataPath, somehow, it is located on SD-card (is it?) and if user has no such card (inserted or card slot at all) the game gonna break... That's what I don't want. I have no idea how to store level info in other way.. To create hundreds of similar scenes is not what I would want to do..
Ah sorry I missread part of the initial question. But now that I have more of an idea of what you are trying, is there any specific reason that these level files you're saving at edit time need to be in streaming assets? could they not be in resources instead? and then loaded via Resources.Load instead of manually reading the files yourself?
StreamingAssets is a folder that keeps files in it in the form they were created. Not compressed, not converted into some other format etc. So I can access any file by its name. Can I do same thing with Resources folder? I know how to do it with sprites etc, but have no idea what to do with byte file.