Application类的静态属性和静态方法:
静态属性(Static Variables)
静态属性 | 英文解释 | 中文说明 |
---|---|---|
string dataPath | Contains the path to the game data folder (Read Only). | 游戏数据路径 |
string persistentDataPath | Contains the path to a persistent data directory (Read Only). | 持久化数据路径。 |
string streamingAssetsPath | Contains the path to the StreamingAssets folder (Read Only). | 流数据缓存目录。 |
string temporaryCachePath | Contains the path to a temporary data / cache directory (Read Only). | 零时缓存目录。 |
int levelCount | The total number of levels available (Read Only). | 场景的总数。 |
int loadedLevel | The level index that was last loaded (Read Only). | 当前加载的场景序号 |
int loadedLevelName | The name of the level that was last loaded (Read Only). | 当前加载的场景名称。 |
bool isLoadingLevel | Is some level being loaded? (Read Only). isLoadingLevel returns true if a level load was requested this frame already. | 表示当前加载的场景是否还需要当前帧。 |
NetworkReachability internetReachability | Returns the type of Internet reachability currently possible on the device. | 表示当前设备的网络连接方式。 |
RuntimePlatform platform | Returns the platform the game is running (Read Only). | 表示当前游戏运行的平台。 |
bool isConsolePlatform | Is the current Runtime platform a known console platform. | 表示当前运行的平台是否为控制台。 |
bool isMobilePlatform | Is the current Runtime platform a known mobile platform. | 当前运行的平台是否为移动平台。 |
bool isWebPlayer | Are we running inside a web player? (Read Only). | 当前运行的平台是否为web平台。 |
bool isEditor | Are we running inside the Unity editor? (Read Only). | 表示当前是否在Unity编辑器环境中运行程序。 |
int targetFrameRate | Instructs game to try to render at a specified frame rate. | 帧速率。 |
ThreadPriority backgroundLoadingPriority | Priority of background loading thread. | 表示后台加载优先级。 |
string bundleIdentifier | eturns application bundle identifier at runtime. | 表示应用运行时的标识符。 |
string cloudProjectId | A unique cloud project identifier. It is unique for every project (Read Only). | 云应用的唯一标识符。 |
string companyName | Return application company name (Read Only). | 应用的公司名称。 |
ApplicationInstallMode installMode | Returns application install mode (Read Only). | 应用安装模式。 |
bool runInBackground | Should the player be running when the application is in the background? | 应用是否在后台运行。 |
ApplicationSandboxType sandboxType | Returns application running in sandbox (Read Only). | 应用程序运行的沙箱类型。 |
string srcValue | The path to the web player data file relative to the html file (Read Only). | web player 文件的路径。 |
int streamedBytes | How many bytes have we downloaded from the main unity web stream (Read Only). | 字节流数。 |
SystemLanguage systemLanguage | How many bytes have we downloaded from the main unity web stream (Read Only). | 当前系统使用的语言。 |
string unityVersion | The version of the Unity runtime used to play the content. | Unity的版本。 |
string version | Returns application version number (Read Only). | 应用版本。 |
int webSecurityEnabled | Indicates whether Unity's webplayer security model is enabled. | unity 的webplayer的安全模式是否开启。 |
string absoluteURL | The absolute path to the web player data file (Read Only). | 用于保存在web浏览器中数据文件的绝对路径。 |
bool genuine | Returns false if application is altered in any way after it was built. | |
bool genuineCheckAvailable | Contains the path to the game data folder (Read Only). | |
ApplicationInstallMode installMode | Returns application install mode (Read Only). | 应用安装模式。 |
静态方法(Static Functions)
静态方法 | 英文解释 | 中文说明 |
---|---|---|
void LoadLevel(int index); void LoadLevel(string name); | Loads the level by its name or index. | 根据场景名称和索引号加载场景 |
void LoadLevelAdditive(int index);void LoadLevelAdditive(string name); | Loads a level additively. | 根据场景名称和索引号加载场景,但是当前场景的物体不销毁 |
AsyncOperation LoadLevelAsync(int index); AsyncOperation LoadLevelAsync(string levelName); | Loads the level asynchronously in the background. | 异步加载场景 |
AsyncOperation LoadLevelAdditiveAsync(int index); AsyncOperation LoadLevelAdditiveAsync(string levelName); | Loads the level additively and asynchronously in the background. | 异步加载场景,而且当前物体不销毁 |
void Quit(); | Quits the player application. | 退出游戏 |
void CancelQuit(); | Cancels quitting the application. This is useful for showing a splash screen at the end of a game. | 取消应用退出。 |
bool CanStreamedLevelBeLoaded(int levelIndex); | Can the streamed level be loaded? | 获得当前levelindex的场景是否被加载。 |
void CaptureScreenshot(string filename, int superSize = 0); | Captures a screenshot at path filename as a PNG file. | 截屏。 |
void OpenURL(string url); | Opens the url in a browser. | 在浏览器中访问网址 |
AsyncOperation RequestUserAuthorization(UserAuthorization mode); | Request authorization to use the webcam or microphone in the Web Player. | 请求获得权限 |
void ExternalCall(string functionName, params object[] args); | alls a function in the containing web page (Web Player only). | 在webplayer 调用一个javaScrip函数。 |
void ExternalEval(string script); | Evaluates script snippet in the containing web page (Web Player only). | 在webplayer上执行javascrip片段。 |
float GetStreamProgressForLevel(int levelIndex); | How far has the download progressed? [0...1]. | 下载进度。 |
bool HasUserAuthorization(UserAuthorization mode); | pCheck if the user has authorized use of the webcam or microphone in the Web Player. | 检测用户是否有webcam和手机在webpalyer的权限。 |
以上表格来源链接:http://www.jianshu.com/p/617789c9919a
数据文件路径,共有四个属性,分别为:dataPath、persistentDataPath、streamingAssetsPath、 temporaryCachePath。
- dataPaht是包含游戏数据文件夹的路径,权限为只读,返回的是一个相对路径,即对于不同的游戏平台返回的路径是不一样的。注意:Application.dataPath 返回的路径目录,在移动端是没有访问权限的(既不能访问此目录)。
- persistentDataPaht返回的是一个持久化数据存储目录,权限为只读,在同一平台,不用的应用程序访问此属性返回值相同,但是不同的平台就不相同了。当应用程序发布到IOS和Android平台中,这个路径会指向一个公共的路径,而且应用每次更新时这里的数据不会被清除。
注意:这个路径比较特殊,这个路径下是可读写。而且在IOS上就是应用程序的沙盒,但是在Android可以是程序的沙盒,也可以是SDCard。并且在Android打包发布时,PlayerSetting设置中的Write Access选项,可以设置它的路径是沙盒还是SDCard,默认情况Internal Only即沙盒。该路径的特点:
- 内容可读写,不过只能运行时才能写入或者读取。提前将数据存入这个路径是不可行的。
- 无内容限制。你可以从StreamingAsset中读取二进制文件或者从AssetBundle读取文件来写入PersistentDataPath中。
- 写下的文件,可以在电脑上查看。同样也可以清掉。
- streamingAssetsPath返回的是流数据的缓存目录,返回路径为相对路径适合用来存储一些外部数据文件。
- temporaryCachePath返回一个临时数据缓存目录(只读),同一平台不用应用程序访问此属性的返回值相同,不同平台返回值不同。
总结:dataPath 和 stremingAssetsPath是相对于程序的安装目录,是相对路径。非常适用于移植平台设置外部数据文件读取路径。而persistentDataPath和temporaryCachePath返回的程序所在平台的固定位置。适用于存储程序运行过程中一些数据。
来源链接:http://www.jianshu.com/p/bbc2690bce30
文章仅供学习和参考使用!