-- Lua中的继承 function Inherit(tbParent, tbChild) if not tbParent then local o = tbChild or {} setmetatable(o, { __index = o }) return o else local tb = tbChild or {} tbParent.__index = tbParent --local super_mt = getmetatable(tbParent) setmetatable(tb, tbParent) tb.super = setmetatable({}, tbParent) return tb end end function RandomList(arr) if not arr or #arr <= 1 then return end local index for i = #arr, 1, -1 do index = math.random(1, i) arr[i], arr[index] = arr[index], arr[i] end end --查找对象-- function find(str) return GameObject.Find(str) end function destroy(obj) GameObject.DestroyImmediate(obj) end function newObject(prefab) return GameObject.Instantiate(prefab) end function CheckListIsContainValue1(_list,_value) if _list and _value then for key, value in pairs(_list) do if value ==_value then return true end end end return false end function CheckListIsContainValue2(_list,_value) if _list and _value then for key, value in pairs(_list) do if value[1] ==_value then return true end end end return false end --适配 function screenAdapte(go) --if Screen.width > 1080 or Screen.height > 1920 then -- local scale = math.max(Screen.width / 1080, Screen.height / 1920) -- go.transform.localScale = Vector3.one * scale --end end function effectAdapte(go) local scale = Screen.width / Screen.height / 1080 * 1920 --local scale = Screen.width / 1080 --local scale = 1920 / Screen.height --Log("scale:"..scale) local v3 = go.transform.localScale if scale <= 1 then Util.SetParticleScale(go, scale) end go.transform.localScale = v3 end --创建面板-- function createPanel(name) PanelManager:CreatePanel(name) end function child(str) return transform:FindChild(str) end function subGet(childNode, typeName) return child(childNode):GetComponent(typeName) end function findPanel(str) local obj = find(str) if obj == nil then error(str .. " is null") return nil end return obj:GetComponent("BaseLua") end function ReloadFile(file_path) package.loaded[file_path] = nil -- 消除载入记录 return require(file_path) -- 重新加载lua文件 end function UnLoadLuaFiles(config) for i, v in ipairs(config) do package.loaded[v] = nil package.preload[v] = nil end end function LoadLuaFiles(config) for i, v in ipairs(config) do require(v) end end --播放指定音效,在同一时刻点击音效不播放 function PlaySoundWithoutClick(sound) SoundManager.PlaySound(sound) Framework.PlayClickSoundThisTime = false end -- 连续弹出文字 -- 1 -- 使用正常Tip -- 2 -- 使用带颜色的 function PopupText(strTable, delayTime, type) local index = 1 local timer timer = Timer.New(function() if index == #strTable + 1 then timer:Stop() else if type == 1 then PopupTipPanel.ShowTip(strTable[index]) elseif type == 2 then PopupTipPanel.ShowColorTip(strTable[index].name, strTable[index].icon, strTable[index].num) end index = index + 1 end end, delayTime, #strTable * delayTime * 2) timer:Start() end function Util_SetHeadImage(spLoader, url, image, isSelf) if image == nil then return end if url == nil then Util_SetToDefaultHeadImage(spLoader, image) return end if url == "" or url == "/0" then Util_SetToDefaultHeadImage(spLoader, image) return end imageDownloadMgr:SetImage_Image(url, image, isSelf) end function AddParticleSortLayer(go,layer) if layer==0 then return end local list=go.transform:GetComponentsInChildren(typeof(UnityEngine.Transform)):ToTable() for key, value in pairs(list) do local aaa=value local render=aaa:GetComponent(typeof(UnityEngine.Renderer)) if render then render.sortingOrder=render.sortingOrder+layer end local render2=aaa:GetComponent(typeof(UnityEngine.SkinnedMeshRenderer)) if render2 then render2.sortingOrder=render.sortingOrder+layer end local canvas=aaa:GetComponent(typeof(UnityEngine.Canvas)) if canvas then canvas.sortingOrder=canvas.sortingOrder+layer end end end function SetParticleSortLayer(go,layer) if layer==0 then return end local list=go.transform:GetComponentsInChildren(typeof(UnityEngine.Transform)):ToTable() for key, value in pairs(list) do local aaa=value local render=aaa:GetComponent(typeof(UnityEngine.Renderer)) if render then render.sortingOrder=layer end local render2=aaa:GetComponent(typeof(UnityEngine.SkinnedMeshRenderer)) if render2 then render2.sortingOrder=layer end local canvas=aaa:GetComponent(typeof(UnityEngine.Canvas)) if canvas then canvas.sortingOrder=layer end end end function Util_SetToDefaultHeadImage(spLoader, image) if image == nil then return end local bundleName = "normal_asset" local assetName = "Avatar" local sprite = spLoader:LoadSprite("Platform", assetName) image.sprite = sprite end function TextHelper_Get24HourTimeStr(time) if time < 10 then return "0" .. time else return time end end function PrintWanNum(num) num = tonumber(num) if num >= 100000000 then return string.format("%.1f", num / 100000000) .. Language[11028] elseif num >= 1000000 then return tostring(math.floor(num / 10000)) .. Language[10037] else return tostring(num) end end function PrintWanNum2(num) num = tonumber(num) if num >= 100000000 then return string.format("%.1f", num / 100000000) .. Language[11028] elseif num >= 100000 then return tostring(math.floor(num / 10000)) .. Language[10037] --return tostring(math.floor(num / 1000)/10) .. "万" else return tostring(num) end end function PrintWanNum3(num) num = tonumber(num) if num >= 100000000 then return string.format("%.2f", num / 100000000) .. Language[11028] elseif num >= 100000 then return string.format("%.2f",num / 10000) .. Language[10037] else return tostring(num) end end --判断两个时间在同一天 function Util_Check_insameday(time1, time2) local date1 = os.date("*t", time1) local date2 = os.date("*t", time2) if date1.year == date2.year and date1.month == date2.month and date1.day == date2.day then return true end return false end --判断两个时间在同一个月 function Util_Check_insamemonth(time1, time2) local date1 = os.date("*t", time1) local date2 = os.date("*t", time2) if date1.year == date2.year and date1.month == date2.month then return true end return false end --判断两个时间在同一星期 function Util_Check_insameweek(time1, time2) local week_second = 7 * 24 * 3600 local time_zero = os.time { year = 2015, month = 1, day = 5, hour = 0, min = 0, sec = 0 } local time1_tran = time1 - time_zero local time2_tran = time2 - time_zero local week1 = math.floor(time1_tran / week_second) local week2 = math.floor(time2_tran / week_second) if week1 == week2 then return true end return false end --秒转换成文字对应时间 function GetTimeStrBySeconds(_seconds) return os.date(Language[10774], _seconds) end --秒转换成文字对应时间 只有分秒 function GetTimeMaoHaoStrBySeconds(_seconds) return os.date("%M:%S", _seconds) end --秒转换成文字对应时间只有月日时 function GetTimeMonthDayMinBySeconds(_seconds) return os.date(Language[12284], _seconds) end function PrintTable(root) local cache = { [root] = "." } local function _dump(t, space, name) if type(t) == "table" then local temp = {} for k, v in pairs(t) do local key = tostring(k) if cache[v] then tinsert(temp, "+" .. key .. " {" .. cache[v] .. "}") elseif type(v) == "table" then local new_key = name .. "." .. key cache[v] = new_key tinsert(temp, "+" .. key .. _dump(v, space .. (next(t, k) and "|" or " ") .. srep(" ", #key), new_key)) else tinsert(temp, "+" .. key .. " [" .. tostring(v) .. "]") end end return tconcat(temp, "\n" .. space) end end print(_dump(root, "", "")) end local isPcall = true --用于查找错误用 function MyPCall(func, ...) if not isPcall then func() return end local flag, msg = pcall(func) if not flag then LogError(msg) local args = {...} if #args > 0 then local s = "" for k, v in ipairs(args) do s = s .. "|" .. tostring(v) end LogRed("error params:"..s) end end end function PlayUIAnims(gameObject, callback) local anims = gameObject:GetComponentsInChildren(typeof(PlayFlyAnim)) if anims.Length > 0 then for i = 0, anims.Length - 1 do anims[i]:PlayAnim(false, callback) end end end function PlayUIAnimBacks(gameObject, callback) local anims = gameObject:GetComponentsInChildren(typeof(PlayFlyAnim)) if anims.Length > 0 then for i = 0, anims.Length - 1 do anims[i]:PlayHideAnim(callback) end end end function PlayUIAnim(gameObject, callback) local anim = gameObject:GetComponent(typeof(PlayFlyAnim)) if anim then anim:PlayAnim(false, callback) end end function StringToTable(str) local list={} local aa=string.split(str,"|") for i=1,#aa do local bb=string.split(aa[i],"#") list[i]={} for j=1,#bb do list[i][j]=tonumber(bb[j]) end end return list end function SecTorPlayAnim(prefabList,_scale) local scale = 0.05 if _scale then scale = _scale end for i, node in ipairs(prefabList) do Timer.New(function () node.gameObject:SetActive(true) PlayUIAnim(node.gameObject) end,scale*(i-1)):Start() end end function SecTorPlayAnimByScroll(scroll,_scale) local scale = 0.05 if _scale then scale = _scale end -- scroll:ForeachItemGO(function (index, go) -- Timer.New(function () -- go.gameObject:SetActive(true) -- PlayUIAnim(go.gameObject) -- end, scale*(index-1)):Start() -- end) end function PlayUIAnimBack(gameObject, callback) --local anim = gameObject:GetComponent(typeof(PlayFlyAnim)) local anim = gameObject:GetComponent("PlayFlyAnim") if anim then anim:PlayHideAnim(callback) end end --地图uv坐标 function Map_UV2Pos(u, v) return u * 256 + v end --地图uv坐标 function Map_Pos2UV(pos) return math.floor(pos / 256), pos % 256 end -- 公会地图坐标精细化处理 function GuildMap_UV2Pos(u, v) -- return u * 256 + v local _u = math.floor(u *100) local _v = math.floor(v *100) return _u * 25600 + _v end function GuildMap_Pos2UV(pos) -- return math.floor(pos / 256), pos % 256 local _u = math.floor(pos/25600)/100 local _v = pos%25600/100 return math.round(_u), math.round(_v), _u, _v end function GetStarOrGodSoulLv(index,data) if data.star>=11 then return data.star,3 end if data.godSoulLv and data.godSoulLv > 0 then return data.godSoulLv,3 elseif data.star > 9 then return data.star,2 end return data.star,index end function SetHeroFlyEffect(par,spLoader,_star,_layer,_scale,imgFloor,addY,isList) local effect=Util.GetGameObject(par, "c_long_touxiang_lizi(Clone)") local img=Util.GetGameObject(par,"flyImg") local y=0 if addY then y=addY end if img==nil then img = poolManager:LoadAsset("FlyUpImg", PoolManager.AssetType.GameObject) -- newObject("FlyUpImg") img.transform:SetParent(par.transform) img.name="flyImg" --img:GetComponent("RectTransform").sizeDelta = Vector2.New(116,50) img.transform.localScale = Vector3.one*_scale img.transform.localPosition = Vector3.New(0,71*_scale+y,0) if imgFloor then img.transform:SetSiblingIndex(imgFloor) else img.transform:SetSiblingIndex(3) end else if _star>11 then img.gameObject:SetActive(true) else img.gameObject:SetActive(false) end end img=img:GetComponent("Image") local go=img if _star>11 then if _star>13 then go.gameObject:SetActive(false) else go.gameObject:SetActive(false) end if effect==nil then effect=poolManager:LoadAsset("c_long_touxiang_lizi", PoolManager.AssetType.GameObject) end SetParticleSortLayer(effect,_layer) effect:SetActive(false) effect.transform:SetParent(par.transform) effect:GetComponent("RectTransform").localPosition = Vector3.New(0,y,0) effect:GetComponent("RectTransform").localScale = Vector3.New(1,1,1)*_scale effect.transform:SetAsFirstSibling() local long1=Util.GetGameObject(effect, "longaniduan") local long2=Util.GetGameObject(effect, "longaniduan (1)") local bg1=Util.GetGameObject(effect, "baoguang (9)") local bg2=Util.GetGameObject(effect, "baoguang (10)") local bg3=Util.GetGameObject(effect, "c_ui_qinyan_duan") long1:SetActive(false) long2:SetActive(false) bg1:SetActive(false) bg2:SetActive(false) bg3:SetActive(false) if _star==14 then go.sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_daoju1") elseif _star==15 then go.sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_daoju2") bg1:SetActive(true) bg2:SetActive(true) elseif _star==16 then bg1:SetActive(true) bg2:SetActive(true) bg3:SetActive(true) -- long1:SetActive(true) -- long2:SetActive(true) go.sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_daoju2") end if isList and isList==true then local particles=effect:GetComponentsInChildren(typeof(UnityEngine.ParticleSystem)) for key, value in pairs(particles:ToTable()) do local mat=value:GetComponent(typeof(UnityEngine.Renderer)) if mat.material.shader.name=="YXZ/Effect/Mix Masking(Without Moving)_alphablend" then mat.material.shader=poolManager:LoadAsset("YXZ_MixMaskingWithoutMoving_alphablend_1",poolManager.AssetType.Other) end end end else go.gameObject:SetActive(false) if effect~=nil then effect:SetActive(false) end end go:SetNativeSize() return effect end function SetHeroFormationFlyEffect(par,spLoader,effect,_star,_layer) local li=Util.GetGameObject(effect,"lizi2") local bg1=Util.GetGameObject(effect,"dajin_effect_03") local bg2=Util.GetGameObject(effect,"c_ui_qinyan_kuan") local long1=Util.GetGameObject(effect,"longaniduan1") local long2=Util.GetGameObject(effect,"longaniduan2") li:SetActive(false) long1:SetActive(false) long2:SetActive(false) bg1:SetActive(false) bg2:SetActive(false) if _star<=13 then bg1:SetActive(true) else bg2:SetActive(true) end SetParticleSortLayer(effect,_layer) --SetParticleSortLayer(effect2,_layer) local img=Util.GetGameObject(par,"flyImg") if img==nil then if _star<=11 then return end img = poolManager:LoadAsset("FlyUpImg", PoolManager.AssetType.GameObject) img.transform:SetParent(par.transform) img.name="flyImg" img.transform.localScale = Vector3.one img:GetComponent("RectTransform").sizeDelta = Vector2.New(126,110) img.transform.localPosition = Vector3.New(95,180,0) else img:SetActive(false) end if _star<=11 then img:SetActive(false) return end img=img:GetComponent("Image") img.gameObject:SetActive(false) if _star==12 then img.sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_kapai1") elseif _star==13 then li:SetActive(true) img.sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_kapai2") elseif _star==14 then li:SetActive(true) -- long1:SetActive(true) -- long2:SetActive(true) img.sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_kapai2") else img.gameObject:SetActive(false) end end function GetPassiveByMaxStar(heroConfig,list) --local OpenPassiveSkillRules = list local heroRankUp=ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.HeroRankupConfig,"Type",2,"OpenStar",heroConfig.MaxRank) if not heroRankUp then list=heroConfig.OpenPassiveSkillRules end local aaa={} if list then for i = 1,#list do if list[i][2]<=heroRankUp.Id then table.insert(aaa,list[i]) end end end return aaa end function GetPassiveByMaxStar2(heroConfig,list,star) --local OpenPassiveSkillRules = list local heroRankUp=ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.HeroRankupConfig,"Type",2,"OpenStar",star) if not heroRankUp then list=heroConfig.OpenPassiveSkillRules end local aaa={} if list then local skillList={} for i = 1,#list do local id=list[i][2] if id<=heroRankUp.Id then table.insert(aaa,list[i]) --skillList[id]=list[i] end end -- for key, value in pairs(skillList) do -- table.insert(aaa,value) -- end end return aaa end --把英雄星级父对象和星级传过来 type 1 第6-11个预设 type 2 第12-17个预设 type 3 第18-24个预设 function SetHeroStars(spLoader, starGrid, star, type,_starSize,_scale,_pivot,rotation) -- local horizonta = starGrid:GetComponent("LayoutGroup") -- if not horizonta then -- local pos = starGrid:GetComponent("RectTransform").anchoredPosition3D -- pos.y = -1.03 -- starGrid:GetComponent("RectTransform").anchoredPosition3D = pos -- horizonta = starGrid:AddComponent(typeof(UnityEngine.UI.HorizontalLayoutGroup)) -- horizonta.childAlignment = "LowerLeft" -- end --LogError("star====="..star) if type==nil then type=1 end if star>=11 then type=3 end if type==3 then star=star-10 end local starSize if not _starSize and type == 3 then --第一个值代表缩放,第二个值代表y轴移动到的y轴的位置 starSize = Vector3.New(1,-15.6) elseif not _starSize and star >= 10 then starSize = Vector2(60,57) else starSize = Vector2(35,35) end if _starSize then starSize = _starSize end local scale = -17.78 if type == 3 then scale = -13 end if _scale then scale = _scale end local pivot = Vector2.zero if _pivot then pivot = _pivot end local starPre = Util.GetGameObject(starGrid, "starGrid(Clone)") if not starPre then starPre = poolManager:LoadAsset("starGrid", PoolManager.AssetType.GameObject) end local size = starPre:GetComponent("RectTransform").sizeDelta size.y = starSize.y starPre.transform.sizeDelta = size starPre.transform:SetParent(starGrid.transform) starPre:GetComponent("RectTransform").localPosition = Vector3.zero starPre:GetComponent("RectTransform").localScale = Vector3.New(1,1,1) starPre.transform:SetAsFirstSibling() starPre:GetComponent("LayoutGroup").spacing = scale starPre:GetComponent("RectTransform").pivot = pivot starPre.transform:GetChild(0).gameObject:SetActive(false) LogError("star============="..star.." type=========="..type) if star < 7 and type and type == 3 then starPre.transform:GetChild(0).gameObject:SetActive(true) for i = 2, 24 do if i > 18 and i <= star + 18 then starPre.transform:GetChild(i - 1).gameObject:SetActive(true) --starPre.transform:GetChild(i - 1):GetComponent("RectTransform").sizeDelta = starSize local fx_shenhun = Util.GetGameObject(starPre.transform:GetChild(i - 1),"fx_shenhun") if fx_shenhun then local fixedScale = 1/ Util.GetGameObject(fx_shenhun,"zong/Particle System").transform.localScale.x Util.SetParticleScale(fx_shenhun,fixedScale) Util.SetParticleScale(fx_shenhun,starSize.x) local pos = fx_shenhun.transform.localPosition pos.y = starSize.y fx_shenhun.transform.localPosition = pos end else starPre.transform:GetChild(i - 1).gameObject:SetActive(false) end end elseif star < 6 then for i = 2, 24 do if i - 1 <= star then starPre.transform:GetChild(i - 1):GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroStarImage[1]) starPre.transform:GetChild(i - 1):GetComponent("RectTransform").sizeDelta = starSize if rotation then starPre.transform:GetChild(i - 1):GetComponent("RectTransform").rotation = Quaternion.Euler(rotation) end starPre.transform:GetChild(i - 1).gameObject:SetActive(true) else starPre.transform:GetChild(i - 1).gameObject:SetActive(false) end end elseif star > 5 and star < 10 then for i = 2, 24 do if i - 1 <= star - 5 then starPre.transform:GetChild(i - 1):GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroStarImage[2]) starPre.transform:GetChild(i - 1):GetComponent("RectTransform").sizeDelta = starSize if rotation then starPre.transform:GetChild(i - 1):GetComponent("RectTransform").rotation = Quaternion.Euler(rotation) end starPre.transform:GetChild(i - 1).gameObject:SetActive(true) else starPre.transform:GetChild(i - 1).gameObject:SetActive(false) end end elseif star > 9 then if type and type == 1 then for i = 2, 24 do if i - 1 == star - 4 then starPre.transform:GetChild(i - 1).gameObject:SetActive(true) starPre.transform:GetChild(i - 1):GetComponent("RectTransform").sizeDelta = starSize else starPre.transform:GetChild(i - 1).gameObject:SetActive(false) end end -- elseif type and type == 2 then -- for i = 2, 24 do -- if i > 11 and i == star + 2 then -- starPre.transform:GetChild(i - 1).gameObject:SetActive(true) -- starPre.transform:GetChild(i - 1):GetComponent("RectTransform").sizeDelta = starSize -- else -- starPre.transform:GetChild(i - 1).gameObject:SetActive(false) -- end -- end else for i = 2, 24 do if i - 1 == star - 4 then starPre.transform:GetChild(i - 1).gameObject:SetActive(true) starPre.transform:GetChild(i - 1):GetComponent("RectTransform").sizeDelta = starSize else starPre.transform:GetChild(i - 1).gameObject:SetActive(false) end end end end ForceRebuildLayout(starGrid.transform) end --设置英雄立绘朝向 function SetHEeroLiveToward(go,toward,pos) if go and toward==1 then go.transform.rotation=Vector3.New(0,180,0) if pos then go.transform.localPosition=Vector3.New(-pos[1],pos[2],0) end else go.transform.rotation=Vector3.New(0,0,0) end end function SetHeroBg(spLoader, bg,cardBg,star,quality,layer) local hong = Util.GetGameObject(bg,"Effect_UI_yansekuang_HongSe") local bai = Util.GetGameObject(bg,"Effect_UI_yansekuang_BaiSe") local fly = Util.GetGameObject(bg,"c_long_bansheng_lizishan") local flyImg=Util.GetGameObject(bg,"flyImg") -- if quality ~= 0 then -- bg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardStarImage[quality]) -- end if star <= 5 then cardBg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardQuantityImage[star]) bg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardStarImageBG[star]) if hong then hong.gameObject:SetActive(false) end if bai then bai.gameObject:SetActive(false) end elseif star <= 9 then cardBg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardQuantityImage[5]) bg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardStarImageBG[5]) if hong then hong.gameObject:SetActive(false) end if bai then bai.gameObject:SetActive(false) end elseif star <= 10 then cardBg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardQuantityImage[10]) bg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardStarImageBG[10]) if hong then hong.gameObject:SetActive(true) end if bai then bai.gameObject:SetActive(false) end else cardBg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardQuantityImage[star]) bg:GetComponent("Image").sprite = spLoader:LoadSprite(GetHeroCardStarImageBG[star]) if hong then hong.gameObject:SetActive(false) end if bai then bai.gameObject:SetActive(true) end end if fly and flyImg and layer then local shan=Util.GetGameObject(bg,"c_long_bansheng_lizishan/lizi") local bgEffect2=Util.GetGameObject(bg,"c_long_bansheng_lizishan/dajin_effect_03") local bgEffect=Util.GetGameObject(bg,"c_long_bansheng_lizishan/c_ui_qinyan_chang") local long=Util.GetGameObject(bg,"c_long_bansheng_lizishan/konglong") shan:SetActive(false) bgEffect:SetActive(false) bgEffect2:SetActive(false) long:SetActive(false) if star>13 then flyImg.gameObject:SetActive(false) if star==14 then shan:SetActive(true) flyImg:GetComponent("Image").sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_kapai1") elseif star==15 then shan:SetActive(true) bgEffect:SetActive(false) flyImg:GetComponent("Image").sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_kapai2") elseif star==16 then shan:SetActive(true) bgEffect:SetActive(true) --long:SetActive(true) flyImg:GetComponent("Image").sprite=spLoader:LoadSprite("r_tongyong_tianfufeisheng_kapai2") end else shan:SetActive(false) bgEffect:SetActive(false) long:SetActive(false) flyImg.gameObject:SetActive(false) end SetParticleSortLayer(bg,layer) SetParticleSortLayer(long,layer) else if flyImg then flyImg.gameObject:SetActive(false) end if fly then fly:SetActive(false) end end end --把英雄星级父对象和星级传过来 local star2index = { [1] = {3}, [2] = {2, 4}, [3] = {2, 3, 4}, [4] = {1, 2, 4, 5}, [5] = {1, 2, 3, 4, 5} } function SetCardStars(starGrid, star,starType,lstarScale) local starScale = lstarScale and lstarScale or 8 if star==0 then starGrid.gameObject:SetActive(false) return else starGrid.gameObject:SetActive(true) end if star>=11 then starType=3 end if starType == 3 then starScale = 25 star=star-10 end for i = 1, starGrid.transform.childCount do starGrid.transform:GetChild(i - 1).gameObject:SetActive(false) end if star < 6 then if starType == 3 then for _, i in ipairs(star2index[star]) do starGrid.transform:GetChild(16 + i - 1).gameObject:SetActive(true) end else for _, i in ipairs(star2index[star]) do starGrid.transform:GetChild(i - 1).gameObject:SetActive(true) end end elseif star > 5 and star < 10 then for _, i in ipairs(star2index[star-5]) do starGrid.transform:GetChild(5 + i - 1).gameObject:SetActive(true) end elseif star > 9 then starGrid.transform:GetChild(star).gameObject:SetActive(true) if star > 10 then Util.GetGameObject(starGrid.transform:GetChild(star),"star").gameObject:SetActive(false) end end starGrid:GetComponent("LayoutGroup").spacing = starScale ForceRebuildLayout(starGrid.transform) end -- 在给定节点下加载预设, 返回实例化的预设 function newObjToParent(prefab, parent) local go = newObject(prefab) go.transform:SetParent(parent.transform) go.transform.localScale = Vector3.one go.transform.localPosition = Vector3.zero go:SetActive(true) return go end -- 清除节点下所有的子节点 function ClearChild(parent) Util.ClearChild(parent.transform) end -- 加载一个商店使用的item function AddShopItem(parent, itemId, shopType) local item = SubUIManager.Open(SubUIConfig.ShopItemView, parent.transform) item:OnOpen(itemId, shopType) return item end -- 根据ID返回物品的Icon,配置数据在artResourceConfig中 function SetIcon(spLoader, id) if not id or id == 0 then Log("设置的物品Icon不存在!") return end local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local icon = nil local resId = itemConfig[id].ResourceID if not resId then Log("资源ID不存在!!") return end local resPath = GetResourcePath(resId) if not resPath then Log("尚未有此类美术资源!!") return end icon = spLoader:LoadSprite(resPath) return icon,itemConfig[id] end function SetFrame(spLoader, id) if not id or id == 0 then Log("设置的物品Icon不存在!") return end local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local icon = nil local resId = itemConfig[id].Quantity if not resId then Log("资源ID不存在!!") return end icon = spLoader:LoadSprite(GetQuantityImageByquality(resId)) return icon end --属性表ID转换表 function GetProIndexByProId(proId) local proIndex = 0 if proId == 1 then -- 最大生命 proIndex = 3 elseif proId == 2 then -- 攻击力 proIndex = 4 elseif proId == 3 then -- 护甲 proIndex = 5 elseif proId == 4 then -- 魔抗 proIndex = 6 elseif proId == 5 then -- 速度 proIndex = 7 elseif proId == 6 or proId == 67 or proId == 68 then -- 当前生命值 proIndex = 2 elseif proId == 51 then -- 伤害加成 proIndex = 8 elseif proId == 52 then -- 伤害减免 proIndex = 9 elseif proId == 53 then -- 效果命中 proIndex = 10 elseif proId == 54 then -- 效果抵抗 proIndex = 11 elseif proId == 55 then -- 暴击率 proIndex = 12 elseif proId == 56 then -- 暴伤 proIndex = 13 elseif proId == 57 then -- 回复率 proIndex = 14 elseif proId == 101 then -- 火焰伤害 proIndex = 15 elseif proId == 102 then -- 狂风伤害 proIndex = 16 elseif proId == 103 then -- 碧水伤害 proIndex = 17 elseif proId == 104 then -- 大地伤害 proIndex = 18 elseif proId == 105 then -- 神圣伤害 elseif proId == 106 then -- 黑暗伤害 elseif proId == 107 then -- 火焰抗性 elseif proId == 108 then -- 狂风抗性 elseif proId == 109 then -- 碧水抗性 elseif proId == 110 then -- 大地抗性 elseif proId == 111 then -- 神圣抗性 elseif proId == 112 then -- 黑暗抗性 end return proIndex end --逐渐显示对应文字内容,若在此期间点击屏幕,则立刻显示完文字内容 function ShowText(go, str, duration, callBack) local text = go:GetComponent("Text") text.text = "" local tween = text:DOText(str, duration) local isClick = false tween:OnUpdate(function() if Input.GetMouseButtonDown(0) then isClick = true end if isClick then if tween then tween:Kill() go:GetComponent("Text").text = str if callBack then callBack() end end end end) tween:OnComplete(callBack) end -- 将秒转换成分:秒格式返回 function SetTimeFormation(seconds) local str = "" local ten_minute = math.modf(seconds / 600) local minute = math.modf(seconds / 60) % 10 local ten_second = math.modf(seconds / 10) % 6 local second = seconds % 10 str = ten_minute .. minute .. " : " .. ten_second .. second return str end function Dump(data, showMetatable, lastCount) if type(data) == "table" then --Format local count = lastCount or 0 count = count + 1 local B2 = "" for i = 1, count do B2 = B2 .. " " end Log(B2 .. "{\n") --Metatable if showMetatable then local blank = " " for i = 1, count do blank = blank .. " " end local mt = getmetatable(data) Log(blank .. "\"__metatable\" = ") Dump(mt, showMetatable, count) end --Key for key, value in pairs(data) do local blank = " " for i = 1, count do blank = blank .. " " end if type(key) == "string" then Log(blank .. "\"" .. key .. "\" = " .. GetStr(value)) elseif type(key) == "number" then Log(blank .. "[" .. key .. "] = " .. GetStr(value)) else Log(blank .. string.format("%s", key) .. GetStr(value)) end Dump(value, showMetatable, count) end --Format local B0 = " " for i = 1, lastCount or 0 do B0 = B0 .. " " end Log(B0 .. "}") end --Format if not lastCount then Log("\n") end end function GetStr(data) local str = "" if type(data) ~= "table" then --Value if type(data) == "string" then str = ("\"" .. data .. "\"") elseif data == nil then str = "nil" else str = (string.format("%s", data)) end end return str end function GetBgByHeroNatural(id) if id == 1 then return "UI_hz_beibao_pinjise_chengse" elseif id == 2 then return "UI_hz_beibao_pinjise_chengse" elseif id == 3 then return "UI_hz_beibao_pinjise_chengse" elseif id == 4 then return "UI_hz_beibao_pinjise_chengse" elseif id == 5 then return "UI_hz_beibao_pinjise_hongse" elseif id == 6 then return "UI_hz_beibao_pinjise_huangse" elseif id == 7 then return "UI_hz_beibao_pinjise_huangse" end end --通过item稀有度读取背景框 function GetQuantityImageByquality(quality,star) if star then--and star > 5 if star == 1 then --huise,但是没图 return "UI_hz_beibao_pinjise_06_2" elseif star == 2 then return "UI_hz_beibao_pinjise_lvse" elseif star == 3 then return "UI_hz_beibao_pinjise_qingse" elseif star == 4 then return "UI_hz_beibao_pinjise_zise" elseif star == 5 then return "UI_hz_beibao_pinjise_chengse" elseif star >= 6 and star <=10 then return "UI_hz_beibao_pinjise_hongse" elseif star == 11 then return "UI_hz_beibao_pinjise_06_1" else return "UI_hz_beibao_pinjise_06_2" end -- if star == 1 then -- return "UI_hz_beibao_pinjise_06_2" -- elseif star == 2 then -- return "UI_hz_beibao_pinjise_lvse" -- elseif star == 3 then -- return "UI_hz_beibao_pinjise_qingse" -- elseif star == 4 then -- return "UI_hz_beibao_pinjise_zise" -- elseif star == 5 then -- return "UI_hz_beibao_pinjise_chengse" -- elseif star >= 6 and star <=10 then -- return "UI_hz_beibao_pinjise_hongse" -- elseif star == 11 then -- return "UI_hz_beibao_pinjise_huangse" -- end else if quality == 0 or quality == 1 then return "UI_hz_beibao_pinjise_06_2" elseif quality == 2 then return "UI_hz_beibao_pinjise_lvse" elseif quality == 3 then return "UI_hz_beibao_pinjise_qingse" elseif quality == 4 then return "UI_hz_beibao_pinjise_zise" elseif quality == 5 then return "UI_hz_beibao_pinjise_chengse" elseif quality == 6 then return "UI_hz_beibao_pinjise_hongse" elseif quality == 7 then return "UI_hz_beibao_pinjise_huangse" elseif quality >= 8 then return "UI_hz_beibao_pinjise_06_1" end -- if quality == 0 or quality == 1 then -- return "UI_hz_beibao_pinjise_06_2" -- elseif quality == 2 then -- return "UI_hz_beibao_pinjise_lvse" -- elseif quality == 3 then -- return "UI_hz_beibao_pinjise_qingse" -- elseif quality == 4 then -- return "UI_hz_beibao_pinjise_zise" -- elseif quality == 5 then -- return "UI_hz_beibao_pinjise_chengse" -- elseif quality == 6 then -- return "UI_hz_beibao_pinjise_hongse" -- elseif quality == 7 then -- return "UI_hz_beibao_pinjise_huangse" -- elseif quality >= 8 then -- end end end --通过item稀有度读取背景框 function GetQuantityImageByqualityPoint(quality) if quality == 1 then return "r_hunyin_zise" elseif quality == 2 then return "r_hunyin_zise" elseif quality == 3 then return "r_hunyin_zise" elseif quality == 4 then return "r_hunyin_zise" elseif quality == 5 then return "r_hunyin_chengse" elseif quality == 6 then return "r_hunyin_hongse" elseif quality == 7 then return "r_hunyin_caise" else return "r_hunyin_caise" end end --通过item稀有度读取文字 function GetQuantityStrByquality(quality) if quality == 1 then return Language[10181] elseif quality == 2 then return Language[10180] elseif quality == 3 then return Language[10179] elseif quality == 4 then return Language[10178] elseif quality == 5 then --原橙色改为金色 return Language[10176] elseif quality == 6 then return Language[10177] elseif quality == 7 then return "白金" else return Language[10181] end end --通过Hero稀有度读取碎片遮罩(小) function GetHeroChipQuantityImageByquality(quality) if quality == 1 then return "PieceMask_white" elseif quality == 2 then return "PieceMask_green" elseif quality == 3 then return "PieceMask_blue" elseif quality == 4 then return "PieceMask_purple" elseif quality == 5 then return "PieceMask_goden" elseif quality == 6 then return "PieceMask_red" elseif quality == 7 then return "PieceMask_Platinum_01" else return "PieceMask_white" end end --通过Hero稀有度读取背景框(小) function GetHeroQuantityImageByquality(quality,star) if star and star>0 then--and star > 5 if star == 1 then return "UI_hz_beibao_pinjise_06_2" elseif star == 2 then return "UI_hz_beibao_pinjise_lvse" elseif star == 3 then return "UI_hz_beibao_pinjise_qingse" elseif star == 4 then return "UI_hz_beibao_pinjise_zise" elseif star == 5 then return "UI_hz_beibao_pinjise_chengse" elseif star >= 6 and star <=10 then return "UI_hz_beibao_pinjise_hongse" elseif star == 11 then return "UI_hz_beibao_pinjise_huangse" else return "UI_hz_beibao_pinjise_06_3" end else if quality == 0 or quality == 1 then return "UI_hz_beibao_pinjise_06_2" elseif quality == 2 then return "UI_hz_beibao_pinjise_lvse" elseif quality == 3 then return "UI_hz_beibao_pinjise_qingse" elseif quality == 4 then return "UI_hz_beibao_pinjise_zise" elseif quality == 5 then return "UI_hz_beibao_pinjise_chengse" elseif quality == 6 then return "UI_hz_beibao_pinjise_hongse" elseif quality >= 7 then return "UI_hz_beibao_pinjise_huangse" end end end function GetHeroQuantityImageByHeroNatural(quality) if quality == 0 or quality == 1 then return "UI_hz_beibao_pinjise_06_2" elseif quality == 2 then return "UI_hz_beibao_pinjise_lvse" elseif quality == 3 then return "UI_hz_beibao_pinjise_qingse" elseif quality == 4 then return "UI_hz_beibao_pinjise_chengse" elseif quality == 5 then return "UI_hz_beibao_pinjise_hongse" elseif quality >= 6 then return "UI_hz_beibao_pinjise_huangse" end end --通过Hero稀有度读取背景框(卡库)外框 function GetHeroCardQuantityWaiImageByquality(quality) if quality <= 3 then return "r_hero_lankuang" elseif quality == 4 then return "r_hero_zikuang" elseif quality == 5 then return "r_hero_huangkuang" elseif quality > 5 then return "r_hero_huangkuang" end end --通过Hero或异妖稀有度读取资质框 function GetQuantityImage(spLoader, quality) local sprite if quality<11 then sprite=spLoader:LoadSprite(AptitudeQualityFrame[1]) elseif quality>=11 and quality<13 then sprite=spLoader:LoadSprite(AptitudeQualityFrame[2]) elseif quality>=13 and quality<15 then sprite=spLoader:LoadSprite(AptitudeQualityFrame[3]) elseif quality>=15 and quality<17 then sprite=spLoader:LoadSprite(AptitudeQualityFrame[4]) elseif quality>=17 and quality<19 then sprite=spLoader:LoadSprite(AptitudeQualityFrame[5]) end return sprite end --通过装备位置获得装备位置类型字符串 function GetEquipPosStrByEquipPosNum(_index) if _index == 1 then return Language[10391] elseif _index == 2 then return Language[12041] elseif _index == 3 then return Language[10393] elseif _index == 4 then return Language[12042] elseif _index == 5 then return "界神技" elseif _index == 6 then return Language[12044] elseif _index == 7 then return "主角礼物" elseif _index == 8 then return "英雄礼物" end end --通过职业获取职业字符串 function GetJobStrByJobNum(_index) if _index == 0 then return Language[12045] elseif _index == 1 then return Language[11971] elseif _index == 2 then return Language[11972] elseif _index == 3 then return Language[11973] elseif _index == 4 then return Language[11974] elseif _index == 5 then return Language[11975] end end --通过职业获取职业字符串 function GetJobSpriteStrByJobNum(_index) if _index == 1 then return "r_hero_huo 1_zh" elseif _index == 2 then return "r_hero_feng 1_zh" elseif _index == 3 then return "r_hero_shui 1_zh" elseif _index == 4 then return "r_hero_dadi 1_zh" elseif _index == 5 then return "r_hero_dadi 1_zh" elseif _index == 6 then return "r_hero_dadi 1_zh" else return "r_hero_huo 1_zh" end end --角色定位ID 获取角色定位背景图片 function GetHeroPosBgStr(_i) if _i==1 then return "r_hero_roudundi" elseif _i==2 then return "r_hero_shuchudi" elseif _i==3 then return "r_hero_kongzhidi" elseif _i==4 then return "r_hero_fuzhudi" end end function GetTianFuIcon(star) local aaa="r_tongyong_feisheng_icon" if star==14 then aaa="r_tongyong_feisheng_icon3" elseif star==13 then aaa="r_tongyong_feisheng_icon2" elseif star==12 then aaa="r_tongyong_feisheng_icon1" elseif star==11 then aaa="r_tongyong_tianfu_icon" end return aaa end --根据角色定位Id 获取角色定位图 function GetHeroPosStr(_i) if _i==1 then return "UI_hz_zhonghe02_25_1" elseif _i==2 then return "UI_hz_zhonghe02_25" elseif _i==3 then return "UI_hz_zhonghe02_25_3" elseif _i==4 then return "UI_hz_zhonghe02_25_2" end end --根据角色定位Id 获取角色定位图 function GetHeroQualityStr(_i,star) if star and star>11 then return "r_hero_pinzhi_shenhua" end if _i==1 then return "r_hero_pinzhi_putong" elseif _i==2 then return "r_hero_pinzhi_lianghao" elseif _i==3 then return "r_hero_pinzhi_youxiu" elseif _i==4 then return "r_hero_pinzhi_xiyou" elseif _i==5 then return "r_hero_pinzhi_shishi" elseif _i==6 then return "r_hero_pinzhi_chuanshuo" elseif _i==7 then return "r_hero_pinzhi_shenhua" end end --根据角色职业Id 获取角色职业图标 function GetHeroProfessionById(_professionId) if _professionId==1 then return "ui_yz_zd" elseif _professionId==2 then return "ui_ss_zd" elseif _professionId==3 then return "ui_zhs_zd" elseif _professionId==4 then return "ui_lds_zd" end end --获取技能类型 data 当前技能数据 function GetSkillType(data) local SkillIconType={"r_hero_pu_zh","r_hero_jue_zh","r_hero_bei_zh","r_hero_fei_zh"} if data.skillConfig.Type == SkillType.Pu then return SkillIconType[SkillType.Pu]--普技 elseif data.skillConfig.Type == SkillType.Jue then return SkillIconType[SkillType.Jue]--绝技 elseif data.skillConfig.Type == SkillType.Bei then return SkillIconType[SkillType.Bei]--被动技 elseif data.skillConfig.Type == SkillType.Fei then return SkillIconType[SkillType.Fei]--被动技 end end function GetSkillTypeDes(data) if data.skillConfig.Type == SkillType.Pu then return "普"--普技 elseif data.skillConfig.Type == SkillType.Jue then return "绝"--绝技 elseif data.skillConfig.Type == SkillType.Bei then return "被"--被动技 elseif data.skillConfig.Type == SkillType.Fei then return "火"--被动技 end end --通过角色属性获取角色属性图标 function GetProStrImageByProNum(_index) if _index == 1 then return "r_hero_huo 1_zh"--人 elseif _index == 2 then return "r_hero_feng 1_zh"--佛 elseif _index == 3 then return "r_hero_shui 1_zh"--妖 elseif _index == 4 then return "r_hero_dadi 1_zh"--道 elseif _index == 5 then return "z_icon_qingjinbao"--时空 elseif _index == 6 then return "z_icon_qingjinbao" else return "z_icon_01_zh"--全部 end end --通过装备位置获得装备位置类型字符串 function GetQuaStringByEquipQua(_Qua) -- if _Qua == 1 then return Language[12046] elseif _Qua == 2 then return Language[12047] elseif _Qua == 3 then return Language[12048] elseif _Qua == 4 then return Language[12049] elseif _Qua == 5 then return Language[12050] elseif _Qua == 6 then return Language[12051] elseif _Qua == 7 then return Language[12052] elseif _Qua == 8 then return "[神话]" end end --通过item稀有度获取改颜色的文字 function GetStringByEquipQua(_Qua, _Str) if _Qua == 1 then return string.format("%s", _Str) elseif _Qua == 2 then return string.format("%s", _Str) elseif _Qua == 3 then return string.format("%s", _Str) elseif _Qua == 4 then return string.format("%s", _Str) elseif _Qua == 5 then return string.format("%s", _Str) elseif _Qua == 6 then return string.format("%s", _Str) elseif _Qua == 7 then return string.format("%s", _Str) elseif _Qua == 8 then return string.format("%s", _Str) end end --冒险通过区域序号取得区域名称美术字图标 function GetAreaNameIconByAreaNumer(index) if index == 1 then return "r_guaji_qiyuanzhidi" elseif index == 2 then return "r_guaji_yiwangzhilu" elseif index == 3 then return "r_guaji_houhuizhishi" elseif index == 4 then return "r_guaji_zuifashengdian" elseif index == 5 then return "r_guaji_qidaoshengsuo" elseif index == 6 then return "r_guaji_youjieyehuo" elseif index == 7 then return "r_guaji_wushengmishi" elseif index == 8 then return "r_guaji_wanshenghuanghun" end end --- N钟,N时,N天 function GetLeftTimeStrByDeltaTime(deltaTime) if deltaTime > 86400 then return math.floor(deltaTime / 86400) .. Language[10017] end if deltaTime > 3600 then return math.floor(deltaTime / 3600) .. Language[12053] end if deltaTime > 60 then return math.floor(deltaTime / 60) .. Language[12054] end return math.floor(deltaTime)..Language[10316] end function GetLeftTimeStrByDeltaTime2(second) local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = math.floor(second % 60) local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) if second > 86400 then return day .. Language[10017]..hour ..Language[10970] end if second > 3600 then return hour..Language[10970]..minute .. Language[12054] end return minute .. Language[12054] .. sec .. Language[10316] end --- 获取经历的时间字符串 --- 刚刚,N分钟前,N小时前,N天前 function GetDeltaTimeStrByDeltaTime(deltaTime) if deltaTime > 86400 then return math.floor(deltaTime / 86400) .. Language[10823] end if deltaTime > 3600 then return math.floor(deltaTime / 3600) .. Language[10822] end if deltaTime > 60 then return math.floor(deltaTime / 60) .. Language[10821] end return Language[10820] end function GetDeltaTimeStr(timestamp) local curTimeStemp = GetTimeStamp() local deltaTime = curTimeStemp - timestamp return GetDeltaTimeStrByDeltaTime(deltaTime) end --- 计算公式 a*x^3 + b*x^2 + c*x +d --- 1、 CalculateCostCount(x, a, b, c, d) --- 2、 CalculateCostCount(x, array) --- array 为按顺序存储a, b, c, d值的数组 --- function CalculateCostCount(x, ...) if not x then return end local args = { ... } if type(args[1]) == "table" then args = args[1] end if type(args[1]) ~= "number" then return end local a = args[1] local b = args[2] local c = args[3] local d = args[4] local cost = math.pow(x, 3) * a + math.pow(x, 2) * b + x * c + d return cost end --- 获取当前时间戳 function GetTimeStamp() return PlayerManager.serverTime end --- 获取当前时间到下一个n点的时间长度 --- 获取当前时间到一天中某时的剩余时间(24小时制) function CalculateSecondsNowTo_N_OClock(n) local curTimeStemp = GetTimeStamp() --- 标准时间戳从1970年1月1日8点开始,加上八个小时的秒数,使其从0点开始 --- 8*60*60 = 28800 --- 24*60*60 = 86400 local todayPassSeconds = (curTimeStemp + 28800) % 86400 local targetSeconds = n * 3600 --- 60*60 = 3600 if todayPassSeconds <= targetSeconds then return targetSeconds - todayPassSeconds else -- 如果已经过去了,则计算到第二天这个时间点需要的秒数 return targetSeconds + 86400 - todayPassSeconds end end --获取某个时间戳对应的星期几 --目标日期 = (ALLDays % 7) + 基准星期(1970年1月1日,那天是星期四) WeekNumList = { [0] = 4, [1] = 5, [2] = 6, [3] = 7, [4] = 1, [5] = 2, [6] = 3, } function GetTimeStampCorrespondingWeekNum(second) local WeekNum = 0 local day = math.floor(second / (24 * 3600)) WeekNum = (day % 7)-- + 4 return WeekNumList[WeekNum] end --获取到本周结束的剩余时间 function TimeToCurWeekEnd() local leftTime = 604800- (GetTimeStamp() - 316800)%604800 return leftTime end function TimeToFelaxible(second)--大于一天用多少天多少小时,小于一天用00:00:00 if second <= 86400 then if not second or second < 0 then return "00:00:00" end local _sec = second % 60 local allMin = math.floor(second / 60) local _min = allMin % 60 local _hour = math.floor(allMin / 60) return string.format("%02d:%02d:%02d", _hour, _min, _sec), _hour, _min, _sec elseif second > 86400 then local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) return string.format(Language[10487],day, hour) end end --- 将一段时间转换为天时分秒 function TimeToDHMS(second) local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) return string.format(Language[10585],day, hour, minute, sec) end --- 将一段时间转换为天时分 function TimeToDHM(second) local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) return string.format(Language[11390],day, hour, minute) end --- 将一段时间转换为天 function TimeToD(second) local day = math.floor(second / (24 * 3600)) return day,string.format("%s天",day) end --- 将一段时间转换为天时 function TimeToDH(second) local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) return string.format(Language[10487],day, hour) end --- 将一段时间转换为时 function TimeToH(second) local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) return string.format(Language[11704], hour) end --- 将一段时间转换为时分秒 function TimeToHMS(t) if not t or t < 0 then return "00:00:00" end local _sec = t % 60 local allMin = math.floor(t / 60) local _min = allMin % 60 local _hour = math.floor(allMin / 60) return string.format("%02d:%02d:%02d", _hour, _min, _sec), _hour, _min, _sec end --- 将一段时间转换为时分 function TimeToHM(t) if not t or t < 0 then return "00:00:00" end local _sec = t % 60 local allMin = math.floor(t / 60) local _min = allMin % 60 local _hour = math.floor(allMin / 60) return string.format("%02d:%02d", _hour, _min) end --- 将一段时间转换为分秒 function TimeToMS(t) if not t or t < 0 then return "00:00" end local _sec = t % 60 local _min = math.floor(t / 60) return string.format("%02d:%02d", _min, _sec) end --- 将一段时间转换为分或秒 function TimeToMorS(t) if not t or t < 0 then return "0" elseif t > 0 and t < 60 then return math.floor(t).."秒" else local _min = math.floor(t / 60) return string.format("%02d分", _min) end end --- 获取今天某时间点时间戳 function Today_N_OClockTimeStamp(n) local currentTime = math.floor(GetTimeStamp()) local tab = os.date("*t", currentTime) tab.hour = n tab.min = 0 tab.sec = 0 local N_TimeStamp = os.time(tab) return N_TimeStamp end ----- 时效类时间(服务器按照每天凌晨的5点为起始的一天) function GetTimePass(timeValue) local tab = os.date("*t", timeValue) tab.hour = 0 tab.min = 0 tab.sec = 0 local tab2 = os.date("*t", timeValue) tab2.hour = 0 tab2.min = 0 tab2.sec = 0 local timeStartSum = os.time(tab2) --0点 local forwardDay local zeroTimeStamp = os.time(tab) if timeValue > zeroTimeStamp and timeValue < timeStartSum then forwardDay = 1 else forwardDay = 0 end local dayPass = math.ceil((GetTimeStamp() - timeStartSum) / 86400) return (dayPass + forwardDay) > 7 and 7 or (dayPass + forwardDay) end ---时间格式化接口 function GetTimeShow(data) local year = math.floor(os.date("%Y", data)) local month = math.floor(os.date("%m", data)) local day = math.floor(os.date("%d", data)) local time = year .. "." .. month .. "." .. day return time end ---obj必须是userdata(c#对象) function IsNull(obj) if not obj then return true end if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.IS_NULL) then return obj:IsNull() else return obj == nil or obj:Equals(nil) end end ------- 红点相关 ---------- -- 绑定红点物体 function BindRedPointObject(rpType, rpObj) RedpotManager.BindObject(rpType, rpObj) end -- 清除红点上绑定的所有物体 function ClearRedPointObject(rpType, rpObj) RedpotManager.ClearObject(rpType, rpObj) end -- 强制改变红点状态(不建议使用) function ChangeRedPointStatus(rpType, state) RedpotManager.SetRedPointStatus(rpType, state) end -- 重置服务器红点状态到隐藏状态 function ResetServerRedPointStatus(rpType) RedpotManager.SetServerRedPointStatus(rpType, RedPointStatus.Hide) end -- 检测红点显示 function CheckRedPointStatus(rpType) RedpotManager.CheckRedPointStatus(rpType) end ------------------------- --统用属性展示 function GetPropertyFormatStr(type, value) if type == 1 then return value else if value % 100 == 0 then return string.format("%d%%", value / 100) else return string.format("%.2f%%", value / 100) end end end --统用属性展示 function GetPropertyFormatStrOne(type, value) if type == 1 then return value else if value % 100 == 0 then return string.format("%d%%", value / 100) else return string.format("%.2f%%", value / 100) end end end --装备专属属性展示 function GetEquipPropertyFormatStr(type, value) if type == 1 then return value else if value / 100 > 1 then return string.format("%d%%", value / 100) else return string.format("%d%%", 1) end end end -- 将秒转换成显示使用的时间 function FormatSecond(second) local day = math.floor(second / (24 * 3600)) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600) return string.format(Language[12055], day, hour, minute, sec) end -- 将时间戳转换为用于显示的日期字符串 function TimeStampToDateStr(timestamp) local date = os.date("*t", timestamp) local cdate = os.date("*t", GetTimeStamp()) if date.year == cdate.year and date.month == cdate.month and date.day == cdate.day then return string.format("%02d:%02d", date.hour, date.min) end return string.format(Language[12056], date.year, date.month, date.day, date.hour, date.min) end function TimeStampToDateStr4(timestamp) local date = os.date("*t", timestamp) local cdate = os.date("*t", GetTimeStamp()) return string.format("%d年%d月%d日 %02d:%02d:%02d", date.year, date.month, date.day, date.hour, date.min,date.sec) end -- 将时间转换为年月日 function TimeStampToDateStr2(timestamp) local date = os.date("*t", timestamp) local cdate = os.date("*t", GetTimeStamp()) return date.year..date.month..date.day end -- 将时间转换为年月日 function TimeStampToDateStr6(timestamp) local date = os.date("*t", timestamp) local cdate = os.date("*t", GetTimeStamp()) return date.year.."-"..date.month.."-"..date.day end -- 将时间戳转换为用于显示的日期字符串(时分秒) function TimeStampToDateStr3(second) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - sec - minute * 60) / 3600) return string.format("%02d:%02d:%02d", hour, minute, sec) end -- 将时间戳转换为用于显示的日期字符串 倒计时大于等于1小时精确到分,小于1小时精确到秒。 function TimeStampToDateStr3new(second) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - sec - minute * 60) / 3600) if hour > 0 then return string.format("%02d:%02d", hour, minute) else return string.format("%02d:%02d", minute, sec) end end -- 将时间戳转换为用于显示的日期字符串 倒计时大于等于1小时精确到分,小于1小时精确到秒。 function TimeStampToDateStr3new1(second) local minute = math.floor(second / 60) % 60 local sec = second % 60 local hour = math.floor(math.floor(second - sec - minute * 60) / 3600) if hour > 0 then return string.format("%02d时%02d分", hour, minute) else return string.format("%02d分%02d秒", minute, sec) end end function TimeStampToDateStr5(timestamp) local date = os.date("*t", timestamp) local cdate = os.date("*t", GetTimeStamp()) return string.format("%02d:%02d:%02d", date.hour, date.min, date.sec) end --时间格式转换(只显示月日时分) function TimeStampToMDHM(timestamp) local date = os.date("*t", timestamp) --local cdate = os.date("*t", GetTimeStamp()) --if date.year == cdate.year and date.month == cdate.month and date.day == cdate.day then -- return string.format("%02d:%02d", date.hour, date.min) --end return string.format(Language[10627],date.month, date.day,date.hour, date.min) --return string.format("%d年%d月%d日 %02d:%02d", date.year, date.month, date.day, date.hour, date.min) end --- 根据id获取资源 function GetResourcePath(id) local config = ConfigManager.TryGetConfigData(ConfigName.ArtResourcesConfig, id) if config then return GetLanguageStrById(config.Name) end return "r_shijie_tili" end --- 根据ItemId获取资源名称 function GetSpriteNameByItemId(id) local artId = ConfigManager.GetConfigData(ConfigName.ItemConfig, id).ResourceID local config = ConfigManager.TryGetConfigData(ConfigName.ArtResourcesConfig, artId) if config then return GetLanguageStrById(config.Name) end return "r_shijie_tili" end --- 获取玩家头像资源 function GetPlayerHeadSprite(spLoader, headId) if headId == 0 then headId = 71000 end local head = ConfigManager.GetConfigData(ConfigName.ItemConfig, headId) return spLoader:LoadSprite(GetResourcePath(head.ResourceID)) end --- 获取玩家头像框资源 function GetPlayerHeadFrameSprite(spLoader, frameId) if frameId == 0 then frameId = 80000 end local frame = ConfigManager.GetConfigData(ConfigName.ItemConfig, frameId) return spLoader:LoadSprite(GetResourcePath(frame.ResourceID)) end --- 获取玩家头像框资源 function GetPlayerHeadFrameEffect(frameId) if frameId == 80004 then return "UI_Effect_TouXiang_Lanlong", 1.1, Vector3.New(-8, -5, 0) elseif frameId == 80005 then return "UI_Effect_TouXiang_QingLong", 1.15, Vector3.New(-9, 5, 0) elseif frameId == 80006 then return "UI_Effect_TouXiang_BaiHu", 1.15, Vector3.New(-3, -8, 0) end end --是否弹出快捷购买面板 function PopQuickPurchasePanel(type, needNum) local ownNumber = BagManager.GetItemCountById(type) if ownNumber >= needNum then return false else UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = type }) return true end end ----- SDK数据上报 ----- @param context ---- { ---- type, -- required, 调用时机 ---- } function SubmitExtraData(context) if not AppConst.isSDKLogin then return end local params = SDK.SDKSubmitExtraDataArgs.New() params.dataType = context.type params.serverID = tonumber(PlayerManager.serverInfo.server_id) params.serverName = PlayerManager.serverInfo.name params.zoneID = tostring(AppConst.OpenId) params.zoneName = PlayerManager.serverInfo.name params.roleID = tostring(PlayerManager.uid) params.roleName = PlayerManager.nickName params.roleLevel = tostring(PlayerManager.level) params.guildID = PlayerManager.familyId params.Vip = tostring(VipManager.GetVipLevel()) params.moneyNum = BagManager.GetItemCountById(16) params.roleCreateTime = PlayerManager.userCreateTime params.roleLevelUpTime = context.roleLevelUpTime and context.roleLevelUpTime or "0" -- 特殊处理, 改名时用zoneName传递老名字 if context.type == SDKSubMitType.TYPE_CHANGE_NAME then params.zoneName = context.oldName end SDKMgr:SubmitExtraData(params) end -- context = { -- title = "", -- content = "", -- confirmCallback = function() end, -- cancelCallback = function() end, -- confirmText = "确认", -- cancelText = "取消", -- type, -- 单双按钮 -- extra --额外操作 -- } function ShowConfirmPanel(context) UIManager.OpenPanel(UIName.CommonConfirmPanel, context) end -- 检测某一面板关闭再抛相应的事件 function CallBackOnPanelClose(uiPanel, func) if UIManager.IsOpen(uiPanel) then local triggerCallBack triggerCallBack = function (panelType, panel) if panelType == uiPanel then if func then func() end Game.GlobalEvent:RemoveEvent(GameEvent.UI.OnClose, triggerCallBack) end end Game.GlobalEvent:AddEvent(GameEvent.UI.OnClose, triggerCallBack) else if func then func() end end end -- 检测某一面板打开再抛相应的事件 function CallBackOnPanelOpen(uiPanel, func) if not UIManager.IsOpen(uiPanel) then local triggerCallBack triggerCallBack = function (panelType, panel) if panelType == uiPanel then if func then func() end Game.GlobalEvent:RemoveEvent(GameEvent.UI.OnOpen, triggerCallBack) end end Game.GlobalEvent:AddEvent(GameEvent.UI.OnOpen, triggerCallBack) else if func then func() end end end -- 通过地图坐标设置物体在UI平面的位置 function SetObjPosByUV(pos) local u, v = Map_Pos2UV(pos) local v2 = RectTransformUtility.WorldToScreenPoint(TileMapView.GetCamera(), TileMapView.GetLiveTilePos(u, v)) v2.x = (v2.x)/Screen.width*UIManager.UIWidth - UIManager.Offset.Left v2.y = (v2.y)/Screen.height*UIManager.UIHeight - UIManager.Offset.Bottom return v2 end --获取技能描述 function GetSkillConfigDesc(cfg) if cfg.DescColor then local ss = {} for i=1, #cfg.DescColor do local str if cfg.DescColor[i] == 1 then str=string.format("%s", GetLanguageStrById(cfg.DescValue[i])) elseif cfg.DescColor[i] == 2 then str=string.format("%s", GetLanguageStrById(cfg.DescValue[i])) else str=cfg.DescValue[i] end ss[i] = str end return string.format(GetLanguageStrById(cfg.Desc), unpack(ss)) end return GetLanguageStrById(cfg.Desc) end --获取技能描述 function GetCurrSkillConfigDesc(cfg,soulLv) if cfg.DescColor then local ss = {} local skillValue=cfg.DescValue if cfg.SpiritsValue and soulLv and soulLv>0 then if cfg.SpiritsValue[soulLv] then skillValue=cfg.SpiritsValue[soulLv] end end for i=1, #cfg.DescColor do local str if cfg.DescColor[i] == 1 then str=string.format("%s", GetLanguageStrById(skillValue[i])) elseif cfg.DescColor[i] == 2 then str=string.format("%s", GetLanguageStrById(skillValue[i])) else str=skillValue[i] end ss[i] = str end return string.format(GetLanguageStrById(cfg.Desc), unpack(ss)) end return GetLanguageStrById(cfg.Desc) end -- 设置排名所需要的数字框 function SetRankNumFrame(spLoader, rankNum) local rankNumRes = { [1] = "r_Dungeon_001", [2] = "r_Dungeon_002", [3] = "r_Dungeon_003", [4] = "r_hero_zhuangbeidi", } local resPath = rankNum > 3 and rankNumRes[4] or rankNumRes[rankNum] local icon = spLoader:LoadSprite(resPath) return icon end function SetSoulEffect(quality,root) local effect1 = Util.GetGameObject(root,"UI_Effect_Kuang_JinSe") local effect2 = Util.GetGameObject(root,"UI_Effect_Kuang_HongSe") local effect3 = Util.GetGameObject(root,"UI_effect_WuCai_Kuang") if quality then effect1:SetActive(quality == 5) effect2:SetActive(quality == 6) effect3:SetActive(quality == 7 or quality==8) else effect1:SetActive(false) effect2:SetActive(false) effect3:SetActive(false) end end --- 本方法适用滚动条中 生成item的使用 (主要适用每条滚动条item数量不定的滚动条中) --- itemview重设复用 1根节点 2生成到父节点 3item容器 4容器上限 5缩放 6层级 7根据数据类型生成 8不定参数据... --- type=true 针对表数据为一维数据 type=false 针对表数据为二维数据 function ResetItemView(root,rewardRoot,itemList,max,scale,sortingOrder,type,...) local args={...} local data1=args[1] local data2=args[2] if itemList[root] then -- 存在 for i = 1, max do itemList[root][i].gameObject:SetActive(false) end if type then itemList[root][1]:OnOpen(false, {data1,data2},scale,false,false,false,sortingOrder) itemList[root][1].gameObject:SetActive(true) else for i = 1, #data1 do if itemList[root][i] then itemList[root][i]:OnOpen(false, {data1[i][1],data1[i][2],data1[i][3],data1[i][4]},scale,false,false,false,sortingOrder) itemList[root][i]:Reset({data1[i][1],data1[i][2]},ItemType.Hero,{false,true,true,true}) itemList[root][i].gameObject:SetActive(true) end end end else -- 不存在 新建 itemList[root]={} for i = 1, max do itemList[root][i] = SubUIManager.Open(SubUIConfig.ItemView, rewardRoot) itemList[root][i].gameObject:SetActive(false) end if type then itemList[root][1]:OnOpen(false, {data1,data2},scale,false,false,false,sortingOrder) itemList[root][1].gameObject:SetActive(true) else for i = 1, #data1 do itemList[root][i]:OnOpen(false, {data1[i][1],data1[i][2],data1[i][3],data1[i][4],data1[i][5]},scale,false,false,false,sortingOrder) itemList[root][i]:Reset({data1[i][1],data1[i][2]},ItemType.Hero,{false,true,true,true}) itemList[root][i].gameObject:SetActive(true) end end end end --计算字符串长度 function LengthString(inputstr) -- 计算字符串宽度 -- 可以计算出字符宽度,用于显示使用 if not inputstr or inputstr == "" then return end local lenInByte = #inputstr local width = 0 local i = 1 while (i<=lenInByte) do local curByte = string.byte(inputstr, i) local byteCount = 1; if curByte>0 and curByte<=127 then byteCount = 1 --1字节字符 elseif curByte>=192 and curByte<223 then byteCount = 2 --双字节字符 elseif curByte>=224 and curByte<239 then byteCount = 3 --汉字 elseif curByte>=240 and curByte<=247 then byteCount = 4 --4字节字符 end local char = string.sub(inputstr, i, i+byteCount-1) -- print(char) i = i + byteCount -- 重置下一字节的索引 width = width + 1 -- 字符的个数(长度) end return width end --都截取长度 function SubString(inputstr,num) local num = num and num or 0 local str = "" if not inputstr or inputstr == "" then return "" end local lenInByte = #inputstr local width = 0 local i = 1 while (i<=lenInByte) do local curByte = string.byte(inputstr, i) local byteCount = 1; if curByte>0 and curByte<=127 then byteCount = 1 --1字节字符 elseif curByte>=192 and curByte<223 then byteCount = 2 --双字节字符 elseif curByte>=224 and curByte<239 then byteCount = 3 --汉字 elseif curByte>=240 and curByte<=247 then byteCount = 4 --4字节字符 end local char = string.sub(inputstr, i, i+byteCount-1) -- print(char) str = str..char i = i + byteCount -- 重置下一字节的索引 width = width + 1 -- 字符的个数(长度) if width == num then return (str) end end return str end --都截取长度 function SpliteAndInsertString(_inputstr,_maxNum,_cutNum,_insert) local str = "" local str2 = "" if not _inputstr or _inputstr == "" then return "" end local lenInByte = #_inputstr local width = 0 local i = 1 while (i<=lenInByte) do local curByte = string.byte(_inputstr, i) local byteCount = 1; if curByte>0 and curByte<=127 then byteCount = 1 --1字节字符 elseif curByte>=192 and curByte<223 then byteCount = 2 --双字节字符 elseif curByte>=224 and curByte<239 then byteCount = 3 --汉字 elseif curByte>=240 and curByte<=247 then byteCount = 4 --4字节字符 end local char = string.sub(_inputstr, i, i+byteCount-1) -- print(char) i = i + byteCount -- 重置下一字节的索引 width = width + 1 -- 字符的个数(长度) if width <= _cutNum then str = str..char else str2 = str2..char end end if width <= _maxNum then LogPink("1:"..tostring(_inputstr)) return _inputstr else LogPink("2:"..tostring(str.._insert..str2)) return str.._insert..str2 end end function FixableString(inputstr,num) if LengthString(inputstr) > num then return SubString(inputstr,num-1).."..." else return inputstr end end --只有英文截取长度 function SubString2(inputstr,num) if GetCurLanguage() == 0 then return inputstr end if not inputstr or inputstr == "" then return "" end local num = num and num or 0 local str = "" local lenInByte = #inputstr local width = 0 local i = 1 while (i<=lenInByte) do local curByte = string.byte(inputstr, i) local byteCount = 1; if curByte>0 and curByte<=127 then byteCount = 1 --1字节字符 elseif curByte>=192 and curByte<223 then byteCount = 2 --双字节字符 elseif curByte>=224 and curByte<239 then byteCount = 3 --汉字 elseif curByte>=240 and curByte<=247 then byteCount = 4 --4字节字符 end local char = string.sub(inputstr, i, i+byteCount-1) -- print(char) str = str..char i = i + byteCount -- 重置下一字节的索引 width = width + 1 -- 字符的个数(长度) if width == num then if lenInByte > num then str = str .. "..." end return (str) end end if lenInByte > num then str = str .. "..." end return str end function StringConvertToTable(inputstr) local str = {} local lenInByte = #inputstr local i = 1 while (i<=lenInByte) do local curByte = string.byte(inputstr, i) local byteCount = 1; if curByte>0 and curByte<=127 then byteCount = 1 --1字节字符 elseif curByte>=192 and curByte<223 then byteCount = 2 --双字节字符 elseif curByte>=224 and curByte<239 then byteCount = 3 --汉字 elseif curByte>=240 and curByte<=247 then byteCount = 4 --4字节字符 end local char = string.sub(inputstr, i, i+byteCount-1) -- print(char) table.insert(str,char) i = i + byteCount end return str end function CreatNumberPrefab(inputstr,itemList) local tempNumList = StringConvertToTable(inputstr) for i = 1, #itemList do -- grid.transform:GetChild(i - 1).gameObject:SetActive(false) if i <= #tempNumList then itemList[i].text = tempNumList[i] itemList[i].gameObject:SetActive(true) else itemList[i].gameObject:SetActive(false) end end end --本地文本显示统一调用此接口 function GetLanguageStrById(zhStr) if languageDic[zhStr] then if GetCurLanguage() == 0 then return languageDic[zhStr].zh elseif GetCurLanguage() == 1 then return languageDic[zhStr].en elseif GetCurLanguage() == 2 then return languageDic[zhStr].vi else return languageDic[zhStr].zh end end return zhStr end -- 0:中文 1:英文 function GetCurLanguage() if PlayerPrefs.HasKey("language") then return PlayerPrefs.GetInt("language") else return 0 end end -- 文字大小比例缩放 FontSizeScaleToZh = { [0] = 1, [1] = 0.9, [2] = 0.8 } function LanguageFontSizeFilter(text, size) local l = GetCurLanguage() text.fontSize = math.floor(size * FontSizeScaleToZh[l]) end function SetHeroIcon(spLoader, heroData,icon,heroConfig) -- LogGreen("heroData.skinId:"..tostring(heroData.skinId)) if not heroData.skinId or heroData.skinId == 0 then icon.sprite = spLoader:LoadSprite(GetResourcePath(heroConfig.Icon)) else local heroSkinconfig = ConfigManager.GetConfigDataByKey(ConfigName.HeroSkin,"Type",heroData.skinId) icon.sprite = spLoader:LoadSprite(GetResourcePath(heroSkinconfig.Icon)) end end --通过角色属性获取角色属性图标 function GetFourElementBgByType(_index) if _index == 1 then return "s_silingshilian_renjieshiliandi" elseif _index == 2 then return "s_silingshilian_fochanshiliandi" elseif _index == 3 then return "s_silingshilian_yaolingshiliandi" elseif _index == 4 then return "s_silingshilian_daoxuanshiliandi" else return "s_silingshilian_daoxuanshiliandi" end end function GetEquipSuitStr(Star,num) -- return string.format("%s件%s%s星激活",num,QualityNameDef[ ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality],ConfigManager.GetConfigData(ConfigName.EquipStarsConfig,Star).Stars) return string.format("%s件%s%s星装备激活",num,QualityNameDef[ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality],ConfigManager.GetConfigData(ConfigName.EquipStarsConfig,Star).Stars) end function GetEquipSuitStr2(Star,num) -- return string.format("%s件%s%s星激活",num,QualityNameDef[ ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality],ConfigManager.GetConfigData(ConfigName.EquipStarsConfig,Star).Stars) if ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality>6 then return string.format("%s件%s装备激活",num,QualityNameDef[ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality]) else return string.format("%s件%s%s星激活",num,QualityNameDef[ ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality],ConfigManager.GetConfigData(ConfigName.EquipStarsConfig,Star).Stars) end end function SetTextVerTial(textCom,vec,alin,posType,nameNum) if GetCurLanguage() == 0 then return end local textComp = textCom:GetComponent("Text") textComp.horizontalOverflow = 1 local go = nil if textCom.transform.parent.name ~= "VerticalTextParent" then go = GameObject.New() go.name = "VerticalTextParent" --LogGreen(tostring(go.name)) go.transform:SetParent(textCom.transform.parent.transform) go:SetActive(true) local rectCom = go:GetComponent("RectTransform") or go:AddComponent(typeof(UnityEngine.RectTransform)) rectCom.anchorMin = Vector2.New(0,1) rectCom.anchorMax = Vector2.New(0,1) rectCom.localScale = Vector3.one local weight = textComp.fontSize rectCom.sizeDelta = Vector2.New(weight,weight) local pos = rectCom.localPosition pos.x = weight pos.y = -weight/2 pos.z = 0 rectCom.anchoredPosition3D = pos textCom.transform:SetParent(go.transform) textCom:GetComponent("RectTransform").localPosition = vec if posType then textCom:GetComponent("RectTransform").anchoredPosition3D = vec end if not alin then textComp.alignment = "MiddleLeft" else textComp.alignment = alin end rectCom.rotation = Quaternion.Euler(Vector3.New(0,0,-90)) end if nameNum then textComp.text = SubString2(textComp.text,nameNum) end end function GetHeroNaturalImg(lv) local str="" if lv==1 then str="r_hero_putong" elseif lv==2 then str="r_hero_lianghao" elseif lv==3 then str="r_hero_youxiu" elseif lv==4 then str="r_hero_xiyou" elseif lv==5 then str="r_hero_shishi" elseif lv==6 then str="r_hero_chuanshuo" elseif lv==7 then str="r_hero_shenhua" end return str end function GetHeroHandBookNaturalImg(lv) local str="" if lv==1 then str="r_hero_tujian_putong" elseif lv==2 then str="r_hero_tujian_lianghao" elseif lv==3 then str="UI_hz_gonghui_05" elseif lv==4 then str="UI_hz_gonghui_04" elseif lv==5 then str="UI_hz_gonghui_03" elseif lv==6 then str="UI_hz_gonghui_02" elseif lv==7 then str="UI_hz_gonghui_01" end return str end function SetEnglishActive(go) if GetCurLanguage() == 0 then return end go.gameObject:SetActive(false) end function GetEquipSuitStr(Star,num) local qua=ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality if qua==8 then qua=7 end local suitConfig=ConfigManager.GetConfigData(ConfigName.EquipSuiteConfig,Star) -- return string.format(Language[12057],num,QualityNameDef[ ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality],ConfigManager.GetConfigData(ConfigName.EquipStarsConfig,Star).Stars) if qua>6 then return string.format("%s件%s及以上装备激活",num,suitConfig.Name) else return string.format(Language[12057],num,QualityNameDef[ ConfigManager.GetConfigDataByKey(ConfigName.EquipConfig,"Star",Star).Quality],ConfigManager.GetConfigData(ConfigName.EquipStarsConfig,Star).Stars) end end -- 绑定扫光特效的资源 function BindLightFlash(light, target) local meshrender = light.gameObject:GetComponent("MeshRenderer") local m = meshrender.material local texture = target.gameObject:GetComponent("Image").mainTexture m:SetTexture("_Mask", texture) end function GetCutOutStr(_str,_num) if not _str then return "" end local str="" if LengthString(_str) >= _num + 1 then str=SubString(_str,_num) .. "..." else str = _str end return str end function JingJiShouWeiToEn(_str) if not _str or _str == "" then return "" end -- --LogGreen("input _str:".._str) -- if _str == "竞技守卫" then return GetLanguageStrById(_str) -- end -- --LogGreen("return str:".._str) -- return _str end -- 忽略字符串头部的空白字符 function ltrim(input) return (string.gsub(input, "^[ \t\n\r]+", "")) end -- 忽略字符串尾部的空白字符 function rtrim(input) return (string.gsub(input, "[ \t\n\r]+$", "")) end -- 忽略字符串首尾的空白字符 function trim(input) return (string.gsub(input, "^%s*(.-)%s*$", "%1")) end function GetPlayerRoleSingleConFig() return ConfigManager.GetConfigDataByKey(ConfigName.PlayerRole,"Role",0) end -- 网络url转码 function decodeURI(s) if not s then return "" end s = string.gsub(s, '%%(%x%x)', function(h) return string.char(tonumber(h, 16)) end) return s end function encodeURI(s) if not s then return "" end s = string.gsub(s, "([^%w%.%- ])", function(c) return string.format("%%%02X", string.byte(c)) end) return string.gsub(s, " ", "+") end -- 通过浏览器打开网页 function OpenWeb(url) if url then if ServerConfigManager.IsSettingActive(ServerConfigManager.SettingConfig.INNER_WEB_CONTROL) then SDKMgr:OpenWeb(url) else UnityEngine.Application.OpenURL(url) end end end function GetProfessionNameById(_professionId) if _professionId==1 then return "肉盾" elseif _professionId==2 then return "输出" elseif _professionId==3 then return "控制" elseif _professionId==4 then return "辅助" end return "" end -- 设置图片数字显示 function SetNumShow(numGrid,numPre,numStr,isShow) local numTb = StringConvertToTable(tostring(numStr)) local numList = {} for i = 1,numGrid.transform.childCount - 1 do table.insert(numList,numGrid.transform:GetChild(i-1):GetComponent("Text")) end for i = 1, math.max(#numList,#numTb) do if not numTb[i] then numList[i].gameObject:SetActive(false) else if not numList[i] then local go = newObjToParent(numPre.gameObject,numGrid.gameObject) go.transform:SetSiblingIndex(numGrid.transform.childCount-2) go.transform.localScale = numPre.transform.localScale table.insert(numList,go:GetComponent("Text")) end numList[i].gameObject:SetActive(true) numList[i].text = numTb[i] end end if isShow then numGrid.transform:GetChild(numGrid.transform.childCount-1).gameObject:SetActive(true) else numGrid.transform:GetChild(numGrid.transform.childCount-1).gameObject:SetActive(false) end ForceRebuildLayout(numGrid.transform) end --连接table function ConnectTable(curTable,targetTable) for i,v in pairs(targetTable) do table.insert(curTable,v) end return curTable end --检测gm商店是否开启 function CheckGMIsOpen(type,value) local str="" if type==1 then return PlayerManager.level>=value,string.format(Language[10293],value) elseif type==2 then local name=ConfigManager.GetConfigData(ConfigName.MainLevelConfig,value).Name or "" return FightPointPassManager.IsFightPointPass(value),string.format(Language[10295], GetLanguageStrById(name)) elseif type==3 then local config=ConfigManager.GetConfigData(ConfigName.GMInfo,value) local isBuy=true for i = 1, #config.Items do local master=ConfigManager.GetConfigData(ConfigName.GMMaster,config.Items[i]) local buy=OperatingManager.IsBuyGift(master.PackID) if buy==false then isBuy=false end end return isBuy,config.Name.."全部兑换解锁" elseif type==4 then return VipManager.GetChargedNum()>=value,"累充"..value.."元解锁" elseif type==5 then local recharge=ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig,value) return OperatingManager.IsBuyGift(value),"购买"..recharge.Name.."解锁" end end function GetTaiChuPriLv() local lv=0 local datas=ConfigManager.GetAllConfigsDataByKey(ConfigName.GMMaster,"Type",9) if datas then table.sort(datas,function(a,b) return a.Id