UGCProjects/GZJ/Script/Global/TableHelper.lua
2025-01-08 22:46:12 +08:00

57 lines
1.4 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

TableHelper = TableHelper or {}
function TableHelper.DeepCopy(obj)
local InTable = {};
local function Func(obj)
if type(obj) ~= "table" then --判断表中是否有表
return obj;
end
local NewTable = {}; --定义一个新表
InTable[obj] = NewTable; --若表中有表则先把表给InTable再用NewTable去接收内嵌的表
for k,v in pairs(obj) do --把旧表的key和Value赋给新表
NewTable[Func(k)] = Func(v);
end
return setmetatable(NewTable, getmetatable(obj))--赋值元表
end
return Func(obj) --若表中有表,则把内嵌的表也复制了
end
function TableHelper.DeepCopyTable(TableData)
if TableData == nil then
return {}
end
local TmpTab = {}
for k, v in pairs(TableData) do
if type(v) == "table" then
local SubTab = TableHelper.DeepCopyTable(v)
TmpTab[k] = SubTab
else
TmpTab[k] = v
end
end
return TmpTab
end
function TableHelper.GetName(Actor)
if UE.IsValid(Actor) then
return UE.GetPathName(Actor)
elseif Actor ~= nil then
return type(Actor)
end
return "[NullActor]"
end
function TableHelper.Contains(tab, val)
for i, Val in pairs(tab) do
if Val == val then
return true
end
end
return false
end
return TableHelper