示例#1
0
 private void UpdateComplete()
 {
     //LuaHelper.Instance.DoString("require('LuanchABFW')");
     //LuaHelper.Instance.CallLuaFunc("LuanchABFW", "startABFW");
     ABMgr.GetInstance().LoadAssetBundlePack("mainscene", "mainscene/prefabs.ab", Complete);
     //ABMgr.GetInstance().LoadAssetBundlePack("mainscene", "mainscene/prefabs.ab", Complete);
 }
示例#2
0
    public static void LoadNewScene(string name)
    {
        LoadingName = name;

        Debug.Log("LoadNewScene: " + name);
        ABMgr.GetInstance().LoadLevel("99.loading");
    }
示例#3
0
 static public int LoadAB(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         ABMgr         self = (ABMgr)checkSelf(l);
         System.String a1;
         checkType(l, 2, out a1);
         self.LoadAB(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
示例#4
0
文件: Global.cs 项目: bsn069/bsnxlua
        public void UnInit()
        {
            Log.Info("NBsn.C_Global.UnInit()");

            LuaConsoleGesture.UnInit();
            m_LuaConsoleGesture = null;

            Lua.UnInit();
            m_Lua = null;

            UIMgr.UnInit();
            m_UIMgr = null;

            AtlasMgr.UnInit();
            m_AtlasMgr = null;

            ResMgr.UnInit();
            m_ResMgr = null;

            ABMgr.UnInit();
            m_ABMgr = null;

            Coroutine.UnInit();
            m_Coroutine = null;

            EventMgr.UnInit();
            m_EventMgr = null;

            Log.UnInit();
            m_Log = null;

            m_tfMain = null;
            m_Main   = null;
            m_goMain = null;
        }
示例#5
0
    /// <summary>
    /// 从ab包中加载lua资源
    /// </summary>
    /// <param name="filepath">require的lua脚本文件名</param>
    /// <returns></returns>
    public byte[] MyCustomABLoader(ref string filepath)
    {
        ////从AB包中加载lua文件
        ////加载AB包
        ////string path = Application.streamingAssetsPath + "/lua";
        //string path = Application.streamingAssetsPath + "/lua";
        //AssetBundle ab = AssetBundle.LoadFromFile(path);

        ////加载lua文件
        //TextAsset tx = ab.LoadAsset<TextAsset>(filepath + ".lua");
        ////加载lua文件,返回byte数组
        //return tx.bytes;

        //必须用同步加载
        TextAsset lua = ABMgr.GetInstance().LoadRes <TextAsset>("lua", filepath + ".lua");

        if (lua != null)
        {
            return(lua.bytes);
        }
        else
        {
            Debug.Log("MyCustomABLoader重定向失败,文件名为" + filepath);
        }
        return(null);
    }
示例#6
0
 private void Complete(string abName)
 {
     UnityEngine.Object obj = ABMgr.GetInstance().LoadAsset("mainscene", "mainscene/prefabs.ab", "UI_Notice.prefab", false);
     if (null == obj)
     {
         Debug.Log("null ");
     }
     else
     {
         Instantiate(obj);
     }
 }
示例#7
0
    //再写一个Load 用于从AB包加载Lua文件
    private byte[] MyCustomLoaderFormAB(ref string filepath)
    {
        //改为我们的AB包管理器加载
        TextAsset file2 = ABMgr.GetInstance().LoadRes <TextAsset>("lua", filepath + ".lua");

        if (file2 != null)
        {
            return(file2.bytes);
        }
        else
        {
            Debug.Log("MyCustomLoaderFormAB重定向失败");
        }
        return(null);
    }
示例#8
0
    IEnumerator _loadLua(string file, Action <string> cb)
    {
        file = (file + ".lua").ToLower();
        file = file.Replace("(clone)", "");

        bool ab = ABMgr.luaExist(file);

        string name = "ab_lua_" + file;
        string ret  = "";

        if (ab)
        {
            var request = AssetBundleManager.LoadAssetAsync(name, file, typeof(TextAsset));
            if (request == null)
            {
                TextAsset asset = Resources.Load("Lua/" + file) as TextAsset;
                if (asset != null)
                {
                    cb(asset.text);
                    yield break;
                }

                cb(ret);
                yield break;
            }

            yield return(StartCoroutine(request));

            TextAsset ta = request.GetAsset <TextAsset> ();

            if (ta != null)
            {
                ret = ta.text;
            }
        }
        else
        {
            TextAsset asset = Resources.Load("Lua/" + file) as TextAsset;
            if (asset != null)
            {
                cb(asset.text);
                yield break;
            }
        }

        cb(ret);
        yield break;
    }
示例#9
0
    void Awake()
    {
        scriptEnv = luaEnv.NewTable();

        LuaTable meta = luaEnv.NewTable();

        meta.Set("__index", luaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        scriptEnv.Set("self", this);
        foreach (var injection in injections)
        {
            scriptEnv.Set(injection.name, injection.value);
        }

        luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv);

        Action luaAwake = scriptEnv.Get <Action>("awake");

        scriptEnv.Get("start", out luaStart);
        scriptEnv.Get("update", out luaUpdate);
        scriptEnv.Get("ondestroy", out luaOnDestroy);

        if (luaAwake != null)
        {
            luaAwake();
        }

        luaEnv.AddLoader((ref string filename) =>
        {
            var result = ABMgr.GetLuaContent(filename + ".lua");
            if (result)
            {
                return(result.bytes);
            }

            return(null);
        });
    }
示例#10
0
文件: Global.cs 项目: bsn069/bsnxlua
        private IEnumerator StartApp()
        {
            var pView = UIMgr.GetView("UIUpdate") as NBsn.NMVVM.UpdateV;

            pView.Show();

            var pUpdateRes = new NBsn.NUpdateRes.C_UpdateRes();

            yield return(Coroutine.Start(pUpdateRes.Run()));

#if UNITY_EDITOR
            if (pUpdateRes.IsSuccess())
            {
                yield break;
            }
#endif
            UIMgr.InitAfterUpdateRes();
            ResMgr.InitAfterUpdateRes();
            ABMgr.InitAfterUpdateRes();

            Lua.DoString("require('main')");
        }
示例#11
0
 IEnumerator BeginLoading()
 {
     yield return(ABMgr.GetInstance().LoadLevelAsync(LoadingName));
 }
示例#12
0
 public ABMgr GetABMgr()
 {
     return(ABMgr.GetInstance());
 }
示例#13
0
        public void LoadForABByUrl(string url, Action <UnityEngine.Object> callback, bool releaseAb = false)
        {
            bool needLoadAb = false;
            var  info       = cfg.ResData.GetResInfoByUrl(url);

            if (info == null)
            {
                Debug.LogError("资源路径不存在 url:" + url);
                if (callback != null)
                {
                    callback(null);
                }
                return;
            }

            if (mAllRes.ContainsKey(info.address))
            {
                if (callback != null)
                {
                    callback(mAllRes[info.address]);
                }
                return;
            }

#if UNITY_EDITOR
            needLoadAb = cfg.SimulateAssetBundle;
#else
            needLoadAb = true;
#endif
            if (!needLoadAb)
            {
#if UNITY_EDITOR
                var asset = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(info.path);
                if (asset == null)
                {
                    Debug.LogError("资源加载失败:url=" + url + " /path=" + info.path);
                }
                else
                {
                    mAllRes[info.address] = asset;
                }

                if (callback != null)
                {
                    callback(asset);
                }
                return;
#endif
            }

            ABMgr.GetAB(info.ABName, a =>
            {
                UnityEngine.Object asset = null;
                if (a == null)
                {
                    Debug.LogError("加载assetbundle失败url:" + url);
                }
                else
                {
                    string assetName = Path.GetFileName(url);
                    asset            = ABMgr.LoadAsset(info.ABName, assetName);
                    if (asset == null)
                    {
                        Debug.LogError("资源加载失败:url=" + url);
                    }
                    else
                    {
                        mAllRes[info.address] = asset;
                    }

                    if (releaseAb)
                    {
                        ABMgr.Release(info.ABName);
                    }
                }

                if (callback != null)
                {
                    callback(asset);
                }
            });
        }
示例#14
0
 private void UpdateComplete()
 {
     ABMgr.Instance().LoadAssetBundlePack("mainscene", "mainscene/prefabs.ab", Complete);
 }
示例#15
0
文件: Global.cs 项目: bsn069/bsnxlua
        // 游戏逻辑初始化
        public void Init(GameObject goMain, NBsn.M_Main Main)
        {
            NBsn.C_Platform.Info();

            m_goMain = goMain;
            m_Main   = Main;
            m_tfMain = m_goMain.transform;

            m_Log = new NBsn.C_Log();
            Log.Init();
            NBsn.C_PathConfig.Debug();

            m_EventMgr = new NBsn.C_EventMgr();
            EventMgr.Init();

            m_Lua = new NBsn.C_Lua();
            Lua.Init();

            m_Coroutine = new NBsn.C_Coroutine();
            Coroutine.Init(m_Main);

            m_ABMgr = new NBsn.C_ABMgr();
            ABMgr.Init(null);

            m_ResMgr = new NBsn.C_ResMgr();
            ResMgr.Init();

            m_AtlasMgr = new NBsn.C_AtlasMgr();
            AtlasMgr.Init();

            m_UIMgr = new NBsn.C_UIMgr();
            UIMgr.Init(m_tfMain);

            m_LuaConsoleGesture = new NBsn.C_Gesture();
            LuaConsoleGesture.Init(
                () => {
                var pView = UIMgr.GetView("UILuaConsole") as NBsn.NMVVM.LuaConsoleV;
                pView.Show();
            }
                , EasyTouch.SwipeDirection.Right
                , EasyTouch.SwipeDirection.Down
                , EasyTouch.SwipeDirection.Left
                , EasyTouch.SwipeDirection.Up
                );

            ABMgr.LoadABManifest();
            ABMgr.LoadRes2ABId();

            Coroutine.Start(StartApp());
            // var pView = UIMgr.GetView("UIUpdate") as NBsn.NMVVM.UpdateV;
            // pView.Show();
            // //var pVM = pView.VM;
            // //pVM.TextCenter.Value = "";

            // var pUpdateRes = new NBsn.NUpdateRes.C_UpdateRes();
            // pUpdateRes.GetVerInfo();
            //Lua.DoString("require('main')");


            // C_ResLoadParam pResLoadParam = new C_ResLoadParam();
            // pResLoadParam.strPath = @"atlas\red";
            // pResLoadParam.strSuffix = "prefab";
            // var a = ResMgr.Load<Sprite>(pResLoadParam);
            // Log.Info(a);
        }
示例#16
0
    void Awake()
    {
        mInstance = this;

        ldr = GameObject.Find("UI Root").GetComponent <Loader>();
    }
示例#17
0
文件: XLuaMgr.cs 项目: gbyh/XGame
 private byte[] CustomLoader(ref string filename)
 {
     return(ABMgr.LoadLuaFile(filename));
 }
示例#18
0
 private void Awake()
 {
     Instance    = this;
     mCacheABDic = new Dictionary <string, PackInfo>();
 }
示例#19
0
        public static IEnumerator CheckAB(AssetBundleManifest mb, AssetBundleManifest mc, Action <float> update)
        {
            var mani = mb != null ? mb : mc;
            var ma   = m_AssetBundleManifest;

            mC = mc;

            if (ma == null)
            {
                ABMgr.saveABs(mani.GetAllAssetBundles());
                yield break;
            }

            string[] abs = ma.GetAllAssetBundles();

            List <abitem> checks = new List <abitem> ();

            Debug.Log("CheckAB...");

            foreach (var ab in abs)
            {
                var  hash = ma.GetAssetBundleHash(ab);
                bool down = true;

                if (mani != null && mani.GetAssetBundleHash(ab) == hash)
                {
                    down = false;
                }

                if (down)
                {
                    checks.Add(new abitem(ab, hash));
                }
            }

            int total = checks.Count;
            int cnt   = 0;

            Debug.Log("to be update: " + total);

            foreach (abitem item in checks)
            {
                var ab   = item.name;
                var hash = item.hash;

                string bundleBaseDownloadingURL = GetAssetBundleBaseDownloadingURL(ab);
                if (!bundleBaseDownloadingURL.EndsWith("/"))
                {
                    bundleBaseDownloadingURL += "/";
                }

                var url = bundleBaseDownloadingURL + ab;
                WWW www = WWW.LoadFromCacheOrDownload(url, hash, 0);
                yield return(www);

                Debug.Log("update success: " + ab);

                www.assetBundle.Unload(true);
                cnt++;

                if (update != null)
                {
                    update((float)cnt / total);
                }
            }

            ABMgr.saveABs(abs);
            yield break;
        }
示例#20
0
文件: Mgr.cs 项目: isaveu/MyFrameWork
 // Start is called before the first frame update
 public static void Initialize()
 {
     Assetbundle  = ABMgr.Instance;
     UI           = PanelMgr.Instance;
     VersionCheck = VersionCheckMgr.Instance;
 }
示例#21
0
 static public int LoadRes(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(string), typeof(string)))
         {
             ABMgr         self = (ABMgr)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             System.String a2;
             checkType(l, 3, out a2);
             var ret = self.LoadRes(a1, a2);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (matchType(l, argc, 2, typeof(string), typeof(string)))
         {
             ABMgr         self = (ABMgr)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             System.String a2;
             checkType(l, 3, out a2);
             var ret = self.LoadRes <UnityEngine.Object>(a1, a2);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         else if (argc == 4)
         {
             ABMgr         self = (ABMgr)checkSelf(l);
             System.String a1;
             checkType(l, 2, out a1);
             System.String a2;
             checkType(l, 3, out a2);
             System.Type a3;
             checkType(l, 4, out a3);
             var ret = self.LoadRes(a1, a2, a3);
             pushValue(l, true);
             pushValue(l, ret);
             return(2);
         }
         pushValue(l, false);
         LuaDLL.lua_pushstring(l, "No matched override function LoadRes to call");
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }