Lua热更新基础语法

1,什么是热更新

  热更新可以在不重新下载客户端的情况下,更新游戏的内容。

2,为什么C#脚本不可以直接更新

  C#运行前需要编译dll文件,这个编译的过程在移动平台无法完成

3,什么是AssetBundle

    资源更新技术,就是通过AssetBundle,我们可以通过AssetBundle更新游戏UI,也可以把脚本或者其他代码当成资源打包成     AssetBundle然后更新到客户端。

    Lua是一个精悍小巧的脚本语言,可以跨平台运行解析,而且不需要编译的过程

4,如何利用Lua进行热更新

   在移动端可以编写Lua的解析器,通过这个解析器,可以运行最新的Lua脚本,然后我们把控制游戏逻辑的代码都写成Lua脚本

5,如何学习热更新技术

   1,学习Lua编程

   2,学习通过LuaInterface和luanet进行Lua和C#的交互通信

   3,学习使用AssetBundle进行资源更新

   4,学习uLua SimpleFramework

6,Lua是个什么东东 

  设计目的是为了嵌入应用程序中,从而为应用程序提供灵活的扩展和定制功能,

  Lua有一个同时进行的JIT项目,提供在特定平台上的即时编译功能。

  

  Luaforwindows 

   http://luaforwindows.luaforge.net/

   (可安装的exe文件,一整套的Lua开发环境,有Lua的解释器,参考手册,范例和库,文档,和编辑器) 

  lua安装目录下打开  SciTE.exe,lua文件的后缀为.lua,按下F5运行

7,如何定义变量

  num= 100

  在Lua中定义变量是没有类型的,根据存储什么数据,来决定是什么类型

如何添加注释

1,单行注释--注释内容

2,多行注释  --[[ 这里是注释内容 ]]--

Lua中变量类型如下:

1,nil表示空数据,等同于null

2,boolean布尔类型,存储true和false

3,string字符串类型,字符串可以用双引号也可以使用单引号表示

4,number小数类型(Lua中没有整数类型)

5,table表类型

  myTable = {34,,34,2,342,4}

  myTable[3]

我们可以使用type()来取得一个变量的类型

注意事项

默认定义的变量都是全局的,定义局部变量需要在前面加一个local;

在代码块中声明的局部变量,当代码块运行结束的时候,这个变量就会被释放;

temp= 34

local var = 345

if语句的用法

local hp = 40
if hp<=0 then
	print("role is die")
elseif hp>=50 then
	print("role is good")
else
	print("role is bad")
end

循环结构while循环

index = 1
while index<=100 do
	print(index)
	index=index+1
end

循环结构repeat循环

repeat
	print(index)
	index=index+1
until index>100

for循环结构

sum = 0

for index = 1,100 do
	sum=sum+index
end
print(sum)

函数(方法)

function Plus(num1,num2)
	return num1+num2
end

res  = Plus(34,45)
print(res)

数学运算函数

   math.abs                        --  取绝对值

   math.cos                        --取三角函数

   math.max

   math.maxinteger

   math.min

   math.random

   math.sin

   math.sqrt

   math.tan

字符串处理相关函数

   string.byte

   string.char

   string.find

   sting.format

   string.lower

   string.sub

   string.upper

   ..字符串相加

   tostring()  把一个数字转化成字符串

   tonumber()把一个字符串转化成数字

table 表

   在Lua中的table类似C#中的字典,其实就是一个 key-value键值对的数据结构。

  1,table的创建

    myTable = {}

    表名后面使用{}赋值,表示一个空的表

  2,table的赋值

     myTable[3]=34 当键是一个数字的时候的赋值方式

     myTable["name"]="taikr"当键是一个字符串的赋值方式

     myTable.name = "siki"当键是一个字符串的赋值方式

  3,table的访问

  myTable[3] 当键是数字的时候,只有这一种访问方式

  myTable.name 当键是字符串的时候有两种访问方式

  myTable["name"]

表相关的函数

1.table.concat,把表中所有数据连成一个字符串

2,table.insert,向指定位置插入一个数据

3,table.move,移动数据

4,table.pack,包装成一个表

5,table.remove,移除指定位置的数据

6,table.sort,排序

7,table.unpack,返回一个数组,指定范围的数组

--[[
myTable={}
myTable[1]=34
myTable[3]="sdf"

myTable["name"] = "taikr"
myTable.name = "siki"

print(myTable[1] ,myTable.name,myTable["name"] )


myTable = {name="taikr",age=18,isMan = false}

myTable.school = "泰课在线"

print(myTable.isMan,myTable.school )
]]--

--scores = {34,56,123,6734,23}
--print( scores[1] )

--for index=1,table.getn(scores) do
	--print( scores[index] )
--end

--[[
myTable = {name="taikr",age=18,isMan = false}

for index,value in pairs(myTable) do
print(index,value)
end
]]--
myTable = {name="taikr",age=18,isMan = false}
scores = {34,56,123,6734,23}
table.insert( myTable,2,2 ) -- myTable[2]=2
table.remove(scores,3)
table.sort(scores)
print( table.concat(scores))

猜你喜欢

转载自blog.csdn.net/qq_35647121/article/details/81052157