1. xlua之将c#集合转换成table
-- 将c#的list转换成table
local function ConvertCSListToTable(list)
local t = {};
for i = , list.Count - do
table.insert(t, list[i]);
end
return t;
end -- 将c#的数组转换成table
local function ConvertCSArrayToTable(array)
local t = {};
for i = , array.Length - do
table.insert(t, array[i]);
end
return t;
end -- 将c#的字典转换成table
local function ConvertCSDicToTable(dic)
local t = {};
local etor = dic:GetEnumerator(); while (etor:MoveNext())
do
local current = etor.Current;
local k = current.Key;
local v = current.Value;
table.insert(t, {k, v});
end return t;
end
2. 分割字符串
-- 分割字符串
function this.Split(input, delimiter)
input = tostring(input);
delimiter = tostring(delimiter); if (delimiter == "") then
return false;
end local pos,arr = , {};
for st,sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - ));
pos = sp + ;
end
table.insert(arr, string.sub(input, pos));
return arr;
end
3. 判断 unity3d 中 GameObject 是否为 null
详见:https://blog.****.net/qq_34907362/article/details/80482493
function IsNil(uobj)
return uobj == nil or uobj:Equals(nil)
end
4. xlua之与c#枚举器的关系
小鱼人(692540236) 13:20:32
xlua中我如果想跟c#中一样去启动新协程,等新协程结束再执行后面的逻辑,怎么弄啊?
|
Home_to_the_mold(383894728) 13:45:33
-- HotFix.UIRankMainTest.lua
-- 模拟Lua侧的异步回调 local function lua_async_test(seconds, coroutine_break) print('lua_async_test '..seconds..' seconds!') -- TODO:这里还是用Unity的协程相关API模拟异步,有需要的话再考虑在Lua侧实现一个独立的协程系统 yield_return(CS.UnityEngine.WaitForSeconds(seconds)) coroutine_break(true, seconds) end -- lua侧新建协程:本质上是在Lua侧建立协程,然后用异步回调驱动, -- 协程热更示例 -- cs侧协程热更 |