This commit is contained in:
2020-07-04 14:41:25 +08:00
parent 70c346d2c1
commit a8f02e4da5
3748 changed files with 587372 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
--与 同为1则为1
--或 有一个为1则为1
--非 true为 false其余为true
--异或 相同为0不同为1
BitUtl = {}
local __andBit = function(left, right) --与
return (left == 1 and right == 1) and 1 or 0
end
local __orBit = function(left, right) --或
return (left == 1 or right == 1) and 1 or 0
end
local __xorBit = function(left, right) --异或
return (left + right) == 1 and 1 or 0
end
local __base = function(left, right, op) --对每一位进行op运算然后将值返回
if left < right then
left, right = right, left
end
local res = 0
local shift = 1
while left ~= 0 do
local ra = left % 2 --取得每一位(最右边)
local rb = right % 2
res = shift * op(ra, rb) + res
shift = shift * 2
left = math.modf(left / 2) --右移
right = math.modf(right / 2)
end
return res
end
---@public 与
function BitUtl.andOp(left, right)
return __base(left, right, __andBit)
end
---@public 或
function BitUtl.orOp(left, right)
return __base(left, right, __orBit)
end
---@public 异或
function BitUtl.xorOp(left, right)
return __base(left, right, __xorBit)
end
---@public 非
function BitUtl.notOp(left)
return left > 0 and -(left + 1) or -left - 1
end
---@public left左移num位
function BitUtl.lShiftOp(left, num)
return left * (2 ^ num)
end
---@public right右移num位
function BitUtl.rShiftOp(left, num)
return math.floor(left / (2 ^ num))
end
return BitUtl

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 09160cd2c28cb4819a89a1faa7d789bf
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,107 @@
LogLev = {
error = 1,
warning = 2,
debug = 3,
}
local logLev = LogLev.debug
local logBackTraceLev = -1
local select = select
local table = table
local smatch = string.match
local sfind = string.find
---@public 设置日志等级分别是debugwarningerror
function setLogLev(val)
logLev = val or LogLev.debug
end
---@public 设置日志的调用栈信息
function setLogBackTraceLev(lev)
logBackTraceLev = lev
if logBackTraceLev > 0 and logBackTraceLev < 3 then
logBackTraceLev = 3
end
end
local strSplit = function(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {};
local i = 1
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
t[i] = str
i = i + 1
end
return t;
end
local trim = function(s)
-- return (s:gsub("^%s*(.-)%s*$", "%1"))
return smatch(s, '^()%s*$') and '' or smatch(s, '^%s*(.*%S)') -- 性能略优
end
local parseBackTrace = function(traceInfor, level)
if traceInfor and level > 1 then
local traces = strSplit(traceInfor, "\n")
if #traces >= level then
local str = trim(traces[level])
local sList = strSplit(str, ":")
local file = sList[1]
local line = sList[2]
local func = sList[3] or ""
--file = string.match(file, "/%a+%.%a+") or ""
func = string.match(func, "'%a+'") or ""
return file .. ":" .. line .. ":" .. func
end
else
return traceInfor or ""
end
end
local wrapMsg = function (...)
local tb = {}
local v
for i = 1, select("#", ...) do
v = select(i, ...)
if v or type(v) == "boolean" then
table.insert(tb, tostring(v))
else
table.insert(tb, "nil")
end
end
return table.concat(tb, "|")
end
local luaprint = print
function print(...)
if logLev < LogLev.debug then
return
end
local trace = debug.traceback("")
local msg = wrapMsg(...)
msg = msg or ""
luaprint("[debug]:" .. msg .. "\n" .. parseBackTrace(trace, logBackTraceLev))
end
function printw(...)
if logLev < LogLev.warning then
return
end
local trace = debug.traceback("")
local msg = wrapMsg(...)
msg = msg or ""
Utl.printw("[warn]:" .. msg .. "\n" .. parseBackTrace(trace, logBackTraceLev))
end
function printe(...)
if logLev < LogLev.error then
return
end
local trace = debug.traceback("")
local msg = wrapMsg(...)
msg = msg or ""
Utl.printe("[err]:" .. msg .. "\n" .. parseBackTrace(trace, logBackTraceLev))
end

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 79512f5f72b0f48e9bb3aedf9f0bc261
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,147 @@
--[[
-- 更新热更器处理
-- 判断热更新器本身是不是需要更新,同时判断渠道配置是否要更新
--]]
do
---@type System.Collections.Hashtable
local localVer = Hashtable();
---@type System.Collections.Hashtable
local serverVer = Hashtable();
local serverVerStr = "";
-- 热更新器的版本
local upgraderVer = "upgraderVer.json";
local localVerPath = upgraderVer;
--local upgraderName = PStr.b():a(CLPathCfg.self.basePath):a("/upgradeRes/priority/lua/toolkit/CLLVerManager.lua"):e();
local upgraderName = "preUpgradeList";
-- 控制渠道更新的
local channelName = "channels.json";
local finishCallback = nil; -- finishCallback(isHaveUpdated)
local isUpdatedUpgrader = false; -- 是否更新的热更新器
----------------------------------
CLLUpdateUpgrader = {};
function CLLUpdateUpgrader.checkUpgrader(ifinishCallback)
isUpdatedUpgrader = false;
finishCallback = ifinishCallback;
CLVerManager.self:StartCoroutine(FileEx.readNewAllTextAsyn(localVerPath, CLLUpdateUpgrader.onGetLocalUpgraderVer));
end
function CLLUpdateUpgrader.onGetLocalUpgraderVer(content)
localVer = JSON.DecodeMap(content);
if (localVer == nil) then
localVer = Hashtable();
end
local url = PStr.b():a(CLVerManager.self.baseUrl):a("/"):a(upgraderVer):e();
url = Utl.urlAddTimes(url);
WWWEx.get(url, CLAssetType.text,
CLLUpdateUpgrader.onGetServerUpgraderVer,
CLLUpdateUpgrader.onGetServerUpgraderVer, nil, true);
end
function CLLUpdateUpgrader.onGetServerUpgraderVer(content, orgs)
serverVerStr = content;
serverVer = JSON.DecodeMap(content);
serverVer = serverVer == nil and Hashtable() or serverVer;
-- print("MapEx.getInt(localVer, upgraderVer)==" .. MapEx.getInt(localVer, "upgraderVer"))
-- print("MapEx.getInt(serverVer, upgraderVer)==" .. MapEx.getInt(serverVer, "upgraderVer"))
if (MapEx.getString(localVer, "upgraderVer") ~= MapEx.getString(serverVer, "upgraderVer")) then
CLLUpdateUpgrader.updateUpgrader();
else
CLLUpdateUpgrader.checkChannelVer(false);
end
end
function CLLUpdateUpgrader.updateUpgrader(...)
local url = "";
local verVal = MapEx.getString(serverVer, "upgraderVer");
url = PStr.b():a(CLVerManager.self.baseUrl):a("/"):a(upgraderName):a("."):a(verVal):e();
WWWEx.get(url, CLAssetType.text,
CLLUpdateUpgrader.ongetNewestPreupgradList,
CLLUpdateUpgrader.ongetNewestPreupgradList,
upgraderName, true);
end
function CLLUpdateUpgrader.ongetNewestPreupgradList(content, orgs)
if (content ~= nil) then
local preupgradList = JSON.DecodeList(content)
if preupgradList == nil or preupgradList.Count == 0 then
CLLUpdateUpgrader.checkChannelVer(false);
else
CLLUpdateUpgrader.loadServerRes({ preupgradList, 0 })
end
else
CLLUpdateUpgrader.checkChannelVer(false);
end
end
function CLLUpdateUpgrader.loadServerRes(orgs)
local list = orgs[1]
local i = orgs[2]
if i >= list.Count then
-- 完成
CLLUpdateUpgrader.checkChannelVer(true);
else
local cell = list[i];
local name = cell[0]
local ver = cell[1]
local url = PStr.b():a(CLVerManager.self.baseUrl):a("/"):a(name):a("."):a(ver):e();
WWWEx.get(url, CLAssetType.bytes,
CLLUpdateUpgrader.ongetNewestUpgrader,
CLLUpdateUpgrader.ongetNewestUpgrader, { list, i, name }, true);
end
end
function CLLUpdateUpgrader.ongetNewestUpgrader(content, orgs)
local list = orgs[1]
local i = orgs[2]
local fileName = orgs[3]
if (content ~= nil) then
local file = PStr.begin():a(CLPathCfg.persistentDataPath):a("/"):a(fileName):e();
FileEx.CreateDirectory(Path.GetDirectoryName(file));
File.WriteAllBytes(file, content);
else
printe(joinStr(fileName , "get content == nil"));
end
CLLUpdateUpgrader.loadServerRes({ list, i + 1 })
end
-- 取得最新的渠道更新控制信息
function CLLUpdateUpgrader.checkChannelVer(hadUpdatedUpgrader)
isUpdatedUpgrader = hadUpdatedUpgrader;
if (MapEx.getInt(localVer, "channelVer") < MapEx.getInt(serverVer, "channelVer")) then
CLLUpdateUpgrader.getChannelInfor();
else
CLLUpdateUpgrader.finished()
end
end
function CLLUpdateUpgrader.getChannelInfor(...)
local verVal = MapEx.getInt(serverVer, "channelVer");
-- 注意是加了版本号的会使用cdn
local url = PStr.b():a(CLVerManager.self.baseUrl):a("/"):a(channelName):a("."):a(verVal):e();
WWWEx.get(url, CLAssetType.text,
CLLUpdateUpgrader.onGetChannelInfor,
CLLUpdateUpgrader.onGetChannelInfor, channelName, true);
end
function CLLUpdateUpgrader.onGetChannelInfor(content, orgs)
if (content ~= nil) then
local file = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(channelName):e();
FileEx.CreateDirectory(Path.GetDirectoryName(file));
File.WriteAllText(file, content);
end
CLLUpdateUpgrader.finished()
end
function CLLUpdateUpgrader.finished()
if isUpdatedUpgrader then
local file = PStr.begin():a(CLPathCfg.persistentDataPath):a("/"):a(localVerPath):e();
File.WriteAllText(file, serverVerStr);
end
Utl.doCallback(finishCallback, isUpdatedUpgrader);
end
end
--module("CLLUpdateUpgrader", package.seeall)

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9ede2434ae7594f25af812b9d591d734
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,519 @@
-- 资源更新器
--//TODO:1可能考虑把共公部分路径抽取出来以减少配置文件的容量2语言文件考虑增量更新的方式避免改一点点更新整个文件语言文件还是挺大的
-- 服务器
local csSelf = CLVerManager.self
local baseUrl = CLVerManager.self.baseUrl --"http://gamesres.ultralisk.cn/cdn/test";
local platform = ""
local newestVerPath = "newestVers"
local resVer = "resVer"
local versPath = "VerCtl"
local fverVer = "VerCtl.ver" --本地所有版本的版本信息
---@type System.Collections.Hashtable
local localverVer = Hashtable()
---@type System.Collections.Hashtable
local serververVer = Hashtable()
--========================
local verPriority = "priority.ver"
---@type System.Collections.Hashtable
local localPriorityVer = Hashtable() --本地优先更新资源
---@type System.Collections.Hashtable
local serverPriorityVer = Hashtable() --服务器优先更新资源
local verOthers = "other.ver"
---@type System.Collections.Hashtable
local otherResVerOld = Hashtable() --所有资源的版本管理
---@type System.Collections.Hashtable
local otherResVerNew = Hashtable() --所有资源的版本管理
local tmpUpgradePirorityPath = "tmpUpgrade4Pirority"
local haveUpgrade = false
local is2GNetUpgrade = CLVerManager.self.is2GNetUpgrade
local is3GNetUpgrade = CLVerManager.self.is3GNetUpgrade
local is4GNetUpgrade = CLVerManager.self.is4GNetUpgrade
local onFinishInit = nil
local progressCallback = nil
local mVerverPath = ""
local mVerPrioriPath = ""
local mVerOtherPath = ""
---@type System.Collections.Hashtable
local needUpgradeVerver = Hashtable()
local progress = 0
local isNeedUpgradePriority = false
local needUpgradePrioritis = Queue()
local isSucessUpgraded = false
local verVerMD5 = ""
CLLVerManager = {}
-- 更新初始化
--[[
iprogressCallback: 进度回调,回调有两个参数
ifinishCallback: 完成回调
isdoUpgrade: 是否做更新处理
--]]
function CLLVerManager.init(iprogressCallback, ifinishCallback, isdoUpgrade, _verVerMD5)
haveUpgrade = false
verVerMD5 = _verVerMD5
CLVerManager.self.haveUpgrade = false
isNeedUpgradePriority = false
localverVer:Clear()
serververVer:Clear()
localPriorityVer:Clear()
serverPriorityVer:Clear()
otherResVerOld:Clear()
otherResVerNew:Clear()
platform = CLPathCfg.self.platform
CLVerManager.self.platform = platform
mVerverPath = PStr.begin():a(CLPathCfg.self.basePath):a("/"):a(resVer):a("/"):a(platform):a("/"):a(fverVer):e()
mVerPrioriPath =
PStr.begin():a(CLPathCfg.self.basePath):a("/"):a(resVer):a("/"):a(platform):a("/"):a(versPath):a("/"):a(
verPriority
):e()
mVerOtherPath =
PStr.begin():a(CLPathCfg.self.basePath):a("/"):a(resVer):a("/"):a(platform):a("/"):a(versPath):a("/"):a(
verOthers
):e()
CLVerManager.self.mVerverPath = mVerverPath
CLVerManager.self.mVerPrioriPath = mVerPrioriPath
CLVerManager.self.mVerOtherPath = mVerOtherPath
progressCallback = iprogressCallback
onFinishInit = ifinishCallback
if (not isdoUpgrade) then
CLLVerManager.loadPriorityVer()
-- 后面会调用onFinish的回调
CLLVerManager.loadOtherResVer(true)
return
end
--[[*
/// None 无网络
/// WiFi
/// 2G
/// 3G
/// 4G
/// Unknown
*/
--]]
local netState = Utl.getNetState()
local netActived = true
if (netState == "None") then
netActived = false
elseif (netState == "2G") then
if (not is2GNetUpgrade) then
netActived = false
end
elseif (netState == "3G") then
if (not is3GNetUpgrade) then
netActived = false
end
elseif (netState == "4G") then
if (not is4GNetUpgrade) then
netActived = false
end
elseif (netState == "WiFi") then
netActived = true
elseif (netState == "Unknown") then
netActived = true
end
local canDoUpgrade = false
if (platform == "Android") then
if (not CLCfgBase.self.isEditMode and netActived) then
canDoUpgrade = true
end
else
if (not CLCfgBase.self.isEditMode and Utl.netIsActived()) then
canDoUpgrade = true
end
end
if (canDoUpgrade) then
canDoUpgrade = CLLVerManager.checkChannel()
if (canDoUpgrade) then
CLLVerManager.netWorkActived()
else
CLLVerManager.loadPriorityVer()
-- 后面会调用onFinish的回调
CLLVerManager.loadOtherResVer(true)
end
else
-- 说明是编辑器环境
Utl.doCallback(onFinishInit, true)
end
end
-- 验证渠道是否需要更新
function CLLVerManager.checkChannel()
local defaultReuslt = false
-- 先判断是否已经取得取渠道
local fpath = "channels.json"
-- 得渠道控制醘数据
local content = FileEx.readNewAllText(fpath)
local channels = nil
if (content ~= nil) then
channels = JSON.DecodeMap(content)
else
return defaultReuslt
end
-- 取得当前版本的渠道数据
fpath = "chnCfg.json" -- 该文在打包时会自动放在streamingAssetsPath目录下详细参见打包工具
content = FileEx.readNewAllText(fpath)
local chnCfg = nil
if (content ~= nil) then
chnCfg = JSON.DecodeMap(content)
else
return defaultReuslt
end
-- 取得当前包的渠道在渠道配置文件中是否有配置可更新
if (MapEx.getBool(channels, MapEx.getString(chnCfg, "SubChannel"))) then
return true
else
return false
end
return defaultReuslt
end
-- 验证网络是否可用
function CLLVerManager.netWorkActived()
local onCheckNetSateSuc = function(...)
CLVerManager.self:StartCoroutine(FileEx.readNewAllBytesAsyn(mVerverPath, CLLVerManager.onGetlcalVerverMap))
end
local onCheckNetSateFail = function(...)
printw("Cannot connect Server or Net !!!")
CLLVerManager.loadPriorityVer()
-- 后面会调用onFinish的回调
CLLVerManager.loadOtherResVer(false)
end
local url = Utl.urlAddTimes(PStr.b():a(baseUrl):a("/netState.txt"):e())
WWWEx.get(url, CLAssetType.text, onCheckNetSateSuc, onCheckNetSateFail, nil, true, 2)
end
--[[
/// <summary>
/// Ons the get verver map.取得本地版本文件的版本信息
/// </summary>
/// <param name='buff'>
/// Buff.
/// </param>
--]]
function CLLVerManager.onGetlcalVerverMap(buff)
if (buff ~= nil) then
localverVer = CLVerManager.self:toMap(buff)
else
localverVer = Hashtable()
end
CLLVerManager.getServerVerverMap()
end
--[[
/// <summary>
/// Gets the server verver map.取得服务器版本文件的版本信息
/// </summary>
--]]
function CLLVerManager.getServerVerverMap(...)
local url = ""
if CLCfgBase.self.hotUpgrade4EachServer then
-- 说明是每个服务器单独处理更新控制
url = PStr.begin():a(baseUrl):a("/"):a(mVerverPath):a("."):a(verVerMD5):e()
else
url = PStr.begin():a(baseUrl):a("/"):a(mVerverPath):e()
end
WWWEx.get(
Utl.urlAddTimes(url),
CLAssetType.bytes,
CLLVerManager.onGetServerVerverBuff,
CLLVerManager.onGetServerVerverBuff,
nil,
true,
2
)
end
function CLLVerManager.onGetServerVerverBuff(content, orgs)
if (content ~= nil) then
serververVer = CLVerManager.self:toMap(content)
else
serververVer = Hashtable()
end
--判断哪些版本控制信息需要更新
CLLVerManager.checkVervers()
end
function CLLVerManager.checkVervers()
progress = 0
needUpgradeVerver:Clear()
isNeedUpgradePriority = false
local ver = nil
local keysList = MapEx.keys2List(serververVer)
local count = keysList.Count
local key = ""
for i = 0, count - 1 do
key = keysList[i]
ver = MapEx.getString(localverVer, key)
if (ver == nil or ver ~= MapEx.getString(serververVer, key)) then
MapEx.set(needUpgradeVerver, key, false)
end
end
keysList:Clear()
keysList = nil
if (needUpgradeVerver.Count > 0) then
if (progressCallback ~= nil) then
progressCallback(needUpgradeVerver.Count, 0)
end
keysList = MapEx.keys2List(needUpgradeVerver)
count = keysList.Count
key = ""
for i = 0, count - 1 do
key = keysList[i]
CLLVerManager.getVerinfor(key, MapEx.getString(serververVer, key))
end
keysList:Clear()
keysList = nil
else
CLLVerManager.loadPriorityVer()
CLLVerManager.loadOtherResVer(true)
end
end
-- 取得版本文件
function CLLVerManager.getVerinfor(fPath, verVal)
local url = PStr.b():a(baseUrl):a("/"):a(fPath):a("."):a(verVal):e() -- 注意是加了版本号的可以使用cdn
WWWEx.get(url, CLAssetType.bytes, CLLVerManager.onGetVerinfor, CLLVerManager.onGetVerinfor, fPath, true, 2)
end
function CLLVerManager.onGetVerinfor(content, orgs)
if (content ~= nil) then
local fPath = orgs
progress = progress + 1
MapEx.set(localverVer, fPath, MapEx.getString(serververVer, fPath))
local fName = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(newestVerPath):a("/"):a(fPath):e()
if (Path.GetFileName(fName) == "priority.ver") then
-- 优先更新需要把所有资源更新完后才记录
isNeedUpgradePriority = true
serverPriorityVer = CLVerManager.self:toMap(content)
else
FileEx.CreateDirectory(Path.GetDirectoryName(fName))
File.WriteAllBytes(fName, content)
end
MapEx.set(needUpgradeVerver, fPath, true)
if (progressCallback ~= nil) then
progressCallback(needUpgradeVerver.Count, progress)
end
-- if (isFinishAllGet ()) then
if (needUpgradeVerver.Count == progress) then
if (not isNeedUpgradePriority) then
-- 说明没有优先资源需要更新,可以不做其它处理了
--同步到本地
local ms = MemoryStream()
B2OutputStream.writeMap(ms, localverVer)
local vpath = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(mVerverPath):e()
FileEx.CreateDirectory(Path.GetDirectoryName(vpath))
File.WriteAllBytes(vpath, ms:ToArray())
CLLVerManager.loadPriorityVer()
CLLVerManager.loadOtherResVer(true)
else
CLLVerManager.checkPriority() --处理优先资源更新
end
end
else
CLLVerManager.initFailed()
end
end
function CLLVerManager.checkPriority()
--取得本地优先更新资源版本信息
CLVerManager.self:StartCoroutine(FileEx.readNewAllBytesAsyn(mVerPrioriPath, CLLVerManager.onGetNewPriorityMap))
end
function CLLVerManager.onGetNewPriorityMap(buff)
if (buff ~= nil) then
localPriorityVer = CLVerManager.self:toMap(buff)
else
localPriorityVer = Hashtable()
end
CLVerManager.self.localPriorityVer = localPriorityVer -- 同步到c#
progress = 0
needUpgradeVerver:Clear()
needUpgradePrioritis:Clear()
local ver = nil
local keysList = MapEx.keys2List(serverPriorityVer)
local key = nil
local count = keysList.Count
for i = 0, count - 1 do
key = keysList[i]
ver = MapEx.getString(localPriorityVer, key)
if (ver == nil or ver ~= MapEx.getString(serverPriorityVer, key)) then
MapEx.set(needUpgradeVerver, key, false)
needUpgradePrioritis:Enqueue(key)
end
end
keysList:Clear()
keysList = nil
if (needUpgradePrioritis.Count > 0) then
haveUpgrade = true
CLVerManager.self.haveUpgrade = true
if (progressCallback ~= nil) then
progressCallback(needUpgradeVerver.Count, 0)
end
CLLVerManager.getPriorityFiles(needUpgradePrioritis:Dequeue())
else
--同步总的版本管理文件到本地
local ms = MemoryStream()
B2OutputStream.writeMap(ms, localverVer)
local vpath = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(mVerverPath):e()
FileEx.CreateDirectory(Path.GetDirectoryName(vpath))
File.WriteAllBytes(vpath, ms:ToArray())
CLLVerManager.loadOtherResVer(true)
end
end
-- 取得优先更新的资源
function CLLVerManager.getPriorityFiles(fPath)
local Url = ""
local verVal = MapEx.getString(serverPriorityVer, fPath)
Url = PStr.begin():a(baseUrl):a("/"):a(fPath):a("."):a(verVal):e() -- 把版本号拼在后面
-- print("Url==" .. Url);
WWWEx.get(Url, CLAssetType.bytes, CLLVerManager.onGetPriorityFiles, CLLVerManager.initFailed, fPath, true, 2)
if (progressCallback ~= nil) then
progressCallback(needUpgradeVerver.Count, progress, WWWEx.getWwwByUrl(Url))
end
end
function CLLVerManager.onGetPriorityFiles(content, orgs)
if (content == nil) then
CLLVerManager.initFailed()
return
end
local fPath = orgs
progress = progress + 1
-- 先把文件放在tmp目录等全部下载好后再移到正式目录
local fName = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(tmpUpgradePirorityPath):a("/"):a(fPath):e()
FileEx.CreateDirectory(Path.GetDirectoryName(fName))
File.WriteAllBytes(fName, content)
--同步到本地
MapEx.set(localPriorityVer, fPath, MapEx.getString(serverPriorityVer, fPath))
MapEx.set(needUpgradeVerver, fPath, true)
CLVerManager.self.localPriorityVer = localPriorityVer
if (progressCallback ~= nil) then
progressCallback(needUpgradeVerver.Count, progress)
end
if (needUpgradePrioritis.Count > 0) then
CLLVerManager.getPriorityFiles(needUpgradePrioritis:Dequeue())
else
--已经把所有资源取得完成
-- 先把文件放在tmp目录等全部下载好后再移到正式目录
local keysList = MapEx.keys2List(needUpgradeVerver)
local count = keysList.Count
local key = nil
local fromFile = ""
local toFile = ""
for i = 0, count - 1 do
key = keysList[i]
fromFile = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(tmpUpgradePirorityPath):a("/"):a(key):e()
toFile = PStr.begin():a(CLPathCfg.persistentDataPath):a("/"):a(key):e()
FileEx.CreateDirectory(Path.GetDirectoryName(toFile))
File.Copy(fromFile, toFile, true)
end
Directory.Delete(PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(tmpUpgradePirorityPath):e(), true)
keysList:Clear()
keysList = nil
--同步优先资源更新的版本管理文件到本地
local ms = MemoryStream()
B2OutputStream.writeMap(ms, localPriorityVer)
local vpath = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(mVerPrioriPath):e()
FileEx.CreateDirectory(Path.GetDirectoryName(vpath))
File.WriteAllBytes(vpath, ms:ToArray())
--同步总的版本管理文件到本地
ms = MemoryStream()
B2OutputStream.writeMap(ms, localverVer)
vpath = PStr.b():a(CLPathCfg.persistentDataPath):a("/"):a(mVerverPath):e()
FileEx.CreateDirectory(Path.GetDirectoryName(vpath))
File.WriteAllBytes(vpath, ms:ToArray())
CLLVerManager.loadOtherResVer(true)
end
end
function CLLVerManager.loadPriorityVer()
CLVerManager.self:StartCoroutine(FileEx.readNewAllBytesAsyn(mVerPrioriPath, CLLVerManager.onGetVerPriority))
end
function CLLVerManager.onGetVerPriority(buff)
if (buff ~= nil) then
localPriorityVer = CLVerManager.self:toMap(buff)
else
localPriorityVer = Hashtable()
end
CLVerManager.self.localPriorityVer = localPriorityVer
end
function CLLVerManager.loadOtherResVer(sucessProcUpgrade)
isSucessUpgraded = sucessProcUpgrade
CLVerManager.self:StartCoroutine(FileEx.readNewAllBytesAsyn(mVerOtherPath, CLLVerManager.onGetVerOther))
end
function CLLVerManager.onGetVerOther(buff)
if (buff ~= nil) then
otherResVerOld = CLVerManager.self:toMap(buff)
else
otherResVerOld = Hashtable()
end
CLVerManager.self.otherResVerOld = otherResVerOld
local path = PStr.b():a(newestVerPath):a("/"):a(mVerOtherPath):e()
CLVerManager.self:StartCoroutine(FileEx.readNewAllBytesAsyn(path, CLLVerManager.onGetNewVerOthers))
end
function CLLVerManager.onGetNewVerOthers(buff)
if (buff ~= nil) then
otherResVerNew = CLVerManager.self:toMap(buff)
else
otherResVerNew = Hashtable()
end
CLVerManager.self.otherResVerNew = otherResVerNew
progressCallback = nil
Utl.doCallback(onFinishInit, isSucessUpgraded)
end
function CLLVerManager.initFailed(...)
if (progressCallback ~= nil) then
progressCallback(needUpgradeVerver.Count, progress, nil)
end
CLLVerManager.loadPriorityVer()
CLLVerManager.loadOtherResVer(false)
printw("initFailed")
end
function CLLVerManager.isHaveUpgrade(...)
return haveUpgrade
end
return CLLVerManager

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: efa9e997b327b4ccaa15f578bd8e33b6
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,36 @@
-- 日志监听
do
KKLogListener = {}
function KKLogListener.OnLogError(log)
-- 当有异常日志时
if KKWhiteList and KKWhiteList.isWhiteName() then
if CLAlert.self ~= nil then
alertInfo("有异常日志,请在屏幕画圈查看详细!", Color.red, 3, 4)
end
end
-- 记录到服务器
if __recodeErrorLog__ then
if
(not startswith(log.condition, "get attr is nil")) and
(not startswith(log.condition, "Releasing render texture that is set as Camera")) and
(not startswith(log.condition, "Billing disabled")) and
(not startswith(log.condition, "propNames is null")) and
(not string.find(log.condition, "/KokManagement/ErrorServlet"))
then
local url = joinStr(__httpBaseUrl3, "/KokManagement/ErrorServlet")
local formData = Hashtable()
formData:Add("errorKey", joinStr(log.condition, "\n", log.stacktrace))
WWWEx.post(url, formData, CLAssetType.text, nil, nil, nil, true)
end
end
end
function KKLogListener.OnLogWarning(log)
-- 当有警告日志时
end
--------------------------------------------
return KKLogListener
end

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: ac1f7b6a9511249b8bda9003558eb4ea
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,638 @@
-- require 'CLLFunctions'
--- lua工具方法
local table = table
local smatch = string.match
local sfind = string.find
local pnlShade = nil
function showHotWheel(...)
if pnlShade == nil then
pnlShade = CLPanelManager.getPanel("PanelHotWheel")
end
local paras = {...}
if (#(paras) > 1) then
local msg = paras[1]
pnlShade:setData(msg)
else
pnlShade:setData("")
end
-- CLPanelManager.showPanel(pnlShade)
pnlShade:show()
end
function hideHotWheel(...)
if pnlShade == nil then
pnlShade = CLPanelManager.getPanel("PanelHotWheel")
end
-- CLPanelManager.hidePanel(pnlShade)
local func = pnlShade:getLuaFunction("hideSelf")
if (func ~= nil) then
func()
end
end
function mapToColor(map)
local color = Color.white
if (map == nil) then
return color
end
color =
Color(
MapEx.getNumber(map, "r"),
MapEx.getNumber(map, "g"),
MapEx.getNumber(map, "b"),
MapEx.getNumber(map, "a")
)
return color
end
function mapToVector2(map)
local v = Vector2.zero
if (map == nil) then
return v
end
v = Vector2(MapEx.getNumber(map, "x"), MapEx.getNumber(map, "y"))
return v
end
function mapToVector3(map)
local v = Vector3.zero
if (map == nil) then
return v
end
v = Vector3(MapEx.getNumber(map, "x"), MapEx.getNumber(map, "y"), MapEx.getNumber(map, "z"))
return v
end
function mapToVector4(map)
local v = Vector4.zero
if (map == nil) then
return v
end
v =
Vector4(
MapEx.getNumber(map, "x"),
MapEx.getNumber(map, "y"),
MapEx.getNumber(map, "z"),
MapEx.getNumber(map, "w")
)
return v
end
---@return UnityEngine.Transform
function getChild(root, ...)
local args = {...}
local path = ""
if (#args > 1) then
local str = PStr.b()
for i, v in ipairs(args) do
str:a(v):a("/")
end
path = str:e()
else
path = args[1]
end
return root:Find(path)
end
--获取路径
function stripfilename(filename)
return smatch(filename, "(.+)/[^/]*%.%w+$") --*nix system
--return smatch(filename, “(.+)\\[^\\]*%.%w+$”) — windows
end
--获取文件名
function strippath(filename)
return smatch(filename, ".+/([^/]*%.%w+)$") -- *nix system
--return smatch(filename, “.+\\([^\\]*%.%w+)$”) — *nix system
end
--去除扩展名
function stripextension(filename)
local idx = filename:match(".+()%.%w+$")
if (idx) then
return filename:sub(1, idx - 1)
else
return filename
end
end
--获取扩展名
function getextension(filename)
return filename:match(".+%.(%w+)$")
end
function trim(s)
-- return (s:gsub("^%s*(.-)%s*$", "%1"))
return smatch(s, "^()%s*$") and "" or smatch(s, "^%s*(.*%S)") -- 性能略优
end
function startswith(str, substr)
if str == nil or substr == nil then
return nil, "the string or the sub-stirng parameter is nil"
end
if sfind(str, substr) ~= 1 then
return false
else
return true
end
end
function getAction(act)
local actionValue = 0
if (act == "idel") then
--, //0 空闲
return 0
elseif (act == "idel2") then
--, //1 空闲
actionValue = 1
elseif (act == "walk") then
--, //2 走
actionValue = 2
elseif (act == "run") then
--, //3 跑
actionValue = 3
elseif (act == "jump") then
--, //4 跳
actionValue = 4
elseif (act == "slide") then
--, //5 滑行,滚动,闪避
actionValue = 5
elseif (act == "drop") then
--, //6 下落
actionValue = 6
elseif (act == "attack") then
--, //7 攻击
actionValue = 7
elseif (act == "attack2") then
--, //8 攻击2
actionValue = 8
elseif (act == "skill") then
--, //9 技能
actionValue = 9
elseif (act == "skill2") then
--, //10 技能2
actionValue = 10
elseif (act == "skill3") then
--, //11 技能3
actionValue = 11
elseif (act == "skill4") then
--, //12 技能4
actionValue = 12
elseif (act == "hit") then
--, //13 受击
actionValue = 13
elseif (act == "dead") then
--, //14 死亡
actionValue = 14
elseif (act == "happy") then
--, //15 高兴
actionValue = 15
elseif (act == "sad") then
--, //16 悲伤
actionValue = 16
elseif (act == "up") then
--, //17 起立
actionValue = 17
elseif (act == "down") then
--, //18 倒下
actionValue = 18
elseif (act == "biggestAK") then
--, //19 最大的大招
actionValue = 19
elseif (act == "dizzy") then
--, //20 晕
actionValue = 20
elseif (act == "stiff") then
--, //21 僵硬
actionValue = 21
elseif (act == "idel3") then
--, //21 空闲
actionValue = 22
else
actionValue = 0
end
return actionValue
end
-- 动作回调toMap
function ActCBtoList(...)
local paras = {...}
if (#(paras) > 0) then
local callbackInfor = ArrayList()
for i, v in ipairs(paras) do
callbackInfor:Add(v)
end
return callbackInfor
end
return nil
end
function strSplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
local i = 1
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
t[i] = str
i = i + 1
end
return t
end
-- 取得方法体
function getLuaFunc(trace)
if (trace == nil) then
return nil
end
local list = strSplit(trace, ".")
local func = nil
if (list ~= nil) then
func = _G
for i, v in ipairs(list) do
func = func[v]
end
end
return func
end
---@param p coolape.Coolape.CLPanelLua
function doShowPanel(p, paras)
p:setData(paras)
CLPanelManager.showPanel(p)
if NetProto then
NetProto.addPanelListener(p)
end
end
---@param p coolape.Coolape.CLPanelLua
function doHidePanel(p)
CLPanelManager.hidePanel(p)
if NetProto then
NetProto.removePanelListener(p)
end
end
---@param p coolape.Coolape.CLPanelLua
function onLoadedPanel(p, paras)
if CLPanelManager.topPanel then
if NetProto then
NetProto.removePanelListener(CLPanelManager.topPanel)
end
end
p:setData(paras)
CLPanelManager.showTopPanel(p)
if NetProto then
NetProto.addPanelListener(p)
end
end
---@param p coolape.Coolape.CLPanelLua
function onLoadedPanelTT(p, paras)
p:setData(paras)
CLPanelManager.showTopPanel(p, true, true)
if NetProto then
NetProto.addPanelListener(p)
end
end
---@param p coolape.Coolape.CLPanelLua
function onLoadedPanelTF(p, paras)
p:setData(paras)
CLPanelManager.showTopPanel(p, true, false)
if NetProto then
NetProto.addPanelListener(p)
end
end
function hideTopPanel(p)
local p = p or CLPanelManager.topPanel
CLPanelManager.hideTopPanel(p)
if NetProto then
NetProto.removePanelListener(p)
end
end
function SetActive(go, isActive)
if (go == nil) then
return
end
NGUITools.SetActive(go, isActive)
end
function getCC(transform, path, com)
if not transform then
return
end
local tf = getChild(transform, path)
if not tf then
return
end
return tf:GetComponent(com)
end
function isNilOrEmpty(s)
if s == nil or s == "" then
return true
end
return false
end
-- function joinStr(...)
-- local paras = {...}
-- if paras == nil or #paras == 0 then
-- return ""
-- end
-- return table.concat(paras)
-- end
---@public 拼接字符串
function joinStr(...)
-- local paras = {...}
local tb = {}
local v
for i = 1, select("#", ...) do
v = select(i, ...)
if v then
table.insert(tb, tostring(v))
end
end
return table.concat(tb)
end
---@public 保留小数位位数
function getPreciseDecimal(nNum, n)
if type(nNum) ~= "number" then
return nNum
end
n = n or 0
n = math.floor(n)
if n < 0 then
n = 0
end
local nDecimal = 10 ^ n
local nTemp = math.floor(nNum * nDecimal)
local nRet = nTemp / nDecimal
return nRet
end
---@public 截取指定长度字符注意英文个数为E汉字或韩文或其他个数为CE*1 + C*2 <= 14
function cutStr_utf8(str, max)
if not max then
max = 14
end
local name_len = 0
local start_index = 1
local name_substr = str
local isSub = false
while true do
local char = string.sub(str, start_index, start_index)
if char and start_index <= string.len(str) then
local c = string.byte(char)
local len = 1
if 0 <= c and c <= 127 then
len = 1
elseif 192 <= c and c <= 223 then
len = 2
elseif 224 <= c and c <= 239 then
len = 3
elseif 240 <= c and c <= 247 then
len = 4
elseif 248 <= c and c <= 251 then
len = 5
elseif 252 <= c and c <= 253 then
len = 6
else
--print(c,'error');
end
if len == 1 then
--英文按照一个字节来算,其他的都按两字节算
name_len = name_len + 1
else
name_len = name_len + 2
end
--"abc123中国人??";
--local unicode = kkf_get_substring_unicode(str,start_index,len);
--local tp = kkf_unicode_type(unicode);
--print(string.format("%0x",unicode),len,tp);
if name_len > max then
name_substr = string.sub(str, 1, start_index - 1)
isSub = true
break
end
start_index = start_index + len
else
break
end
end
return name_substr, isSub
end
---@public 离线处理
function procOffLine()
if MyCfg.mode == GameMode.none or IDUtl.isLoadingScene then
return
end
-- CLAlert.add(LGet("MsgOffline"), Color.yellow, 1)
printe(LGet("MsgOffline"))
InvokeEx.cancelInvoke() -- 放在前面后面马上就要用到invoke
local ok, result = pcall(doReleaseAllRes)
if not ok then
printe(result)
end
local panel = CLPanelManager.getPanel(CLMainBase.self.firstPanel)
CLPanelManager.showPanel(panel)
-- 重新进入游戏
InvokeEx.invoke(
function()
pcall(releaseRes4GC, false)
CLLMainLua.begain()
end,
0.5
)
end
function doReleaseAllRes()
Time.timeScale = 1
SetActive(CLPanelManager.self.mask, false)
if NetProtoIsland then
NetProtoIsland.__sessionID = 0
end
MyCfg.mode = GameMode.none
if CLLNet then
CLLNet.cancelHeart()
CLLNet.stop()
end
if Net.self.netGameDataQueue then
Net.self.netGameDataQueue:Clear()
end
-- 页面处理
CLPanelManager.hideAllPanel()
local panel = CLPanelManager.getPanel(CLMainBase.self.firstPanel)
CLPanelManager.showPanel(panel)
pcall(
function()
UIRichText4Chat.pool:clean()
end
)
if IDUtl then
IDUtl.clean()
end
if IDMainCity then
IDMainCity.clean()
end
if IDLBattle then
IDLBattle.clean()
end
if IDWorldMap then
IDWorldMap.clean()
end
hideHotWheel()
end
---@public 重新启动前的处理
function doSomethingBeforeRestart()
local ok, result = pcall(doReleaseAllRes)
if not ok then
printe(result)
end
Net.self:clean()
---@type Coolape.CLBaseLua
local worldmap = getCC(MyMain.self.transform, "worldmap", "CLBaseLua")
worldmap:destoryLua()
if IDLCameraMgr then
IDLCameraMgr.clean()
end
if IDMainCity then
IDMainCity.destory()
end
if IDLBattle then
IDLBattle.destory()
end
if IDWorldMap then
IDWorldMap.destory()
end
-- 取消音效开关的回调
SoundEx.clean()
end
---@public gc
function releaseRes4GC(releaseRes)
if releaseRes then
CLUIInit.self.emptAtlas:releaseAllTexturesImm()
CLAssetsManager.self:releaseAsset(true)
Resources.UnloadUnusedAssets()
end
if not MyCfg.self.isUnityEditor then
CS.UnityEngine.Scripting.GarbageCollector.GCMode = CS.UnityEngine.Scripting.GarbageCollector.Mode.Enabled
MyMain.self:gc()
GC.Collect() -- 内存释放
CS.UnityEngine.Scripting.GarbageCollector.GCMode = CS.UnityEngine.Scripting.GarbageCollector.Mode.Disabled
end
end
function dump(obj)
local getIndent, quoteStr, wrapKey, wrapVal, dumpObj
getIndent = function(level)
return string.rep("\t", level)
end
quoteStr = function(str)
return '"' .. string.gsub(str, '"', '\\"') .. '"'
end
wrapKey = function(val)
if type(val) == "number" then
return "[" .. val .. "]"
elseif type(val) == "string" then
return "[" .. quoteStr(val) .. "]"
else
return "[" .. tostring(val) .. "]"
end
end
wrapVal = function(val, level)
if type(val) == "table" then
return dumpObj(val, level)
elseif type(val) == "number" then
return val
elseif type(val) == "string" then
return quoteStr(val)
else
return tostring(val)
end
end
dumpObj = function(obj, level)
if type(obj) ~= "table" then
return wrapVal(obj)
end
level = level + 1
local tokens = {}
tokens[#tokens + 1] = "{"
for k, v in pairs(obj) do
tokens[#tokens + 1] = getIndent(level) .. wrapKey(k) .. " = " .. wrapVal(v, level) .. ","
end
tokens[#tokens + 1] = getIndent(level - 1) .. "}"
return table.concat(tokens, "\n")
end
return dumpObj(obj, 0)
end
--*******************************************************************
--*******************************************************************
local borrowedSpList = {}
-- 当向atlas借一个sprite时
function onBorrowedSpriteCB(atlas, spData)
--print(atlas.name, spData.path)
local m = borrowedSpList[spData.name]
m = m or {}
m.atlas = m.atlas or {}
m.atlas[atlas.name] = atlas.name
if m.data == nil then
m.data = {}
m.data.name = spData.name
m.data.path = spData.path
m.data.x = spData.x
m.data.y = spData.y
m.data.width = spData.width
m.data.height = spData.height
m.data.borderLeft = spData.borderLeft
m.data.borderRight = spData.borderRight
m.data.borderTop = spData.borderTop
m.data.borderBottom = spData.borderBottom
m.data.paddingLeft = spData.paddingLeft
m.data.paddingRight = spData.paddingRight
m.data.paddingTop = spData.paddingTop
m.data.paddingBottom = spData.paddingBottom
end
m.times = m.times or 0
m.times = m.times + 1
borrowedSpList[spData.name] = m
end
---@public
function onApplicationPauseCallback4CountAtlas()
local jstr = json.encode(borrowedSpList)
local path =
joinStr(CLPathCfg.persistentDataPath, "/", CLPathCfg.self.basePath, "/xRes/spriteBorrow/spriteBorrowInfo.json")
Directory.CreateDirectory(Path.GetDirectoryName(path))
File.WriteAllText(path, jstr)
end
--*******************************************************************
--*******************************************************************

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9f545dd1406b8469f97d272c2ab46311
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,86 @@
MyUtl = {}
MyUtl.init = function(panel)
MyUtl.getUIContent(panel)
end
local _TopHeight_ = 132
local _BottomHeight_ = 147
local _ContentRect
local _sizeAdjust
MyUtl.getUIContent = function(panel, top, bottom, forceCal)
-- if _ContentRect and (not forceCal) then
-- return _ContentRect
-- end
top = top or _TopHeight_
bottom = bottom or _BottomHeight_
local sizeAdjust = UIRoot.GetPixelSizeAdjustment(panel.gameObject)
_sizeAdjust = sizeAdjust
_ContentRect =
Vector4(0, (bottom - top) / 2, Screen.width * sizeAdjust, Screen.height * sizeAdjust - (bottom + top))
return _ContentRect
end
MyUtl.setContentView = function(go, top, bottom)
local panel = go:GetComponent("UIPanel")
if panel then
panel.transform.localPosition = Vector3.zero
panel.clipOffset = Vector2.zero
panel.baseClipRegion = MyUtl.getUIContent(panel, top, bottom)
end
end
MyUtl.getSizeAdjust = function()
return _sizeAdjust
end
---public 拨号
MyUtl.callCust = function(cust)
if type(cust.jsonstr) == "string" then
cust.jsonstr = json.decode(cust.jsonstr)
end
cust.jsonstr = cust.jsonstr or {}
local phones = ArrayList()
local taskId = tostring(cust.taskId)
local fields = DBCust.getFieldsByTask(taskId)
for i, attr in ipairs(fields) do
if attr.attrType == DBCust.FieldType.phone then
local phNo = cust.jsonstr[joinStr(attr.id, "_", attr.attrName)]
if not isNilOrEmpty(phNo) then
phones:Add(joinStr(attr.attrName,": ", phNo))
end
end
end
if phones.Count > 0 then
phones:Insert(0, joinStr("默认: ",cust.phoneNo))
CLUIPopListPanel.show(
phones,
phones,
function(val, selectedItem)
if val then
MyUtl.doCall(cust.custId, val)
end
end
)
else
MyUtl.doCall(cust.custId, cust.phoneNo)
end
end
MyUtl.doCall = function(custId, phoneNo)
showHotWheel("拨号中...")
NetProto.send.bi_call(
custId,
phoneNo,
nil,
function(content)
hideHotWheel()
if content.success then
CLAlert.add("拨号成功!", Color.white, 5)
end
end
)
end
return MyUtl

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: af4cdfb46f26e47fda7a5f67f75cd07f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 KiB

View File

@@ -0,0 +1,90 @@
fileFormatVersion: 2
guid: f6e39f40692b949908669908acde6c03
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,469 @@
-- 曲线
require("sys.Math")
---@class curve
local curve = {
_VERSION = 'curve 2.1.1',
_DESCRIPTION = 'tweening for lua',
_URL = 'https://github.com/kikito/tween.lua',
_LICENSE = [[
MIT LICENSE
Copyright (c) 2014 Enrique García Cota, Yuichi Tateno, Emmanuel Oga
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
]]
}
-- easing
-- Adapted from https://github.com/EmmanuelOga/easing. See LICENSE.txt for credits.
-- For all easing functions:
-- t = time == how much time has to pass for the tweening to complete
-- b = begin == starting property value
-- c = change == ending - beginning
-- d = duration == running time. How much time has passed *right now*
local pow, sin, cos, pi, sqrt, abs, asin = math.pow, math.sin, math.cos, math.pi, math.sqrt, math.abs, math.asin
-- linear
local function linear(t, b, c, d)
return c * t / d + b
end
-- quad
local function inQuad(t, b, c, d)
return c * pow(t / d, 2) + b
end
local function outQuad(t, b, c, d)
t = t / d
return -c * t * (t - 2) + b
end
local function inOutQuad(t, b, c, d)
t = t / d * 2
if t < 1 then
return c / 2 * pow(t, 2) + b
end
return -c / 2 * ((t - 1) * (t - 3) - 1) + b
end
local function outInQuad(t, b, c, d)
if t < d / 2 then
return outQuad(t * 2, b, c / 2, d)
end
return inQuad((t * 2) - d, b + c / 2, c / 2, d)
end
-- cubic
local function inCubic (t, b, c, d)
return c * pow(t / d, 3) + b
end
local function outCubic(t, b, c, d)
return c * (pow(t / d - 1, 3) + 1) + b
end
local function inOutCubic(t, b, c, d)
t = t / d * 2
if t < 1 then
return c / 2 * t * t * t + b
end
t = t - 2
return c / 2 * (t * t * t + 2) + b
end
local function outInCubic(t, b, c, d)
if t < d / 2 then
return outCubic(t * 2, b, c / 2, d)
end
return inCubic((t * 2) - d, b + c / 2, c / 2, d)
end
-- quart
local function inQuart(t, b, c, d)
return c * pow(t / d, 4) + b
end
local function outQuart(t, b, c, d)
return -c * (pow(t / d - 1, 4) - 1) + b
end
local function inOutQuart(t, b, c, d)
t = t / d * 2
if t < 1 then
return c / 2 * pow(t, 4) + b
end
return -c / 2 * (pow(t - 2, 4) - 2) + b
end
local function outInQuart(t, b, c, d)
if t < d / 2 then
return outQuart(t * 2, b, c / 2, d)
end
return inQuart((t * 2) - d, b + c / 2, c / 2, d)
end
-- quint
local function inQuint(t, b, c, d)
return c * pow(t / d, 5) + b
end
local function outQuint(t, b, c, d)
return c * (pow(t / d - 1, 5) + 1) + b
end
local function inOutQuint(t, b, c, d)
t = t / d * 2
if t < 1 then
return c / 2 * pow(t, 5) + b
end
return c / 2 * (pow(t - 2, 5) + 2) + b
end
local function outInQuint(t, b, c, d)
if t < d / 2 then
return outQuint(t * 2, b, c / 2, d)
end
return inQuint((t * 2) - d, b + c / 2, c / 2, d)
end
-- sine
local function inSine(t, b, c, d)
return -c * cos(t / d * (pi / 2)) + c + b
end
local function outSine(t, b, c, d)
return c * sin(t / d * (pi / 2)) + b
end
local function inOutSine(t, b, c, d)
return -c / 2 * (cos(pi * t / d) - 1) + b
end
local function outInSine(t, b, c, d)
if t < d / 2 then
return outSine(t * 2, b, c / 2, d)
end
return inSine((t * 2) - d, b + c / 2, c / 2, d)
end
-- expo
local function inExpo(t, b, c, d)
if t == 0 then
return b
end
return c * pow(2, 10 * (t / d - 1)) + b - c * 0.001
end
local function outExpo(t, b, c, d)
if t == d then
return b + c
end
return c * 1.001 * (-pow(2, -10 * t / d) + 1) + b
end
local function inOutExpo(t, b, c, d)
if t == 0 then
return b
end
if t == d then
return b + c
end
t = t / d * 2
if t < 1 then
return c / 2 * pow(2, 10 * (t - 1)) + b - c * 0.0005
end
return c / 2 * 1.0005 * (-pow(2, -10 * (t - 1)) + 2) + b
end
local function outInExpo(t, b, c, d)
if t < d / 2 then
return outExpo(t * 2, b, c / 2, d)
end
return inExpo((t * 2) - d, b + c / 2, c / 2, d)
end
-- circ
local function inCirc(t, b, c, d)
return (-c * (sqrt(1 - pow(t / d, 2)) - 1) + b)
end
local function outCirc(t, b, c, d)
return (c * sqrt(1 - pow(t / d - 1, 2)) + b)
end
local function inOutCirc(t, b, c, d)
t = t / d * 2
if t < 1 then
return -c / 2 * (sqrt(1 - t * t) - 1) + b
end
t = t - 2
return c / 2 * (sqrt(1 - t * t) + 1) + b
end
local function outInCirc(t, b, c, d)
if t < d / 2 then
return outCirc(t * 2, b, c / 2, d)
end
return inCirc((t * 2) - d, b + c / 2, c / 2, d)
end
-- elastic
local function calculatePAS(p, a, c, d)
p, a = p or d * 0.3, a or 0
if a < abs(c) then
return p, c, p / 4
end -- p, a, s
return p, a, p / (2 * pi) * asin(c / a) -- p,a,s
end
local function inElastic(t, b, c, d, a, p)
local s
if t == 0 then
return b
end
t = t / d
if t == 1 then
return b + c
end
p, a, s = calculatePAS(p, a, c, d)
t = t - 1
return -(a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b
end
local function outElastic(t, b, c, d, a, p)
local s
if t == 0 then
return b
end
t = t / d
if t == 1 then
return b + c
end
p, a, s = calculatePAS(p, a, c, d)
return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p) + c + b
end
local function inOutElastic(t, b, c, d, a, p)
local s
if t == 0 then
return b
end
t = t / d * 2
if t == 2 then
return b + c
end
p, a, s = calculatePAS(p, a, c, d)
t = t - 1
if t < 0 then
return -0.5 * (a * pow(2, 10 * t) * sin((t * d - s) * (2 * pi) / p)) + b
end
return a * pow(2, -10 * t) * sin((t * d - s) * (2 * pi) / p ) * 0.5 + c + b
end
local function outInElastic(t, b, c, d, a, p)
if t < d / 2 then
return outElastic(t * 2, b, c / 2, d, a, p)
end
return inElastic((t * 2) - d, b + c / 2, c / 2, d, a, p)
end
-- back
local function inBack(t, b, c, d, s)
s = s or 1.70158
t = t / d
return c * t * t * ((s + 1) * t - s) + b
end
local function outBack(t, b, c, d, s)
s = s or 1.70158
t = t / d - 1
return c * (t * t * ((s + 1) * t + s) + 1) + b
end
local function inOutBack(t, b, c, d, s)
s = (s or 1.70158) * 1.525
t = t / d * 2
if t < 1 then
return c / 2 * (t * t * ((s + 1) * t - s)) + b
end
t = t - 2
return c / 2 * (t * t * ((s + 1) * t + s) + 2) + b
end
local function outInBack(t, b, c, d, s)
if t < d / 2 then
return outBack(t * 2, b, c / 2, d, s)
end
return inBack((t * 2) - d, b + c / 2, c / 2, d, s)
end
-- bounce
local function outBounce(t, b, c, d)
t = t / d
if t < 1 / 2.75 then
return c * (7.5625 * t * t) + b
end
if t < 2 / 2.75 then
t = t - (1.5 / 2.75)
return c * (7.5625 * t * t + 0.75) + b
elseif t < 2.5 / 2.75 then
t = t - (2.25 / 2.75)
return c * (7.5625 * t * t + 0.9375) + b
end
t = t - (2.625 / 2.75)
return c * (7.5625 * t * t + 0.984375) + b
end
local function inBounce(t, b, c, d)
return c - outBounce(d - t, 0, c, d) + b
end
local function inOutBounce(t, b, c, d)
if t < d / 2 then
return inBounce(t * 2, 0, c, d) * 0.5 + b
end
return outBounce(t * 2 - d, 0, c, d) * 0.5 + c * .5 + b
end
local function outInBounce(t, b, c, d)
if t < d / 2 then
return outBounce(t * 2, b, c / 2, d)
end
return inBounce((t * 2) - d, b + c / 2, c / 2, d)
end
curve.easing = {
linear = linear,
inQuad = inQuad, outQuad = outQuad, inOutQuad = inOutQuad, outInQuad = outInQuad,
inCubic = inCubic, outCubic = outCubic, inOutCubic = inOutCubic, outInCubic = outInCubic,
inQuart = inQuart, outQuart = outQuart, inOutQuart = inOutQuart, outInQuart = outInQuart,
inQuint = inQuint, outQuint = outQuint, inOutQuint = inOutQuint, outInQuint = outInQuint,
inSine = inSine, outSine = outSine, inOutSine = inOutSine, outInSine = outInSine,
inExpo = inExpo, outExpo = outExpo, inOutExpo = inOutExpo, outInExpo = outInExpo,
inCirc = inCirc, outCirc = outCirc, inOutCirc = inOutCirc, outInCirc = outInCirc,
inElastic = inElastic, outElastic = outElastic, inOutElastic = inOutElastic, outInElastic = outInElastic,
inBack = inBack, outBack = outBack, inOutBack = inOutBack, outInBack = outInBack,
inBounce = inBounce, outBounce = outBounce, inOutBounce = inOutBounce, outInBounce = outInBounce
}
--local function checkSubjectAndTargetRecursively(subject, target, path)
-- path = path or {}
-- local targetType, newPath
-- for k, targetValue in pairs(target) do
-- targetType, newPath = type(targetValue), copyTables({}, path)
-- table.insert(newPath, tostring(k))
-- if targetType == 'number' then
-- assert(type(subject[k]) == 'number', "Parameter '" .. table.concat(newPath, '/') .. "' is missing from subject or isn't a number")
-- elseif targetType == 'table' then
-- checkSubjectAndTargetRecursively(subject[k], targetValue, newPath)
-- else
-- assert(targetType == 'number', "Parameter '" .. table.concat(newPath, '/') .. "' must be a number or table of numbers")
-- end
-- end
--end
--
--local function checkNewParams(duration, subject, target, easing)
-- assert(type(duration) == 'number' and duration > 0, "duration must be a positive number. Was " .. tostring(duration))
-- local tsubject = type(subject)
-- assert(tsubject == 'table' or tsubject == 'userdata', "subject must be a table or userdata. Was " .. tostring(subject))
-- assert(type(target) == 'table', "target must be a table. Was " .. tostring(target))
-- assert(type(easing) == 'function', "easing must be a function. Was " .. tostring(easing))
-- checkSubjectAndTargetRecursively(subject, target)
--end
local function getEasingFunction(easing)
easing = easing or "linear"
if type(easing) == 'string' then
local name = easing
easing = curve.easing[name]
if type(easing) ~= 'function' then
error("The easing function name '" .. name .. "' is invalid")
end
end
return easing
end
--local function performEasingOnSubject(subject, target, initial, clock, duration, easing)
-- local t, b, c, d
-- for k, v in pairs(target) do
-- if type(v) == 'table' then
-- performEasingOnSubject(subject[k], v, initial[k], clock, duration, easing)
-- else
-- t, b, c, d = clock, initial[k], v - initial[k], duration
-- subject[k] = easing(t, b, c, d)
-- end
-- end
--end
-- Curve methods
---@class Curve
local Curve = {}
local Curve_mt = { __index = Curve }
-- 根据时间求值
function Curve:evaluate(time)
assert(type(time) == 'number', "clock must be a positive number or 0")
return self.easing(time, self.from, self.change, self.duration)
end
--取得当前值
function Curve:get()
return self.value
end
--设置当时间
function Curve:set(clock)
assert(type(clock) == 'number', "clock must be a positive number or 0")
--self.initial = self.initial or copyTables({}, self.target, self.subject)
self.clock = clock
if self.clock <= 0 then
self.clock = 0
self.value = self.from
--copyTables(self.subject, self.initial)
elseif self.clock >= self.duration then
-- the Curve has expired
self.clock = self.duration
--copyTables(self.subject, self.target)
self.value = self.to
else
--performEasingOnSubject(self.subject, self.target, self.initial, self.clock, self.duration, self.easing)
self.value = self.easing(self.clock, self.from, self.change, self.duration)
end
return self.clock >= self.duration
end
function Curve:reset()
return self:set(0)
end
function Curve:update(dt)
assert(type(dt) == 'number', "dt must be a number")
return self:set(self.clock + dt)
end
-- Public interface
---@param duration number
---@param from number
---@param to number
---@param easing curve.easing.xxx
function curve.new(duration, from, to, easing)
easing = getEasingFunction(easing)
-- checkNewParams(duration, subject, target, easing)
return setmetatable({
duration = duration,
from = from,
to = to,
change = to - from,
easing = easing,
clock = 0,
value = from,
}, Curve_mt)
end
-- Public interface
--function curve.new(duration, subject, target, easing)
-- easing = getEasingFunction(easing)
-- checkNewParams(duration, subject, target, easing)
-- return setmetatable({
-- duration = duration,
-- subject = subject,
-- target = target,
-- easing = easing,
-- clock = 0
-- }, Curve_mt)
--end
return curve

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2f2bbc4fd9f2b414fab4250622759e06
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: