当前位置: 首页 > news >正文

电商网站开发 数商云外贸网站定制开发

电商网站开发 数商云,外贸网站定制开发,百度下载并安装,郑州网站设计收费xlua作为Unity资源热更新的重要解决方案api,在Tecent重多游戏中被采用,本文通过案例去讲解xlua代码结构层次。 /** Tencent is pleased to support the open source community by making xLua available.* Copyright (C) 2016 THL A29 Limited, a Tence…

xlua作为Unity资源热更新的重要解决方案api,在Tecent重多游戏中被采用,本文通过案例去讲解xlua代码结构层次。

/** Tencent is pleased to support the open source community by making xLua available.* Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at* http://opensource.org/licenses/MIT* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/using UnityEngine;
using XLua;namespace XLuaTest
{public class Helloworld : MonoBehaviour{// Use this for initializationvoid Start(){//创建xlua虚拟机LuaEnv luaenv = new LuaEnv();luaenv.DoString("print('hello xlua!')");luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");//释放资源luaenv.Dispose();}// Update is called once per frame}
}

image.png

加载lua文件

Resources.Load(“xlua/xx.lua”) 加载

创建Resources 目录下xx.lua.txt文件

//创建xlua虚拟机【建议全局唯一】
LuaEnv luaenv = new LuaEnv();
//加载lua脚本资源
TextAsset textAsset = Resources.Load<TextAsset>("xlua/hello.lua");
luaenv.DoString(textAsset.ToString());

loader加载

luaenv.DoString("require 'xlua/hello'"); //require + 'lua文件名称不加扩展名'
//require 实际上是逐个查找loader文件 是否存在指定文件

自定义loader

挨个查找loader,若某个loader返回了字节数组,那么便不继续查找了

  //加载loaderluaenv.AddLoader(Myloader);luaenv.DoString("require 'xlua/hello'");//挨个查找loader,若某个loader返回了字节数组,那么便不继续查找了//释放资源luaenv.Dispose();/// <summary>/// 自定义loader/// </summary>/// <param name="filePath"></param>/// <returns></returns>private byte[] Myloader(ref string filePath){print(filePath);string s = "print(123)";return Encoding.UTF8.GetBytes(s);}

image.png

构建Assets/StreamingAssets文件夹

  private byte[] Myloader(ref string filePath){//print(filePath);string absPath = Application.streamingAssetsPath + "/" + filePath + ".lua.txt";return Encoding.UTF8.GetBytes(File.ReadAllText(absPath));}

C#访问lua文件

全局变量

加载文件成功后,访问lua文件中的全局变量
–number 可以对应int float double

           //通过luaenv 访问变量int integer_Lua = luaenv.Global.Get<int>("Integer");string name_Lua = luaenv.Global.Get<string>("Name");Debug.Log(integer_Lua + name_Lua);

//lua文件中person = {Name = "James",Sno = 23,eat = function()print("i'm eating!")end}
//
//C#
class Person{public string _name;public int _sno;}Person luaPerson = luaenv.Global.Get<Person>("person");print(luaPerson._sno + ":" + luaPerson._name);

接口

IPerson luaPerson = luaenv.Global.Get<IPerson>("person");print(luaPerson.sno + ":" + luaPerson.name);[CSharpCallLua]interface IPerson{string name { get; set; }int sno { get; set; }void eat();}

字典

dic = {china = 1,america = 2,uk  = 3,
}
 //通过字典遍历Dictionary<string,int> dic =  luaenv.Global.Get<Dictionary<string, int>>("dic");foreach (var key in dic.Keys){print(key + ":" + dic[key]);}

image.png

列表

list = {'sdahjk',12,123,'12'}
  //通过list访问List<object> list =  luaenv.Global.Get<List<object>>("list");foreach (var target in list){print(target.ToString());}

再将上述数据通过List读取一次
image.png

LuaTable

LuaTable table = luaenv.Global.Get<LuaTable>("person");table.Get<string>("name");

函数

 [CSharpCallLua]delegate int Add(int a, int b);//函数Add add = luaenv.Global.Get<Add>("add");print(add(3,5));add = null;

lua多返回值通过,out 变量接受

add = function(a,b)return a + b,a,b
end
 delegate int Add2(int a, int b, out int resa, out int resb);

使用LuaFunction (性能差)

LuaFunction add = luaenv.Global.Get<LuaFunction>("add");object[] objects = add.Call(3, 5);print(objects[0]);
http://www.yayakq.cn/news/246984/

相关文章:

  • 阳泉做网站公司上海网站seo排名优化
  • 简述制作网站的流程推广网站文案素材
  • 苏州专业做网站的公司lanyun网站开发
  • 学交互设计网站安徽省住房和城乡建设厅证件查询
  • 如何开通企业邮箱一键优化win10
  • 建站之星安装模板失败宁波静态网站建设
  • 哈尔滨专业做网站建设品牌网站的好处
  • 陕西网站制作公司哪家好专业做曝光引流网站
  • 阜宁网站制作收费在线咨询天津建设工程信息网滨海时报
  • 宁波网站建设建站系统福州企业网站维护价格低
  • 深圳高端网站建设企业网站建设方法
  • 哪里有免费的网站模板下载 迅雷下载软件关键词点击优化工具
  • 怎么做网站外链接北京市朝阳区网站制作
  • 泉州企业网站制作上海工信部网站备案
  • 海口seo整站wordpress 4.4.3下载
  • 手机域名注册网站北京南站地铁几号线
  • 四川省建设工程质量安全网站wordpress 格子主题
  • 汕头网站建设推广费用做网站要固定电话
  • 1m的带宽做网站可以吗网站跳出率一般是多少
  • 国内网页做的好看的网站选服务好的网站建设公
  • 南京学习网站建设本人有资金寻求合作
  • 本溪 网站建设 做网站杭州做宠物网站的公司哪家好
  • 网站实名认证中心上海做网站hlanggroup
  • 东莞公司网站岑溪网络推广营销
  • 静态页面网站站标代码写进到静态页面了 怎么不显示呢?哪里可以免费推广广告
  • 用自己电脑做网站服务器-phpstudy+花生壳网页推广怎么收取费用
  • 新塘网站seo优化门户网站如何做seo
  • 深圳网站公司好信阳网站网站建设
  • 网站会员充值做哪个分录建设移动门户
  • 网站手机端怎么做js 访问wordpress