Unity Path Related

Source: Internet
Author: User

Original address: http://blog.csdn.net/linxinfa/article/details/51679528

Ios:
Application.datapath:application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/data
Application.streamingassetspath:application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/data/raw
Application.persistentdatapath:application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/documents
Application.temporarycachepath:application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/library/caches

Android:
Application.datapath:/data/app/xxx.xxx.xxx.apk
Application.streamingassetspath:jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
Application.persistentdatapath:/data/data/xxx.xxx.xxx/files
Application.temporarycachepath:/data/data/xxx.xxx.xxx/cache

Windows:
Application.datapath:/assets
Application.streamingassetspath:/assets/streamingassets
Application.persistentdatapath:c:/users/xxxx/appdata/locallow/companyname/productname
Application.temporarycachepath:c:/users/xxxx/appdata/local/temp/companyname/productname

Mac:
Application.datapath:/assets
Application.streamingassetspath:/assets/streamingassets
Application.persistentdatapath:/users/xxxx/library/caches/companyname/product Name
Application.temporarycachepath:/var/folders/57/6b4_9w8113x2fsmzx_yhrhvh0000gn/t/companyname/product Name


Windows Web Player:
Application.datapath:file:///d:/mygame/webplayer (that is, the folder where the package is saved, the folder where the HTML file is located)
Application.streamingassetspath:
Application.persistentdatapath:
Application.temporarycachepath:

--------------------------------------------------------------------------------------------------------------- ---------------

1.Resources folder

The resources folder is a read-only folder that reads objects through Resources.load (). Because all of the resources under this folder can be loaded at runtime, everything under the Resources folder will be unconditionally hit in the release package. It is recommended that only prefab or some object objects be placed under this folder, because prefab will automatically filter out unwanted resources on the object. For example, I put the model file and the map file in the Resources folder, but I have two stickers that are not used on the model, then these two useless stickers will be packaged in the release package. If I use prefab here, then prefab will automatically filter the two unused stickers, so the release package will be smaller.

2.StreamingAssets

The Streamingassets folder is also a read-only folder, but it is a bit different from the resources folder, which is compressed and encrypted, without the use of the point special method is not able to get the original resources. But the Streamingassets folder is not the same, all the resources below it will not be encrypted, and then packaged into the release package intact, so it is easy to get the files inside. So streamingassets is suitable for putting some binary files, and the resources are more suitable for putting some gameobject and object files. Streamingassets can only use the WWW class to read!!

--------------------------------------------------------------------------------------------------------------- ---------------

Streamingassets, on different platforms (Windows, Ios, Android), the directory is eventually published in different locations, so the method of reading is also different.


WWW is asynchronous loading so the Execute load command cannot directly perform read parsing operations, wait for www www = new www (filePath); yield return www; while (!www.isdone) {}result = Www.text;

Android does not support C # IO streaming to read files under Streamingassets because the files under Streamingassets in the Android phone are contained in the compressed. jar file (which is basically the same format as the standard ZIP archive). This means that if you do not use the WWW class in unity to retrieve files, then you need to use additional software to view the archive of the. jar and get the file. --------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------Android is not the same as other platforms, After installation, these files are actually in a jar compression package, so you can not directly read the function of the file read, but to use the WWW mode. The following are the specific practices:
1. Place the file you want to read under the Assets/streamingassets folder of the Unity project and build one without the folder.
2. Read the code (assuming the name "file. txt")
[CSharp]View PlainCopy
  1. Byte[] inbytes; //used to store read-in Data
  2. if (Application.platform = = runtimeplatform.android) //Determine if the current program is running under Android
  3. {
  4. string FileName = "jar:file://" + Application.datapath + "!/assets/" + "file. txt";
  5.         www www =  new www (FileName);                                                               // WWW will automatically start to read the file    
  6.         while (!www.isdone) {}                                                                            //www is asynchronous read, so use loops to wait for    
  7. Inbytes = www.bytes; //Save in byte array
  8. }
  9. Else
  10. {
  11. //Read code for other platforms
  12. }
--------------------------------------------------------------------------------------------------------------- ---------------
Add: Each directory permission:

Root directory: Streamingassets folder

#if Unity_editor
String filepath = Application.datapath + "/streamingassets" + "/my.xml";
#elif Unity_iphone
String filepath = Application.datapath + "/raw" + "/my.xml";
#elif unity_android
string filepath = "jar:file://" + Application.datapath + "!/assets/" + "/my.xml;
#endif

Root directory: Resources folder

can use Resources.load ("name"); Load the objects in the folder

Root directory: Application.datapath folder

You can use Application.datapath for read operations

Application.datapath: Only readable and non-writable, placing some resource data

Application.persistentdatapath

Both iOS and Android platforms can use this directory for read and write operations, and can store various configuration files for modification.

The address on the PC is: C:\Users\ user name \appdata\locallow\defaultcompany\test

--------------------------------------------------------------------------------------------------------------- ---------------

Summarize:
Create the Resources folder in the project root directory to save the file.
You can use Resources.load ("file name, note: Do not include the file suffix name"), and load the objects in the folder.
Note: This party can implement the file implementation of "Delete and modify" operations, but after packaging can not be changed.

Two. Save the file directly on the project root path
Use Application.datapath directly to read the file.
Note: The mobile side is not access rights.

Three. Create the Streamingassets folder in the project root directory to save the file.
1. You can use the Application.datapath to read the file for operation.

[CSharp]View PlainCopy
    1. #if  unity_editor  
    2. string filepath = application.datapath + "/streamingassets" +
    3. #elif  unity_iphone  
    4.  string filepath = application.datapath + "/raw" +
    5. #elif  unity_android  
    6.  string filepath =  "!/assets/" + "/MY.XML;  
    7. #endif   


2. Use Application.streamingassetspath directly to read the file.
Note: This method can be implemented in the PC/MAC computer to implement the "adding and removing changes" and other operations, but on the mobile side only support read operations.

Four. Using Application.persistentdatapath to manipulate files (recommended)
The file exists in the phone sandbox because the file cannot be stored directly,
1. Save to this location by direct download from the server, or update the new resource via MD5 code download
2. Without the server, only indirectly through the file stream from the local read and write to the Application.persistentdatapath file, and then through the Application.persistentdatapath to read the operation.
Note: in Pc/mac pc and Android and ipad, Ipone can do any of the files, in addition to iOS on the contents of this directory can be automatically backed up by icloud.

Unity Path Related

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.