Lua_ Lua结合BundleManager实现网络热更新_023

来源:互联网 发布:mac pro 魔兽世界 编辑:程序博客网 时间:2024/05/21 03:20

创建简单脚本

创建 lua_bundle_test.txt
内容很简单:
print(‘从服务器加载,并执行成功啦’);


使用BundleManager制作Bundle

制作Bundle
这里写图片描述
配置Bundle
这里写图片描述
之后Build
这里写图片描述
将该目录剪切到其他目录比如G:\


HttpFileServer

将剪切的目录拖放到右侧
这里写图片描述


加载Lua代码并执行

using UnityEngine;using System.Collections;using LuaInterface;public class Test1 : MonoBehaviour {    // Use this for initialization    IEnumerator Start () {        DownloadManager.SetManualUrl("http://192.168.10.112:8080/StreamingAssets/Standalones/");        yield return StartCoroutine(DownloadManager.Instance.WaitDownload("lua_bundle.assetBundle"));        WWW www = DownloadManager.Instance.GetWWW("lua_bundle.assetBundle");        var bundle = www.assetBundle;        string[] assNames = bundle.GetAllAssetNames();        foreach(string s in assNames)        {            Debug.Log(s);        }        Object[] asss =  bundle.LoadAllAssets();        foreach(object obj in asss)        {            Debug.Log(obj.GetType());        }        TextAsset text = bundle.LoadAsset("lua_bundle_test") as TextAsset;        LuaState l = new LuaState();        l.DoString(text.text);    }    // Update is called once per frame    void Update () {    }}

加载情况

这里写图片描述

这里写图片描述