--[[ 为pocomanager提供自动化测试的lua服务 --]] local PocoAgent = {} local FuncType = { FindViewPos = 1, IsLoading = 2, IsViewOpened = 3, ForceStageDownload = 4, DownloadReplayData = 5, GetFileRootPath = 6, IsInAssetAnalysis = 7, } local HttpReq = require('Http/HttpReq') --region *************** ui服务 ***************** local rootUICanvas local rootUICamera do local rootObj = UnityEngine.GameObject.Find("UIRootCanvas") rootUICanvas = rootObj:GetComponent(typeof(Tai.Lua.UIScriptableCanvas)) rootUICamera = UnityEngine.GameObject.Find("UIRootCanvas/Camera"):GetComponent(typeof(UnityEngine.Camera)) end local screenPos = {0, 0} --endregion ui服务 local private = {} --region *************** doFunc ***************** --获取ui组件的点击位置,替代poco本身的查找 function private.FindViewPos(classPath,path) local view = rootUICanvas:GetOpenedView(classPath) if view then local transf = view.gameObject.transform local node = transf:Find(path) local pos = node.position pos = rootUICamera:WorldToViewportPoint(pos) pos.y = 1 - pos.y --poco坐标系的原地在右上角,unity里为左下角,所以需要转换 screenPos[1], screenPos[2] = pos.x , pos.y return screenPos end end function private.IsLoading() return MDL.Loading.GetIsLoadingState() end function private.IsViewOpened(uiname) local view = Const_UI_Lua.UIEnum[uiname] or uiname --有些debugview,不存在业务常量里 local find = UIManager.IsViewOpened(view) or UIManager.IsViewOpened(view, true) return find end function private.ForceStageDownload() if LoginProxy.Get_IfAllDownload() then return false end CTL.HotFix.ForceOpenStageDownload(function() UIManager.CloseView(Const_UI_Lua.UIEnum.UIStagePackage) end) return true end function private.DownloadReplayData(url) local localPath = "ReplayData/replaydata" if LuaExt.FileExists(localPath) then LuaExt.FileDelete(localPath) elseif not LuaExt.DirectoryExists("ReplayData") then LuaExt.DirectoryCreate("ReplayData") end HttpReq.StartHttpDownload(url, localPath, function(isSuccess, statusCode) if isSuccess then logging.crit(LTAG.CRIT, "已下载回放数据,url:", url) else logging.error(LTAG.ERROR, "无法下载回放数据,url:", url, " , statusCode: ", statusCode) end end) end function private.GetFileRootPath() --安卓里对应TKData的上层file层,比如/storage/emulated/0/Android/data/com.taiyouxi.dl2.uwapip.perf/files return UnityEngine.Application.persistentDataPath end --资源检测流水线专用判断,取代之前写死的等待几分钟 function private.IsInAssetAnalysis() local AssetAnalysisTools = require("ProfilerKit/AssetAnalysisTools") local isInAssetAnalysis = AssetAnalysisTools.IsInAssetAnalysis() return isInAssetAnalysis end --endregion --执行从python传参过来的函数 local doFunc = PocoAgent doFunc[FuncType.FindViewPos] = private.FindViewPos doFunc[FuncType.IsLoading] = private.IsLoading doFunc[FuncType.IsViewOpened] = private.IsViewOpened doFunc[FuncType.ForceStageDownload] = private.ForceStageDownload doFunc[FuncType.DownloadReplayData] = private.DownloadReplayData doFunc[FuncType.GetFileRootPath] = private.GetFileRootPath doFunc[FuncType.IsInAssetAnalysis] = private.IsInAssetAnalysis function PocoAgent.HandleMsg(funcType, ...) local func = doFunc[funcType] if func then return func(...) end end return PocoAgent