热更新
如热更新果需要更换UI显示,或者修改游戏的逻辑,这个时候,如果不使用热更新,就需要重新打包,然后让玩家重新下载(浪费流量和时间,体验不好)。热更新可以在不重新下载客户端的情况下,更新游戏的内容。
(1)热更新的实现方式
1,使用Lua脚本编写游戏的UI或者其他的逻辑
Lua是一个精悍小巧的脚本语言,可以跨平台运行解析,而且不需要编译的过程
2,使用C#Light
3,使用C#反射技术
(2)在所有的热更新技术中都需要AssetBundle
Unity提供了一个资源更新技术,就是通过AssetBundle,我们可以通过AssetBundle更新游戏UI,也可以把脚本或者其他代码当成资源打包成AssetBundle然后更新到客户端。
(3)热更新技术的学习过程
1,学习Lua编程
2,学习通过LuaInterface和luanet进行Lua和C#的交互通信
3,学习使用AssetBundle进行资源更新
4,学习uLua SimpleFramework
利用us创建自己的热更新游戏
Lua编程的学习
(0)编写程序
1,找到luaforwindows的安装目录,找到SciTE
2,打开SciTE,写入第一行Lua代码
print("Hello World")
3,保存代码,保存为HelloWorld.lua
4,按下F5运行
(1)程序分析
Lua中每一条语句后面是没有;号的
(2)定义变量
num = 100
这里定义了一个全局变量叫做num,赋值为100
在Lua中定义变量是没有类型的,根据存储什么数据,来决定是什么类型
(3)注释
1,单行注释 --注释内容
2,多行注释 --[[ 这里是注释内容 ]]--
(4)Lua中变量类型
4,number小数类型(Lua中没有整数类型)
5,table表类型
myTable = {34,134,34,2,342,4}
myTable[2],表示134,索引是从1开始的。
我们可以使用type()来取得一个变量的类型
(5) 流程控制
-- if语句
1, if [condition] then
end
2, if [condition] then
else
end
3, if [condition] then
elseif [condition] then
else
end
-- while循环
![](http://upload-images.jianshu.io/upload_images/3605723-b486bad9aaac14ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/141/format/webp)
![](http://upload-images.jianshu.io/upload_images/3605723-d55de32116148ad5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/133/format/webp)
--repeat循环(do while)
![](http://upload-images.jianshu.io/upload_images/3605723-0dc2845da864432e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/86/format/webp)
![](http://upload-images.jianshu.io/upload_images/3605723-82207e97b56a0de8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/85/format/webp)
![](http://upload-images.jianshu.io/upload_images/3605723-792428796787e7ad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/121/format/webp)
--for循环
![](http://upload-images.jianshu.io/upload_images/3605723-2276ba92c9ad66a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/100/format/webp)
break可以终止循环 没有continue语法
(6)函数(方法)
![](http://upload-images.jianshu.io/upload_images/3605723-01a78685a5d07f52.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/421/format/webp)
![](http://upload-images.jianshu.io/upload_images/3605723-ef22d9042d0de5ef.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/153/format/webp)
--标准库
1,数学处理的math相关函数
2,字符串处理的string相关函数
![](http://upload-images.jianshu.io/upload_images/3605723-fc5f4b8bb206c809.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/439/format/webp)
3,表处理的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"]
4...table的第二种创建方式
myTable = {name="taikr",age=18,isMan = false}
(表创建之后依然可以添加数据)
数据访问
myTable.name
myTable["name"]
5...table的第三种方式(类似数组的使用)
myTable = {34,34,34,3,4,"sdfdsf"}
当没有键的时候,编译器会默认给每一个值,添加一个数字的键,该键从1开始
6...表的遍历
(1),如果是只有数字键,并且是连续的可以使用下面的遍历
![](http://upload-images.jianshu.io/upload_images/3605723-40ca9751acb7eed4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/248/format/webp)
(2),所有的表都可以通过下面的方式遍历
![](http://upload-images.jianshu.io/upload_images/3605723-d2bef414bb0d4c3e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/251/format/webp)
7...表相关的函数
(1).table.concat (只针对只有值的情况)
把表中所有数据连成一个字符串
![](http://upload-images.jianshu.io/upload_images/3605723-eefcc0793667549d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/158/format/webp)
(2),table.insert
向指定位置插入一个数据
![](http://upload-images.jianshu.io/upload_images/3605723-c9250165b30b843d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/376/format/webp)
(3),table.move
移动数据
![](http://upload-images.jianshu.io/upload_images/3605723-91071b22e1437e0c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/135/format/webp)
(4),table.sort(从小到大排列的)
排序
![](http://upload-images.jianshu.io/upload_images/3605723-f132634f1d8c2b43.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/167/format/webp)
8...通过表来实现面向对象
myTable={} 申明对象
local this = myTable声明this关键字代表当前对象
--定义并声明对象中的属性
myTable.name="siki"
myTable.age = 110
--定义并声明对象中的方法
myTable.function = function ()
[code to execute]
end
function myTable.function ()
[code to execute]
end
![](http://upload-images.jianshu.io/upload_images/3605723-aac349f2eb2c3e22.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/307/format/webp)