当前位置: 首页 > 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/809048/

相关文章:

  • 网站开发需要什么软件有哪些东莞百度seo排名
  • 谢岗镇网站仿做wordpress 适配 手机
  • 办网站租服务器招标网公告
  • 局机关门户网站建设情况汇报影视网站开发背景
  • 免费注册一个网站flash制作网站top
  • 外贸网站装修网站建设多少预算
  • 网站建设项目体会陕西省建设监理协会官网站
  • 网站正在建设中的代码平台制作专业网站制作
  • 网站建设沈阳长春网站建设产品展示
  • 营销型网站建设需要注意什么建设银行网站点击次数
  • 网站搭建平台多少钱黎平网站开发
  • 专门做验收报告的网站wordpress研究
  • 潍坊市安丘建设局网站企业网站资料大全
  • 中文企业网站模板html开发一个简单的系统
  • 南宁制作企业网站大型门户网站系统
  • 站长之家的seo综合查询工具aws使用wordpress
  • 无锡网站排名团队延吉网站建设彩票
  • 凡科建站添加文章263企业邮箱登录口
  • 网站的关键词多少合适梅州在建高铁最新消息
  • 广州网站建设新锐重庆优化网站排名
  • 作为一个大学生网站 应该怎么做常州 招网站开发
  • 网站建设主要产品全国建设项目竣工验收公示网站
  • 网站建设的分析百度投诉中心24小时电话
  • 网站建设淮南免费公司网站模版
  • 网站建设的方法小米网站设计
  • 如何将数据写入wordpress文站成全高清视频免费观看
  • 做品牌形象网站苏州新区城乡建设网站
  • 阿里云网站域名查询如何自己建立网站建设
  • 怎么做网站免费优化做化工的外贸网站都有什么地方
  • 广州网站建设gzzhixunit行业是什么工作 做什么的