miduo_client/Assets/ManagedResources/~Lua/misc/functions_lua.lua

98 lines
2.9 KiB
Lua
Raw Normal View History

2020-05-09 13:31:21 +08:00
local require = require
local string = string
local table = table
int64.zero = int64.new(0,0)
uint64.zero = uint64.new(0,0)
function string.split(input, delimiter)
input = tostring(input)
delimiter = tostring(delimiter)
if (delimiter=='') then return false end
local pos,arr = 0, {}
-- for each divider found
for st,sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(input, pos))
return arr
end
function import(moduleName, currentModuleName)
local currentModuleNameParts
local moduleFullName = moduleName
local offset = 1
while true do
if string.byte(moduleName, offset) ~= 46 then -- .
moduleFullName = string.sub(moduleName, offset)
if currentModuleNameParts and #currentModuleNameParts > 0 then
moduleFullName = table.concat(currentModuleNameParts, ".") .. "." .. moduleFullName
end
break
end
offset = offset + 1
if not currentModuleNameParts then
if not currentModuleName then
local n,v = debug.getlocal(3, 1)
currentModuleName = v
end
currentModuleNameParts = string.split(currentModuleName, ".")
end
table.remove(currentModuleNameParts, #currentModuleNameParts)
end
return require(moduleFullName)
end
--重新require一个lua文件替代系统文件。
function reimport(name)
local package = package
package.loaded[name] = nil
package.preload[name] = nil
return require(name)
end
2021-03-04 19:29:15 +08:00
function GetPreferredHeight(_transform)
2021-03-04 19:29:15 +08:00
ForceRebuildLayout(_transform)
return LayoutUtility.GetPreferredHeight(_transform)
end
function GetPreferredWidth(_transform)
2021-03-04 19:29:15 +08:00
ForceRebuildLayout(_transform)
return LayoutUtility.GetPreferredWidth(_transform)
end
2021-03-04 19:29:15 +08:00
function ForceRebuildLayout(_transform)
2021-03-10 14:56:53 +08:00
if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.LayoutBuilderWrap)
or ServerConfigManager.GetSDKVersionCode() >= 25
then
2021-03-04 19:29:15 +08:00
if not LayoutRebuilder then
LayoutRebuilder = UnityEngine.UI.LayoutRebuilder
end
LayoutRebuilder.ForceRebuildLayoutImmediate(_transform)
end
end
function LoadStreamingTexture(spLoader, name, func)
if name and name ~= "" and func then
2021-06-16 17:29:17 +08:00
if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.IS_LOAD_STREAMING) then
resMgr:LoadStreamingTexture(name, function(sp)
if sp then
func(sp)
else
name = string.split(name, ".")[1]
local sp = spLoader:LoadSprite(name)
func(sp)
end
end)
else
name = string.split(name, ".")[1]
local sp = spLoader:LoadSprite(name)
func(sp)
end
end
end