tolua#的Examples-18_Bundle

    IEnumerator CoLoadBundle(string name, string path)
    {
        using (WWW www = new WWW(path))
        {
            if (www == null)
            {
                Debugger.LogError(name + " bundle not exists");
                yield break;
            }

            yield return www;

            if (www.error != null)
            {
                Debugger.LogError(string.Format("Read {0} failed: {1}", path, www.error));
                yield break;
            }

            LuaFileUtils.Instance.AddSearchBundle(name, www.assetBundle);
            www.Dispose();
        }

        --bundleCount;
    }

    public void LoadBundles()
    {
        List list = new List() { "Lua.unity3d", "Lua_math.unity3d", "Lua_system.unity3d", "Lua_u3d.unity3d", "Lua_protobuf.unity3d" };        
        string streamingPath = Application.streamingAssetsPath.Replace('\\', '/');

        for (int i = 0; i < list.Count; i++)
        {
            string str = list[i];            
            string path = "file:///" + streamingPath + "/" + remoteFolder + str;
            string name = Path.GetFileNameWithoutExtension(str);
            StartCoroutine(CoLoadBundle(name, path));            
        }

        StartCoroutine(LoadFinished());
    }

    void Awake()
    {
        LuaFileUtils file = new LuaFileUtils();
        file.beZip = true;
        LoadBundles();
    }

    void OnBundleLoad()
    {
        LuaState state = new LuaState();
        state.Start();

        state.DoString("print('hello world')");

        state.Dispose();
        state = null;
    }    

这个例子演示的是tolua#如何加载打包进assetbundle中的lua代码,里面重要是
(1)LuaBundle的开关打开file.beZip = true;
(2)将"Lua.unity3d", "Lua_math.unity3d", "Lua_system.unity3d", "Lua_u3d.unity3d", "Lua_protobuf.unity3d" 等核心lua代码库都加载了。
(3)将加载的AssetBundle对象添加LuaFileUtils.Instance.AddSearchBundle(name, www.assetBundle);

[本日志由 admin 于 2016-03-20 10:27 PM 更新]
上一篇: tolua#的Examples-17_Inherit
下一篇: tolua#的Examples-19_cjson
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭