29.xLua热补丁-泛型类替换
29.1 知识点
准备工作
准备泛型类并设置一个泛型函数
[Hotfix]
public class Lesson29_Test<T>
{
public void Test(T t)
{
Debug.Log(t);
}
}
启动Lua脚本并且调用泛型类的函数
LuaManager.Instance.Init();
LuaManager.Instance.DoLuaFile("Lesson29_xLua热补丁_泛型类替换");
Lesson29_Test<string> t1 = new Lesson29_Test<string>();
t1.Test("韬老师");
Lesson29_Test<int> t2 = new Lesson29_Test<int>();
t2.Test(666);
泛型类替换
- 泛型类替换:类名的括号传入类型
xlua.hotfix(CS.Lesson29_Test(CS.System.String), {
Test = function(self, t)
print("泛型类替换:"..t)
end
})
xlua.hotfix(CS.Lesson29_Test(CS.System.Int32), {
Test = function(self, t)
print("泛型类替换:"..t)
end
})
29.2 知识点代码
Lesson29_xLua热补丁_泛型类替换.lua
print('我是Lua脚本 Lesson29_xLua热补丁_泛型类替换')
print("*********知识点一 泛型类替换***********")
-- 泛型类替换 类名的括号传入类型
xlua.hotfix(CS.Lesson29_Test(CS.System.String), {
Test = function(self, t)
print("泛型类替换:"..t)
end
})
xlua.hotfix(CS.Lesson29_Test(CS.System.Int32), {
Test = function(self, t)
print("泛型类替换:"..t)
end
})
Lesson29_xLua热补丁_泛型类替换
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;
public class Lesson29_xLua热补丁_泛型类替换 : MonoBehaviour
{
void Start()
{
LuaManager.Instance.Init();
LuaManager.Instance.DoLuaFile("Lesson29_xLua热补丁_泛型类替换");
Lesson29_Test<string> t1 = new Lesson29_Test<string>();
t1.Test("韬老师");
Lesson29_Test<int> t2 = new Lesson29_Test<int>();
t2.Test(666);
}
}
[Hotfix]
public class Lesson29_Test<T>
{
public void Test(T t)
{
Debug.Log(t);
}
}
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 785293209@qq.com