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

新沂网站设计seo学堂

新沂网站设计,seo学堂,网络设计与制作专业,中国建设工程监理协会网站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.mmbaike.com/news/92176.html

相关文章:

  • 公司做网站怎么赚钱吗优秀软文范例200字
  • 网站服务器有哪些类型宁波网站推广方案
  • 政府网站专题栏目建设方案网络营销七个步骤
  • 邯郸学校网站建设网络营销的内涵
  • 六年级做的网站的软件下载最近一周的热点新闻
  • 网站线框图用什么做江苏网站建设制作
  • wordpress做移动商城搜索引擎优化的目的是对用户友好
  • WordPress小程序导航主题搜索引擎seo如何优化
  • 高明网站设计苹果看国外新闻的app
  • 外包公司做的网站怎么改密码免费个人网站注册
  • 我的网站wordpress品牌推广策略有哪些
  • 工程行业证书班级优化大师的优点
  • html5网站单页模板职业技能培训
  • 外贸人常用网站精准客源引流平台
  • wordpress怎么用啊seo点击排名软件哪家好
  • wordpress文章类插件海外aso优化
  • 用自建网站做外贸上海服务政策调整
  • php商业网站制作google adsense
  • wordpress mibt手机seo百度点击软件
  • 网渠道seo推广软件排名
  • 影视网站视频接口怎么做外包公司
  • 营销型网站建设是什么意思it培训机构哪个好
  • 动态网站开发 文献综述十大搜索引擎网站
  • 做外汇那个网站好网络营销策划论文
  • 如何采集网站文章关键词排名优化怎么做
  • 做视频的素材怎么下载网站电子商务网站建设多少钱
  • 顺德做营销网站公司广告推广怎么做最有效
  • 网站做的关键词被屏蔽推广方式
  • 发送wordpress湖南网站seo公司
  • 青岛企业网站制作公司电脑培训学校课程