Пример #1
0
 static public int get_reses(IntPtr l)
 {
     try {
         XLoadDesc self = (XLoadDesc)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.reses);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #2
0
 static public int get_status(IntPtr l)
 {
     try {
         XLoadDesc self = (XLoadDesc)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.status);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #3
0
 static public int constructor(IntPtr l)
 {
     try {
         XLoadDesc o;
         o = new XLoadDesc();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #4
0
 static public int set__isComplete(IntPtr l)
 {
     try {
         XLoadDesc      self = (XLoadDesc)checkSelf(l);
         System.Boolean v;
         checkType(l, 2, out v);
         self._isComplete = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #5
0
 static public int set_cursor(IntPtr l)
 {
     try {
         XLoadDesc self = (XLoadDesc)checkSelf(l);
         XLoadRes  v;
         checkType(l, 2, out v);
         self.cursor = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #6
0
 static public int set_reses(IntPtr l)
 {
     try {
         XLoadDesc self = (XLoadDesc)checkSelf(l);
         System.Collections.Generic.List <XLoadRes> v;
         checkType(l, 2, out v);
         self.reses = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Пример #7
0
    // DESC不允许为空
    public XLoadDesc fillDesc(XLoadDesc desc)
    {
        // asset desc!= null
        if (desc.reses == null || desc.reses.Count == 0)
        {
            // 直接完成了
            desc._isComplete = true;
            return(desc);
        }
        bool isComplete = true;

        for (int i = 0; i < desc.reses.Count; i++)
        {
            getAssetInfo(desc.reses[i]);
            // 优化直接完成的情况
            if (!desc.reses[i].asset.isComplete)
            {
                isComplete = false;
            }
        }

        desc._isComplete = isComplete;
        return(desc);
    }
Пример #8
0
    // XApp 启动
    IEnumerator init()
    {
        XDebug.Log("init:" + Time.realtimeSinceStartup);
        // 先启动装载服务器
        yield return(StartCoroutine(XLoad.instance.init()));

        if (!XLoad.instance.isOK)
        {
            // 弹对话框
            XDebug.LogError("致命错误XLoad没有装载成功");
        }
        else
        {
            // 先加载进度条
            XLoadDesc desc = XLoad.load("Assets/Res/progress/style1.prefab");
            yield return(desc);

            if (desc.ob == null)
            {
                XDebug.LogError("Assets/Res/progress/style1.prefab not exist, quit!!!");
                yield break;
            }

            XDebug.Log("onLoadProgress:" + Time.realtimeSinceStartup);
            xloading = this.gameObject.AddComponent <XLoading>();
            xpool    = this.gameObject.AddComponent <XPoolManager>();

            GameObject loadingStyle0 = GameObject.Instantiate(desc.ob, uiProgress) as GameObject;
            xloading.addStyle(0, loadingStyle0, loadingStyle0.transform.Find("Slider").GetComponent <UnityEngine.UI.Slider>(), null,
                              loadingStyle0.transform.Find("Info").GetComponent <UnityEngine.UI.Text>(), null);


            // 切换进度条
            XLoading.instance.beginShow(0);

            bool wantUpdateVersion = XConf.isUpdateVersion;

            // 是否更新
            if (!XLoad.instance.isLoadFromAB)
            {
                // editor状态下并不更新版本
                wantUpdateVersion = false;
            }


            if (wantUpdateVersion)
            {
                // 创建更新对象
                XUpdate xup = new XUpdate();

                // 开启更新协程
                yield return(StartCoroutine(xup.updateVersion(XConf.publishUrl)));

                if (xup.isFail)
                {
                    // 失败了MSGBOX,重新更新,下载链接?都是从头走,清除已装载的东西
                    yield break;
                }
                else
                {
                    // 成功了,那么走正式流程,再次来一发
                    // 清理操作-------
                    // StartCoroutine(init());
                    // yield break;
                }
            }


            XLoadDesc descBack = XLoad.load("Assets/Res/ui/uiBack.prefab");
            XLoading.instance.beginShow(0, descBack);

            yield return(descBack);

            if (descBack.ob != null)
            {
                GameObject.Instantiate(descBack.ob, this.uiBack);
            }

            #region 装载lua
            // 开始装载lua文件
            XLoadDesc descLua = loadLua();
            XLoading.instance.beginShow(0, descLua);

            yield return(descLua);

            var luaAsInfo = descLua.assetInfo;
            if (luaAsInfo.isSuccess)
            {
                luaDict = descLua.obDict;
            }

            // 装载lua函数
            LuaState.loaderDelegate += loadLuaFile;

            // 创建一个luaSvr
            luaSvr = new LuaSvr();
            luaSvr.init();

            XLuaBind luaBind = new XLuaBind {
                luaSvr = luaSvr
            };
            XLoading.instance.beginShow(0, luaBind);

            // 全局装载函数

            // 绑定的时间
            yield return(luaBind);

            // 绑定完成后从Main开始执行
            luaSvr.onBindComplete(() =>
            {
                // 初始化调试器
                ldb = new DebugInterface(luaSvr.luaState);
                ldb.init();


                XDebug.Log("luaBindComplete start Main" + Time.realtimeSinceStartup);
                luaSvr.start(XConf.luastart);
                XDebug.Log("luaBindComplete end Main" + Time.realtimeSinceStartup);
            });
            #endregion
        }
    }
Пример #9
0
    // 优化协程版本,不开启更多的协程
    IEnumerator coLoad(XLoadDesc desc, Action <XLoadDesc> cb, bool check)
    {
        // asset desc!= null
        if (check)
        {
            fillDesc(desc);
            if (desc.isComplete)
            {
                if (cb != null)
                {
                    cb(desc);
                }
                yield break;
            }
        }
        // 一个一个的装载
        for (int i = 0; i < desc.reses.Count; i++)
        {
            XLoadRes res = desc.reses[i];

            desc.cursor = res;
            XAssetInfo asset = res.asset;
            if (asset.status == XLoadStatus.NONE)
            {
                asset.status = XLoadStatus.LOADING;

                XBundleInfo bundle = res.asset.bundle;
                #region bundle 装载流程
                // 没装载好
                if (bundle.status == XLoadStatus.NONE)
                {
                    bundle.status = XLoadStatus.LOADING;

                    bool childOK = true;
                    // 拍平了的依赖
                    for (int j = 0; j < bundle.dependAll.Count; j++)
                    {
                        XBundleInfo dpab = bundle.dependAll[j];
                        if (dpab.status == XLoadStatus.NONE)
                        {
                            dpab.status = XLoadStatus.LOADING;
                            // 真正装载的路径
                            dpab.www = new WWW(getPath(dpab));

                            // XDebug.LogError("装载依赖"+ getPath(dpab));
                            yield return(dpab.www);

                            if (!string.IsNullOrEmpty(dpab.www.error) || dpab.www.assetBundle == null)
                            {
                                dpab.status = XLoadStatus.FAIL;
                            }
                            else
                            {
                                dpab.ab     = dpab.www.assetBundle;
                                dpab.status = XLoadStatus.SUCESS;
                            }
                            dpab.www.Dispose();
                            dpab.www = null;
                        }

                        if (!dpab.isComplete)
                        {
                            yield return(dpab);
                        }

                        if (dpab.isFail)
                        {
                            bundle.status = XLoadStatus.FAIL;
                            childOK       = false;
                            break;
                        }
                    }
                    // 装载自己
                    if (childOK)
                    {
                        bundle.www = new WWW(getPath(bundle));

                        // XDebug.LogError("装载自己" + getPath(bundle));
                        yield return(bundle.www);

                        if (!string.IsNullOrEmpty(bundle.www.error) || bundle.www.assetBundle == null)
                        {
                            bundle.status = XLoadStatus.FAIL;
                        }
                        else
                        {
                            bundle.ab     = bundle.www.assetBundle;
                            bundle.status = XLoadStatus.SUCESS;
                        }
                        bundle.www.Dispose();
                        bundle.www = null;
                    }
                }
                #endregion

                if (!bundle.isComplete)
                {
                    yield return(bundle);
                }
                #region 装载asset
                // 失败了
                if (bundle.isFail)
                {
                    asset.status = XLoadStatus.FAIL;
                }
                else
                {
                    // bundle成功了
                    if (asset.all)
                    {
                        asset.rq = bundle.ab.LoadAllAssetsAsync(asset.tp);
                        yield return(asset.rq);

                        if (asset.rq.isDone && asset.rq.allAssets != null)
                        {
                            asset.status = XLoadStatus.SUCESS;
                            asset.obs    = asset.rq.allAssets;
                            if (asset.obs != null)
                            {
                                asset.obDict = new Dictionary <string, UnityEngine.Object>();
                                string[] assetNames = bundle.ab.GetAllAssetNames();

                                if (assetNames.Length == asset.obs.Length)
                                {
                                    for (int k = 0; k < asset.obs.Length; k++)
                                    {
                                        asset.obDict[assetNames[k]] = asset.obs[k];
                                    }
                                }
                                else
                                {
                                    // 如果只有一项,本来名称需要相同的
                                    if (assetNames.Length >= 1)
                                    {
                                        for (int k = 0; k < asset.obs.Length; k++)
                                        {
                                            asset.obDict[assetNames[0]] = asset.obs[k];
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            asset.status = XLoadStatus.FAIL;
                        }

                        asset.rq = null;
                    }
                    else
                    {
                        string relname = getRelPathName(asset.res, bundle);
                        asset.rq = bundle.ab.LoadAssetAsync(relname, asset.tp);
                        yield return(asset.rq);

                        if (asset.rq.isDone && asset.rq.asset != null)
                        {
                            asset.status = XLoadStatus.SUCESS;
                            asset.ob     = asset.rq.asset;
                        }
                        else
                        {
                            asset.status = XLoadStatus.FAIL;
                        }

                        asset.rq = null;
                    }
                }
                #endregion
            }

            // 可以让自己直接返回
            if (!asset.isComplete)
            {
                yield return(asset);
            }
        }
        desc._isComplete = true;
        if (cb != null)
        {
            cb(desc);
        }
    }
Пример #10
0
    // 真正函数地方
    public XLoadDesc realLoad(List <XLoadRes> reses, Action <XLoadDesc> cb)
    {
        // asset reses!= null
        // XLoad默认模块必须装载成功
        if (!_isOK)
        {
            XDebug.LogError("XLoad模块并没有初始化成功就进行装载");
            return(null);
        }

        // 不装载任何资源,默认模式算完成状态
        XLoadDesc desc = new XLoadDesc {
            reses = reses
        };

        fillDesc(desc);

        if (desc.isComplete)
        {
            if (cb != null)
            {
                cb(desc);
            }
            return(desc);
        }

#if UNITY_EDITOR
        // 肯定是EDITOR状态
        if (!isLoadFromAB)
        {
            // 因为是阻塞的,所以没其他问题
            for (int i = 0; i < reses.Count; i++)
            {
                XAssetInfo assetInfo = reses[i].asset;
                if (!assetInfo.isComplete)
                {
                    if (assetInfo.all)
                    {
                        assetInfo.obs    = editorLoadAll(assetInfo.res, assetInfo.tp);
                        assetInfo.status = assetInfo.obs == null ? XLoadStatus.FAIL : XLoadStatus.SUCESS;
                    }
                    else
                    {
                        assetInfo.ob     = editorLoad(assetInfo.res, assetInfo.tp);
                        assetInfo.status = assetInfo.obs == null ? XLoadStatus.FAIL : XLoadStatus.SUCESS;
                    }
                }
            }

            desc._isComplete = true;
            if (cb != null)
            {
                cb(desc);
            }
            return(desc);
        }
        else
#endif
        {
            // 开启协程整流程去装载
            StartCoroutine(coLoad(desc, cb, false));
        }

        return(desc);
    }