Application类

Application 

Application 类没有实例方法和实例属性,在脚本中可以直接调用Application类的静态方法和静态属性来控制程序运行时的数据,比如场景加载,数据的加载等。


Application类常用静态属性

在Application类中,常用的属性主要是dataPath 和 loadedLevel ,后面的temporaryCachePath、persistentDataPath、streamingAsset是Path、属性和dataPath用法一致都是获取相对路径。这里就只说一下dataPath

1.dataPath属性:数据文件路径

 

 

2.loadedLevel属性:关卡索引


Application类常用静态方法

在Application类中,常用的的静态方法有LoadLevelAdditiveAsync方法和RegisterLogCallback方法。

LoadLevelAdditiveAsync方法

异步添加场景

IEnumerator start()
{
    Async0peration async = Application.LoadLevelAdditiveAsync("Gameo2");/异步加载中
    Debug.Log("1:" + async.isDone);11是否加载完成
    Debug.Log("2:" +async.progress);//加载进度,范围0一1yield return async;
    1/加载完成后
    Debug.Log("3:" + async.isDone);Debug.Log("4:" + async.progress);is_load_over = async.isDone;
}

 

RegisterLogCallback方法

public class RegisterLogCallback_ts : MonoBehaviour
{
    string output = "";//日志输出信息
    string stack = "";//堆栈跟踪信息
    string logType = "";//日志类型
    int tp = 0;
    //打印日志信息
    void Update()
    {
        Debug.Log("stack:" + stack);
        Debug.Log("logType:" + logType);
        Debug.Log("tp:"+(tp++));
        Debug.Log("output:" + output);
    }
    void OnEnable()
    {
        //注册委托
        Application.RegisterLogCallback(MyCallback);

    }
    void OnDisable()
    {
        //取消委托
        Application.RegisterLogCallback(null);
    }
    //委托方法
    //方法名字可以自定义,但方法的参数类型要符合Application.LogCallback中的参数类型
    void MyCallback(string logString, string stackTrace, LogType type)
    {
        output = logString;
        stack = stackTrace;
        logType = type.ToString();
    }
}

 

posted @ 2022-07-21 10:20  Luohanhui  阅读(131)  评论(0)    收藏  举报