Unity-Application类常用功能

// 过时的API、不常用的我就不说了
// auhtor   :   Jave.Lin
// date     :   2018-05-16
public sealed class Application
{
    // 可以设置U3D后台下载线程的:线程优先级,可了解DotNet中的线程优先级作用
    public static ThreadPriority backgroundLoadingPriority { get; set; } 
    // build时的GUID,估计可以用于判断程序合法性
    public static string buildGUID { get; }
    // 获取你的App的公司名称,在:U3D的PlayerSettings中的CompanyName
    public static string companyName { get; }
    // Assets目录,注意不用的平台结果不一(PC,iOS,Android)
    public static string dataPath { get; }
    // 可检测安装模式,如,检测是否Development build模式,都可以,查看:ApplicationInstallMode枚举
    public static ApplicationInstallMode installMode { get; } 
    // 可检测当前网络是否可用,还有辨别网络载体类型
    public static NetworkReachability internetReachability { get; }
    // 判断当前是否基于U3D 编辑器下运行的
    public static bool isEditor { get; }
    // 判断U3D程序是否激活(如:iOS, Android如果有其他程序置顶,
    // 处于后台那么return false,PC就是没有程序交互焦点时return false,其他情况return true)
    public static bool isFocused { get; }
    // 判断是否在移动平台在运行
    public static bool isMobilePlatform { get; }
    // 运行时可读写目录,具体什么内容,自己到不同平台下都输出看看吧
    public static string persistentDataPath { get; }
    // 返回当前枚举中的运行时平台信息,具体看:RuntimePlatform 枚举定义
    public static RuntimePlatform platform { get; }
    // 你的发布程序名称,在U3D PlayerSettings中的ProductName可设置
    public static string productName { get; }
    // 还没用过,估计和:isFocused 差不多
    public static bool runInBackground { get; set; }
    // 返回运行时的系统语言类型
    public static SystemLanguage systemLanguage { get; }
    // 可获取或设置U3D程序的目标帧率,如:设置为:60,本身可以运行200FPS的,
    // 但限制后只会到60,手机端上可节省电量,如果设置:60,运行时小于60FPS,那就尽量优化程序吧,因为掉帧了
    public static int targetFrameRate { get; set; }
    // 临时缓存目录,具体什么内容,自己到不同平台下都输出看看吧
    public static string temporaryCachePath { get; }
    // 返回当前运行时的unity版本号
    public static string unityVersion { get; }
    // 返回你的程序版本号,在PlayerSettings中的Version可设置
    public static string version { get; }
    // 字面上意思:当收到log日志消息时触发的事件
    public static event LogCallback logMessageReceived;
    // 这个比较有用了,当能用内存量低时会触发的事件,至于怎么判断当前低能用量内存的方式,大家去搜索吧
    public static event LowMemoryCallback lowMemory;
    // 渲染前的事件?这个没用过
    public static event UnityAction onBeforeRender;
    // 有否Pro授权版的
    public static bool HasProLicense();
    // 在浏览器中打开一个URL(之前不知道有这个API,还去了解了Unity for Android/iOS的开发,
    // 来调用不同平台下的浏览器来打开URL,好麻烦,现在知道有这个接口就方便多了,
    // 不过如果要实现在同一个进程中来打开网页的话,那么这个就需要去了解Unity for xxx的开发了,
    // 因为Application.OpenURL是在操作系统的默认浏览器来打开的)
    public static void OpenURL(string url);
    // 手动退出程序
    public static void Quit();
    // 貌似可用于:摄像头(图像验证)、麦克风(语音验证)的验证请求,还没用过,大家可以试试
    public static AsyncOperation RequestUserAuthorization(UserAuthorization mode);
    // Quit前,先Unload吧,其实觉得这个API有点鸡肋,因为Application.Quit()是进程级别退出,
    // 进程退出的话,那么之前在这个进程申请的所有资源都会自动回收的(线程、内存、等)
    public static void Unload();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章