Ejemplo n.º 1
0
    public void LoadUIView(string path, XLuaCustomExport.OnCreate OnCreate = null)
    {
        Transform newui = Instantiate <Transform>(Resources.Load <Transform>("UI/" + path));

        if (OnCreate != null)
        {
            newui.gameObject.AddComponent <LuaViewBehaviour>();
            OnCreate(newui.gameObject);
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// 实例化UI界面
        /// </summary>
        /// <param name="path">资源路径</param>
        /// <param name="onCreate">实例化UI成功的 回调</param>
        /// <returns></returns>
        public GameObject LoadUIScene(string path, XLuaCustomExport.OnCreate onCreate = null)
        {
            GameObject obj = Resources.Load <GameObject>(path); //这里仅做测试,加载AB包应用异步方式去实现

            if (obj != null)
            {
                GameObject oo = GameObject.Instantiate(obj);
                oo.name = oo.name.Split('(')[0];
                if (onCreate != null)
                {
                    if (oo.GetComponent <LuaViewBehaviour>() == null)
                    {
                        oo.AddComponent <LuaViewBehaviour>();
                    }
                    onCreate(oo);
                }
                return(oo);
            }
            return(null);
        }
Ejemplo n.º 3
0
    /// <summary>
    /// Xlua层加载UI面板
    /// </summary>
    /// <param name="path"> 路径 </param>
    /// <param name="OnCreate"> 创建出来的委托回调 </param>
    public void LoadPopup(string path, LuaTable model, LuaTable data = null, XLuaCustomExport.OnCreate onCreate = null)
    {
        Debug.Log("加载UI窗口 =========== " + path);
        GameObject obj = GameObject.Instantiate(Resources.Load <GameObject>(path), mPopupParent.transform);

        if (obj != null)
        {
            obj.AddComponent <LuaBehaviour>();
        }
        else
        {
            return;
        }
        if (onCreate != null)
        {
            onCreate(obj);
        }
        var view = obj.GetComponent <LuaBehaviour>();

        view.SetLuaModule(model, data);
    }
Ejemplo n.º 4
0
        static int _m_LoadUIView(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                LuaHelper gen_to_be_invoked = (LuaHelper)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 3 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && translator.Assignable <XLuaCustomExport.OnCreate>(L, 3))
                {
                    string _path = LuaAPI.lua_tostring(L, 2);
                    XLuaCustomExport.OnCreate _OnCreate = translator.GetDelegate <XLuaCustomExport.OnCreate>(L, 3);

                    gen_to_be_invoked.LoadUIView(_path, _OnCreate);



                    return(0);
                }
                if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
                {
                    string _path = LuaAPI.lua_tostring(L, 2);

                    gen_to_be_invoked.LoadUIView(_path);



                    return(0);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to LuaHelper.LoadUIView!"));
        }
Ejemplo n.º 5
0
    public void LoadOrDownload <T>(string path, string name, System.Action <T> onComplete, XLuaCustomExport.OnCreate OnCreate = null, byte type = 0) where T : Object
    {
        lock (this)
        {
#if DISABLE_ASSETBUNDLE
            string newPath = string.Empty;
            switch (type)
            {
            case 0:
                newPath = string.Format("Assets/{0}", path.Replace("assetbundle", "prefab"));
                break;

            case 1:
                newPath = string.Format("Assets/{0}", path.Replace("assetbundle", "png"));
                break;
            }

            if (onComplete != null)
            {
                Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(newPath);
                onComplete(obj as T);
            }
            if (OnCreate != null)
            {
                Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>(newPath);
                OnCreate(obj as GameObject);
            }
#else
            //1.加载依赖文件配置
            LoadManifestBundle();

            //2.加载依赖项开始
            string[] arrDps = m_Manifest.GetAllDependencies(path);
            //先检查所有依赖项 是否已经下载 没下载的就下载
            CheckDps(0, arrDps, () =>
            {
                //=============下载主资源开始===================
                string fullPath = (LocalFileMgr.Instance.LocalFilePath + path).ToLower();

                //AppDebug.Log("fullPath=" + fullPath);

                #region  载或者加载主资源
                if (!File.Exists(fullPath))
                {
                    #region 如果文件不存在 需要下载
                    DownloadDataEntity entity = DownloadMgr.Instance.GetServerData(path);
                    if (entity != null)
                    {
                        AssetBundleDownload.Instance.StartCoroutine(AssetBundleDownload.Instance.DownloadData(entity,
                                                                                                              (bool isSuccess) =>
                        {
                            if (isSuccess)
                            {
                                if (m_AssetDic.ContainsKey(fullPath))
                                {
                                    if (onComplete != null)
                                    {
                                        onComplete(m_AssetDic[fullPath] as T);
                                    }
                                    return;
                                }

                                for (int i = 0; i < arrDps.Length; i++)
                                {
                                    if (!m_AssetDic.ContainsKey((LocalFileMgr.Instance.LocalFilePath + arrDps[i]).ToLower()))
                                    {
                                        AssetBundleLoader loader = new AssetBundleLoader(arrDps[i]);
                                        Object obj = loader.LoadAsset(GameUtil.GetFileName(arrDps[i]));
                                        m_AssetBundleDic[(LocalFileMgr.Instance.LocalFilePath + arrDps[i]).ToLower()] = loader;
                                        m_AssetDic[(LocalFileMgr.Instance.LocalFilePath + arrDps[i]).ToLower()]       = obj;
                                    }
                                }

                                //直接加载
                                using (AssetBundleLoader loader = new AssetBundleLoader(fullPath, isFullPath: true))
                                {
                                    if (onComplete != null)
                                    {
                                        Object obj           = loader.LoadAsset <T>(name);
                                        m_AssetDic[fullPath] = obj;
                                        //进行回调
                                        onComplete(obj as T);
                                    }

                                    //todu 进行xlua的回调
                                }
                            }
                        }));
                    }
                    #endregion
                }
                else
                {
                    if (m_AssetDic.ContainsKey(fullPath))
                    {
                        if (onComplete != null)
                        {
                            onComplete(m_AssetDic[fullPath] as T);
                        }
                        return;
                    }

                    //===================================
                    for (int i = 0; i < arrDps.Length; i++)
                    {
                        if (!m_AssetDic.ContainsKey((LocalFileMgr.Instance.LocalFilePath + arrDps[i]).ToLower()))
                        {
                            AssetBundleLoader loader = new AssetBundleLoader(arrDps[i]);
                            Object obj = loader.LoadAsset(GameUtil.GetFileName(arrDps[i]));
                            m_AssetBundleDic[(LocalFileMgr.Instance.LocalFilePath + arrDps[i]).ToLower()] = loader;
                            m_AssetDic[(LocalFileMgr.Instance.LocalFilePath + arrDps[i]).ToLower()]       = obj;
                        }
                    }
                    //===================================
                    //直接加载
                    using (AssetBundleLoader loader = new AssetBundleLoader(fullPath, isFullPath: true))
                    {
                        if (onComplete != null)
                        {
                            Object obj           = loader.LoadAsset <T>(name);
                            m_AssetDic[fullPath] = obj;
                            //进行回调
                            onComplete(obj as T);
                        }

                        //todu 进行xlua的回调
                    }
                }
                #endregion

                //=============下载主资源结束===================
            });
#endif
        }
    }
Ejemplo n.º 6
0
 public void LoadOrDownloadForLua(string path, string name, XLuaCustomExport.OnCreate OnCreate)
 {
     LoadOrDownload <GameObject>(path, name, null, OnCreate: OnCreate, type: 0);
 }
Ejemplo n.º 7
0
    /// <summary>
    /// 加载场景UI
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public void LoadSceneUI(SceneUIType type, System.Action <GameObject> OnLoadComplete, XLuaCustomExport.OnCreate OnCreate = null, string path = null)
    {
        string strUIName = string.Empty;

        string newPath = string.Empty;

        if (type != SceneUIType.None)
        {
            switch (type)
            {
            case SceneUIType.LogOn:
                strUIName = "UI_Root_LogOn";
                break;

            case SceneUIType.SelectRole:
                strUIName = "UI_Root_SelectRole";
                break;

            case SceneUIType.Loading:
                break;

            case SceneUIType.MainCity:
                strUIName = "UI_Root_MainCity";
                break;
            }

            newPath = string.Format("Download/Prefab/UIPrefab/UIScene/{0}.assetbundle", strUIName);
        }
        else
        {
            newPath = path;
        }

        AssetBundleMgr.Instance.LoadOrDownload(newPath, strUIName, (GameObject obj) =>
        {
            obj            = Object.Instantiate(obj);
            CurrentUIScene = obj.GetComponent <UISceneViewBase>();

            if (OnLoadComplete != null)
            {
                OnLoadComplete(obj);
            }

            if (OnCreate != null)
            {
                //此时表示 是从Lua中加载的
                obj.GetOrCreatComponent <LuaViewBehaviour>();
                OnCreate(obj);
            }
        });
    }
Ejemplo n.º 8
0
 public void LoadSceneUI(string path, XLuaCustomExport.OnCreate OnCreate)
 {
     LoadSceneUI(SceneUIType.None, null, OnCreate, path);
 }
Ejemplo n.º 9
0
    public void LoadWindow(string viewName, Action <GameObject> onComplete, Action OnShow = null, XLuaCustomExport.OnCreate OnCreate = null, string path = null)
    {
        if (!m_DicWindow.ContainsKey(viewName) || m_DicWindow[viewName] == null)
        {
            string newPath = string.Empty;

            if (string.IsNullOrEmpty(path))
            {
                newPath = string.Format("Download/Prefab/UIPrefab/UIWindows/pan_{0}.assetbundle", viewName);
            }
            else
            {
                newPath = path;
            }

            AssetBundleMgr.Instance.LoadOrDownload(newPath, string.Format("pan_{0}", viewName),
                                                   (GameObject obj) =>
            {
                obj = UnityEngine.Object.Instantiate(obj);

                UIWindowViewBase windowBase = obj.GetComponent <UIWindowViewBase>();
                if (windowBase == null)
                {
                    return;
                }

                if (OnShow != null)
                {
                    windowBase.OnShow = OnShow;
                }

                m_DicWindow[viewName] = windowBase;

                windowBase.ViewName   = viewName;
                Transform transParent = null;

                switch (windowBase.containerType)
                {
                case WindowUIContainerType.Center:
                    transParent = UISceneCtrl.Instance.CurrentUIScene.Container_Center;
                    break;
                }

                obj.transform.parent        = transParent;
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localScale    = Vector3.one;
                obj.gameObject.SetActive(false);

                //层级管理
                LayerUIMgr.Instance.SetLayer(obj);

                StartShowWindow(windowBase, true);

                if (onComplete != null)
                {
                    onComplete(obj);
                }

                if (OnCreate != null)
                {
                    OnCreate(obj);
                }
            });
        }
        else
        {
            if (onComplete != null)
            {
                GameObject obj = m_DicWindow[viewName].gameObject;
                //层级管理
                LayerUIMgr.Instance.SetLayer(obj);

                onComplete(obj);
            }
        }
    }
Ejemplo n.º 10
0
 public void LoadWindowForLua(string viewName, XLuaCustomExport.OnCreate OnCreate = null, string path = null)
 {
     LoadWindow(viewName, null, null, OnCreate, path);
 }
Ejemplo n.º 11
0
        public void LoadUIDialog(string sceneName, string fileName, string assetName, XLuaCustomExport.OnCreate onCreate = null)
        {
            if (!LoaderManager.Instance.IsLoadedAssetBundle(sceneName, fileName)) //没有加载过,就去加载
            {
                LoaderManager.Instance.LoadAssetBundle(sceneName, fileName, (bundleName, progress) =>
                {
                    Debug.Log(progress);

                    if (progress >= 1.0)
                    {
                        GameObject oo = GameObject.Instantiate(LoaderManager.Instance.LoadAsset(sceneName, fileName, assetName)) as GameObject;
                        oo.name       = oo.name.Split('(')[0];

                        if (onCreate != null)
                        {
                            if (oo.GetComponent <LuaViewBehaviour>() == null)
                            {
                                oo.AddComponent <LuaViewBehaviour>();
                            }
                            onCreate(oo);
                        }
                    }
                });
            }
            else
            {
                GameObject oo = GameObject.Instantiate(LoaderManager.Instance.LoadAsset(sceneName, fileName, assetName)) as GameObject;
                oo.name = oo.name.Split('(')[0];

                if (onCreate != null)
                {
                    if (oo.GetComponent <LuaViewBehaviour>() == null)
                    {
                        oo.AddComponent <LuaViewBehaviour>();
                    }
                    onCreate(oo);
                }
            }
        }