AB Editor打包
using UnityEditor;
using System.IO;
public class AssetBuild
{
[MenuItem("Assets/build AssetsBuild")]
static void BuildAllAssetsBundles()
{
if(!Directory.Exists("AssetsBundles"))
{
Directory.CreateDirectory("AssetsBundles");
}
BuildPipeline.BuildAssetBundles("AssetsBundles", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
}
}
springboot的部署
关键代码
package com.example.demo.Config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class FileConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/FileUnity/**").addResourceLocations(
"file:"+System.getProperty("user.dir")+System.getProperty("file.separator")+"FileUnity"
+System.getProperty("file.separator")
);
}
}
XLUA的调用
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XLua;
public class CallLuaStart : MonoBehaviour
{
private LuaEnv luaEnv;
private void Awake()
{
luaEnv = new LuaEnv();
luaEnv.AddLoader(Myloader);
luaEnv.DoString("require 'UNTIT'");
print("执行");
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private byte[] Myloader(ref string path)
{
string router = Directory.GetCurrentDirectory() + "\\Assets\\ideaLua\\" + path + ".lua.txt";
return System.Text.Encoding.UTF8.GetBytes(File.ReadAllText(router));
}
}
UnityWeb方式进行下载
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
using XLua;
[Hotfix]
public class HotFixMyDeni : MonoBehaviour
{
/* [LuaCallCSharp]*/
void Start()
{
StartCoroutine(DownLoad("http://192.168.0.8:8081/FileUnity/AssetsBundles/per.mat"));
}
IEnumerator DownLoad(string url)
{
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url);
yield return request.SendWebRequest();
AssetBundle AB = DownloadHandlerAssetBundle.GetContent(request);
GameObject obj= AB.LoadAsset<GameObject>("Cube");
Instantiate(obj);
}
// Update is called once per frame
void Update()
{
}
}