Misc_Tips.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by PZM.
  4. --- DateTime: 2021/9/10 9:17
  5. ---@class Misc
  6. ---@field currentUISelectedGameObject UnityEngine.GameObject
  7. ---@field isSelectInputField boolean
  8. Misc = class()
  9. local this = Misc
  10. this.spriteFrameDelta = Vector3(-22, 16, 0)
  11. this.spriteColor = Vector4(1, 1, 1, 1)
  12. this.scaleOne = Vector3.one
  13. this.rotationIdentity = Quaternion.identity
  14. this.tempDot = Dot2.zero
  15. this.tempDot2 = Dot2.zero
  16. this.tempRotation = Quaternion.identity
  17. this.tempVec3 = Vector3.zero
  18. ---@return function
  19. function this.Bind(self, callback, eventData)
  20. if not callback then
  21. return nil
  22. end
  23. return function(...)
  24. local callBackData = table.pack(...)
  25. return callback(self, eventData, callBackData)
  26. end
  27. end
  28. function this.GetSpriteLoader()
  29. if not this.spriteLoader then
  30. this.spriteLoader = CS.TCFramework.AssetLoader(nil)
  31. --CS.TCFramework.DisposeOnDestroy.Add(self.gameObject, self.spriteLoader)
  32. end
  33. return this.spriteLoader
  34. end
  35. function this.GetRawImage(path, cacheTime)
  36. if not this.spriteLoader then
  37. this.spriteLoader = CS.TCFramework.AssetLoader(nil)
  38. end
  39. this.spriteLoader:LoadRawImage(path, cacheTime or CS.TCFramework.ResourceManager.ASSET_CACHE_TIME_USE_DEFAULT)
  40. if this.spriteLoader.request then
  41. return this.spriteLoader.request.asset
  42. end
  43. end
  44. ---@alias LoadSpriteCallback fun(self: table, sprite: UnityEngine.Sprite,data:any):void
  45. ---@param callback LoadSpriteCallback
  46. ---@return void @非UI逻辑加载Res文件夹中的Sprite 同步加载
  47. function this.LoadSprite(self, path, callback, data, cacheTime)
  48. this.GetSpriteLoader():Load(path, typeof(CS.UnityEngine.Sprite), cacheTime or CS.TCFramework.ResourceManager.ASSET_CACHE_TIME_USE_DEFAULT)
  49. if this.spriteLoader.request then
  50. callback(self, this.spriteLoader.request.asset, data)
  51. end
  52. end
  53. ---@param callback LoadSpriteCallback
  54. ---@return void @非UI逻辑加载Res文件夹中的Sprite 同步加载
  55. function this.LoadSpriteAsync(self, path, callback, data, cacheTime)
  56. this.GetSpriteLoader():LoadAsync(path, typeof(CS.UnityEngine.Sprite), cacheTime or CS.TCFramework.ResourceManager.ASSET_CACHE_TIME_USE_DEFAULT)
  57. if this.spriteLoader.isLoading then
  58. this.spriteLoader.loadCallback = function(sprite)
  59. callback(self, sprite, data)
  60. end
  61. else
  62. callback(self, this.spriteLoader.request.asset, data)
  63. end
  64. end
  65. ---@param atlasName string @图集名称
  66. ---@param IconName string @图片名称
  67. ---@param arg function|UIControl @回调或者图片控件
  68. function this.SetSprite(atlasName, iconName, arg)
  69. local atlasPath = string.format("Atlas/%s.spriteatlas", atlasName)
  70. this.GetSpriteLoader():Load(atlasPath, typeof(CS.UnityEngine.U2D.SpriteAtlas))
  71. if this.spriteLoader.request then
  72. local spriteAtlas = this.spriteLoader.request.res
  73. local sprite = spriteAtlas:GetSprite(tostring(iconName))
  74. if (sprite ~= nil and iconName ~= nil) then
  75. sprite.name = tostring(iconName)
  76. local typeArg = type(arg)
  77. if typeArg == "function" then
  78. ---@type function
  79. local callBack = arg
  80. callBack(sprite)
  81. elseif typeArg == "table" then
  82. if IsSubTypeOf(arg, UIControl) then
  83. ---@type UIControl
  84. local ui = arg
  85. ui:SetSprite(sprite)
  86. end
  87. end
  88. else
  89. logError(atlasName .. " 图集中没有发现 imageTable.IconName " .. iconName)
  90. end
  91. end
  92. end
  93. ---@return void @临时,后续需要整理
  94. ---@param assetGroup TCFramework.AssetGroup
  95. function this.SetSpriteFromAtlas(assetGroup, atlasName, iconName, arg)
  96. local atlasPath = string.format("Atlas/%s.spriteatlas", atlasName)
  97. local spriteAtlas = assetGroup:LoadAsset(atlasPath, typeof(CS.UnityEngine.U2D.SpriteAtlas))
  98. local sprite = spriteAtlas:GetSprite(tostring(iconName))
  99. if (sprite ~= nil and iconName ~= nil) then
  100. sprite.name = tostring(iconName)
  101. local typeArg = type(arg)
  102. if typeArg == "function" then
  103. ---@type function
  104. local callBack = arg
  105. callBack(sprite)
  106. elseif typeArg == "table" then
  107. if IsSubTypeOf(arg, UIControl) then
  108. ---@type UIControl
  109. local ui = arg
  110. ui:SetSprite(sprite)
  111. end
  112. end
  113. return sprite
  114. else
  115. logError(atlasName .. " 图集中没有发现 imageTable.IconName " .. iconName)
  116. end
  117. end
  118. ---@param coord1 Dot2
  119. ---@param coord2 Dot2
  120. ---@return EDirection
  121. function this.GetDirectionByTarget(coord1, coord2)
  122. if coord1 == coord2 then
  123. return EDirection.None
  124. end
  125. this.tempDot:CopyFromSub(coord2, coord1)
  126. this.tempDot:SetNormalize()
  127. local max = -math.huge
  128. local dir = EDirection.None
  129. for k, v in pairs(EDirectionToDot2) do
  130. this.tempDot2:Copy(v)
  131. local dot = Dot2.Dot(this.tempDot2:SetNormalize(), this.tempDot)
  132. if dot > max then
  133. max = dot
  134. dir = k
  135. end
  136. end
  137. return dir
  138. end
  139. ---@return number @8方向或者16方向,16方向从0开始到15.顺时针依次增加
  140. function this.GetEffectDirection(coord1, coord2, is16Dir)
  141. if not is16Dir then
  142. return this.GetDirectionByTarget(coord1, coord2)
  143. end
  144. if coord1 == coord2 then
  145. return EDirection.None
  146. end
  147. local stepAngle = is16Dir and 22.5 or 45
  148. local up = Dot2(0, -1)
  149. local dot = coord2 - coord1
  150. local upVec = Vector3(up.x, up.z, 0)
  151. local dotVec = Vector3(dot.x, dot.z, 0)
  152. local cross = Vector3.Cross(upVec, dotVec)
  153. local angle = Vector3.Angle(upVec, dotVec)
  154. if cross.z > 0 then
  155. angle = angle
  156. else
  157. angle = 360 - angle
  158. end
  159. local index = Mathf.Round(angle / stepAngle)
  160. return index
  161. end
  162. ---@param dir Dot2
  163. ---@return EDirection
  164. function this.GetDirection(dir)
  165. for k, v in pairs(EDirectionToDot2) do
  166. if v == dir then
  167. return k
  168. end
  169. end
  170. return EDirection.None
  171. end
  172. ---@param dir EDirection
  173. ---@return Dot2
  174. function this.GetDirectionDot2(dir)
  175. return EDirectionToDot2[dir]
  176. end
  177. function Misc.IsOnUI()
  178. if CS.TCFramework.DebugTool.hasInstance and not CS.TCFramework.DebugTool.instance.minimize then
  179. return true
  180. end
  181. if EventSystem.current == null then
  182. return false
  183. end
  184. if Main.isEditor then
  185. return EventSystem.current:IsPointerOverGameObject()
  186. end
  187. if Platform.name == 'Android' or Platform.name == 'iOS' then
  188. if Input.touchCount > 0 then
  189. return EventSystem.current:IsPointerOverGameObject(Input.GetTouch(0).fingerId)
  190. end
  191. return false
  192. else
  193. return EventSystem.current:IsPointerOverGameObject()
  194. end
  195. end
  196. ---@return boolean @不要在Update中一直调用
  197. function this.IsFocusOnInputText()
  198. if ObjectEx.IsNull(EventSystem.current.currentSelectedGameObject) then
  199. this.isSelectInputField = false
  200. this.currentUISelectedGameObject = nil
  201. return this.isSelectInputField
  202. end
  203. if this.currentUISelectedGameObject == EventSystem.current.currentSelectedGameObject then
  204. return this.isSelectInputField
  205. end
  206. this.currentUISelectedGameObject = EventSystem.current.currentSelectedGameObject
  207. logError(EventSystem.current.currentSelectedGameObject.name)
  208. this.isSelectInputField = ObjectEx.IsNull(this.currentUISelectedGameObject.transform:GetComponent(typeof(CS.UnityEngine.UI.InputField))) == false
  209. return this.isSelectInputField
  210. end
  211. ---@param srcDot Dot2
  212. ---@param pos Vector3
  213. ---@return EDirection
  214. function this.GetDirectionByWorldPos(srcDot, pos)
  215. return this.GetDirectionByTarget(srcDot, Scene.WorldToTile(pos.x, pos.y, pos.z))
  216. end
  217. ---@return Dot2
  218. function Misc.GetDirectionDot2ByWorldPos(srcDot, pos)
  219. return this.GetDirectionDot2(this.GetDirectionByWorldPos(srcDot, pos))
  220. end
  221. function this.GetEnumKey(enumTable, value)
  222. for k, v in pairs(enumTable) do
  223. if v == value then
  224. return k
  225. end
  226. end
  227. return nil
  228. end
  229. ---@param trans UnityEngine.Transform
  230. function this.SetSceneGoTrans(trans, pos, rotaion, scale)
  231. if not pos then
  232. pos = Vector3.zeroNonAlloc
  233. end
  234. if not rotaion then
  235. rotaion = EngineMgr.sceneGoRotaion
  236. end
  237. if not scale then
  238. scale = EngineMgr.modelScale
  239. end
  240. this.tempRotation:EulerNonAlloc(rotaion.x, rotaion.y, rotaion.z)
  241. local q = this.tempRotation
  242. trans:SetLocalPosAndLocalRotAndLocalScale(pos.x, pos.y, pos.z, q.x, q.y, q.z, q.w, scale.x, scale.y, scale.z)
  243. end
  244. ---@param trans UnityEngine.Transform
  245. function this.SetSceneEffectGoTrans(trans, pos)
  246. if EngineMgr.isEffect2D then
  247. if EngineMgr.engineType == EEngineType.Base then
  248. this.SetSceneGoTrans(trans, pos, RoleHeadCfg.headRotation, this.scaleOne)
  249. elseif EngineMgr.engineType == EEngineType.QJ then
  250. this.SetSceneGoTrans(trans, pos, RoleHeadCfg.headRotation, this.scaleOne)
  251. local f = -trans.forward * 50 + pos
  252. trans:SetLocalPosition(f.x, f.y, f.z)
  253. end
  254. else
  255. this.SetSceneGoTrans(trans, pos)
  256. end
  257. end
  258. --- 根据配置表id获取贴图路径
  259. function this.GetSpritePath(cfgId)
  260. local tbl = ConfigManager.Get_cfg_item(cfgId)
  261. return tbl.looks
  262. end
  263. function this.GetSkillIconName(cfgId, level)
  264. local tbl = ConfigManager.Get_cfg_skill_info(cfgId, level)
  265. return tbl.icon ~= "" and tbl.icon or "0"
  266. end
  267. --- 转化标签文本
  268. --- like <Text|x=25|y=20|color=250|size=18|text=施毒术使用必需品.>|<Text|x=25|y=20|color=251|size=18|text=施毒术造成红毒效果.>
  269. function this.TransSpecialText(srcString)
  270. if not string.contains(srcString, "<Text") then
  271. return srcString
  272. end
  273. local strList = string.split(srcString, '>')
  274. local retStrList = {}
  275. local retStr = ""
  276. --like {<Text|x=25|y=20|color=250|size=18|text=施毒术使用必需品., |<Text|x=25|y=20|color=251|size=18|text=施毒术造成红毒效果.>}
  277. for _, splitStr in pairs(strList) do
  278. retStr = ""
  279. if string.sub(splitStr, 1, 1) == "|" then
  280. retStr = retStr .. "\n"
  281. end
  282. -- like Text|x=25|y=20|color=250|size=18|text=施毒术使用必需品.
  283. splitStr_2 = string.gsub(splitStr, "[%<]", "")
  284. -- like {Text,x=25,y=20, color=250, size=18, text=施毒术使用必需品.}
  285. splitStr_3 = string.split(splitStr_2, "|")
  286. -- 先找到文本
  287. for _, splitStr_4 in pairs(splitStr_3) do
  288. if string.contains(splitStr_4, "text") then
  289. -- resStr=施毒术使用必需品.
  290. retStr = retStr .. string.replace(splitStr_4, "text=", "")
  291. end
  292. end
  293. -- 在找其他
  294. for _, splitStr_4 in pairs(splitStr_3) do
  295. if string.contains(splitStr_4, "color") then
  296. local rgbId = tonumber(string.replace(splitStr_4, "color=", ""))
  297. local a = ConfigManager.Get_cfg_color(tonumber(rgbId))
  298. local rgbConfig = ConfigManager.Get_cfg_color(tonumber(rgbId)).color
  299. -- like <color=#00ff00>施毒术使用必需品</color>
  300. retStr = string.format("<color=%s>", rgbConfig) .. retStr
  301. retStr = retStr .. "</color>"
  302. end
  303. end
  304. table.insert(retStrList, retStr)
  305. end
  306. return table.concat(retStrList, "")
  307. end
  308. ---@return number @获得图集播放帧率
  309. ---@param frameInterval number @单位毫秒
  310. function this:GetAtlasFPS(frameInterval)
  311. if frameInterval > 0 then
  312. return 1000 / frameInterval
  313. end
  314. return 10
  315. end
  316. ---@return number @获得图集播放时间
  317. ---@param frameInterval number @单位毫秒
  318. ---@param frameCount number @图集的图片数量
  319. function this:GetAtlasPlayTime(frameCount, frameInterval)
  320. return frameCount * frameInterval * 0.001
  321. end
  322. function this.NewEventManager()
  323. return rrequire "Event/EventManagerBase"
  324. end
  325. ---@param event Event
  326. function this.DispatchValueChange(event, old, new)
  327. if not this.changeData then
  328. ---@type RoleChangeData
  329. this.changeData = {}
  330. end
  331. this.changeData.old = old
  332. this.changeData.new = new
  333. EventManager.Dispatch(event, this.changeData)
  334. end
  335. ---@param role Role
  336. function this.DispatchSelfValueChange(event, role, old, new)
  337. if role.RoleType == ERoleType.Me then
  338. if not this.changeData then
  339. ---@type RoleChangeData
  340. this.changeData = {}
  341. end
  342. this.changeData.old = old
  343. this.changeData.new = new
  344. EventManager.Dispatch(event, this.changeData)
  345. end
  346. end
  347. ---@param trans UnityEngine.Transform
  348. function this.PrintParent(trans, pre)
  349. local content = ""
  350. while trans do
  351. content = trans.name .. '=>' .. content
  352. trans = trans.parent
  353. end
  354. logError(pre .. ' ' .. content)
  355. end
  356. function this.GetTimeStamp()
  357. -- return (DateTime.ToUniversalTime() - DateTime(1970, 1, 1, 0, 0, 0, CS.System.DateTimeKind.Utc)).TotalMillisecond
  358. return UtilityLua.ToNowTimestamp()
  359. end
  360. -- 配置表中的#00ffff转成0x00ffffff
  361. function this.TransTableColorToUnityColor(color)
  362. return string.replace(color, "#", "0x")--.."ff"
  363. end
  364. -- 配置表中的#00ffff转成0x00ffffff
  365. function this.TransUnityColorToTableColor(color)
  366. return string.replace(color, "0x", "#")--.."ff"
  367. end
  368. this.leftTop = 0
  369. this.leftButtom = 0
  370. this.rightTop = 0
  371. this.rightButtom = 0
  372. this.top = 11
  373. this.buttom = 9
  374. ---@param coord Dot2
  375. function this.IsRoleInView(coord)
  376. if not RoleManager.meData then
  377. return
  378. end
  379. if Dot2.DistancePow2(RoleManager.meData.OldCoord, coord) > 169 then
  380. return false
  381. end
  382. this.leftTop = (this.top) * (coord.z - (RoleManager.meData.OldCoord.z))
  383. - (-this.buttom) * (coord.x - (RoleManager.meData.OldCoord.x - this.top))
  384. this.leftButtom = (this.top) * (coord.z - (RoleManager.meData.OldCoord.z - this.buttom))
  385. - (this.buttom) * (coord.x - RoleManager.meData.OldCoord.x)
  386. this.rightTop = (-this.top) * (coord.z - RoleManager.meData.OldCoord.z)
  387. - (this.top) * (coord.x - (RoleManager.meData.OldCoord.x + this.top))
  388. this.rightButtom = (-this.top) * (coord.z - (RoleManager.meData.OldCoord.z + this.top))
  389. - (-this.buttom) * (coord.x - (RoleManager.meData.OldCoord.x))
  390. if ((this.leftTop > 0 and this.leftButtom > 0 and this.rightTop > 0 and this.rightButtom > 0) or (this.leftTop < 0 and this.leftButtom < 0 and this.rightTop < 0 and this.rightButtom < 0)) then
  391. return true
  392. end
  393. return false
  394. end
  395. function this:IsRoleEnterMapPointRange(x, z, range)
  396. return RoleManager.meData.NextCoord.z >= z - range and RoleManager.meData.NextCoord.z <= z + range and
  397. RoleManager.meData.NextCoord.x >= x - range and RoleManager.meData.NextCoord.x <= x + range
  398. end
  399. -- 根据颜色表中的cfgId和文本返回富文本
  400. function this.ReturnRichTextByColorIdAndText(colorId, text)
  401. local colorCfg = ConfigManager.Get_cfg_color(colorId)
  402. local color = colorCfg.color
  403. return this.ReturnRichTextByColorAndText(color, text)
  404. end
  405. -- 根据rgb和文本返回富文本
  406. function this.ReturnRichTextByColorAndText(color, text)
  407. return '<color=' .. color .. '>' .. text .. "</color>"
  408. end
  409. function this.foreachUserData(t, func)
  410. if not t or not func then
  411. return
  412. end
  413. local count = t.Length
  414. for i = 1, count do
  415. func(t[i - 1])
  416. end
  417. end
  418. function this.GetMonsterAtlasName(path)
  419. local strs = string.split(path, '/')
  420. if strs ~= nil then
  421. return strs[#strs - 1], strs[#strs]
  422. end
  423. return nil, nil
  424. end
  425. --获取怪物血条状态
  426. function this.GetBloodColorByStage(stage, specialBloodtab)
  427. local index = stage % (#specialBloodtab - 1)
  428. if index == 0 then
  429. index = #specialBloodtab
  430. else
  431. index = index + 1
  432. end
  433. local hpColorId = specialBloodtab[index]
  434. local hpBgColorId
  435. if index == #specialBloodtab then
  436. hpBgColorId = specialBloodtab[2]
  437. else
  438. hpBgColorId = specialBloodtab[index + 1]
  439. end
  440. if ConfigManager.Exsit_cfg_color(hpColorId) and ConfigManager.Exsit_cfg_color(hpBgColorId) then
  441. return string.replace(ConfigManager.Get_cfg_color(hpColorId).color, '#', '0x'), string.replace(ConfigManager.Get_cfg_color(hpBgColorId).color, '#', '0x')
  442. -- return ColorUtil.TryParseHtmlStringToColor(ConfigManager.Get_cfg_color(hpColorId).color) ,ColorUtil.TryParseHtmlStringToColor(ConfigManager.Get_cfg_color(hpBgColorId).color)
  443. end
  444. return nil, nil
  445. end
  446. -- ◆如,经验大于10000,则显示为1.X万,经验大于100000000,则显示1.X亿
  447. -- 显示2位小数
  448. function this.GetFormatStringNumber(number)
  449. if number < 10000 then
  450. return number
  451. elseif number < 100000000 then
  452. return string.format('%.2f万', number / 10000)
  453. else
  454. return string.format('%.2f亿', number / 100000000)
  455. end
  456. end
  457. -- ◆如,经验大于10000,则显示为1.X万,经验大于100000000,则显示1.X亿
  458. -- 显示2位小数
  459. function this.GetFormatStringNumberWithoutPoint(number)
  460. if number < 10000 then
  461. return number
  462. elseif number < 100000000 then
  463. return string.format('%.0f万', number / 10000)
  464. else
  465. return string.format('%.0f亿', number / 100000000)
  466. end
  467. end
  468. function this.NumberToChinese(num)
  469. local chineseNum = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" }
  470. local chineseUnit = { "", "十", "百", "千", "万", "亿" }
  471. if num == 0 then
  472. return chineseNum[1]
  473. end
  474. local result = ""
  475. local unitPos = 1
  476. local nonZero = false
  477. while num > 0 do
  478. local digit = num % 10
  479. if digit > 0 then
  480. if unitPos == 2 then
  481. result = chineseUnit[unitPos] .. result
  482. else
  483. result = chineseNum[digit + 1] .. chineseUnit[unitPos] .. result
  484. end
  485. nonZero = true
  486. elseif (unitPos == 5 and result:sub(1, 1) ~= chineseNum[1]) or (unitPos ~= 5 and nonZero) then
  487. result = chineseNum[digit + 1] .. result
  488. nonZero = false
  489. end
  490. num = math.floor(num / 10)
  491. unitPos = unitPos + 1
  492. end
  493. return result
  494. end
  495. local lastCollectFuncCallCountsTime = 0
  496. local collectFuncCallCounts = {}
  497. ---@return boolean @ 用来查找死循环调用的 使用 在函数开头 if not Misc.IsCanFuncCallByLimitCount() then return end
  498. function this.IsCanFuncCallByLimitCount(tableName, funcName, limitCallTime)
  499. if Time.frameCount ~= lastCollectFuncCallCountsTime then
  500. table.clear(collectFuncCallCounts)
  501. end
  502. if not collectFuncCallCounts[tableName] then
  503. collectFuncCallCounts[tableName] = {}
  504. end
  505. if limitCallTime == nil then
  506. limitCallTime = 100
  507. end
  508. collectFuncCallCounts[tableName][funcName] = collectFuncCallCounts[tableName][funcName] and collectFuncCallCounts[tableName][funcName] + 1 or 1
  509. if collectFuncCallCounts[tableName][funcName] > limitCallTime then
  510. logError(tableName, funcName, ' call too much > ', limitCallTime)
  511. return false
  512. end
  513. return true
  514. end
  515. function this.GetSampleNumberString(numArg)
  516. local num = tonumber(numArg)
  517. if not num then return numArg end
  518. if num < 10000 then
  519. --5位
  520. return num
  521. elseif num < 100000000 then
  522. --9位
  523. return math.floor(num / 1000 + 0.5) / 10 .. "万"
  524. elseif num < 1000000000000 then
  525. --13位
  526. return math.floor(num / 10000000 + 0.5) / 10 .. "亿"
  527. elseif num < 10000000000000000 then
  528. --17位
  529. return math.floor(num / 100000000000 + 0.5) / 10 .. "兆"
  530. else
  531. return math.floor(num / 100000000000 + 0.5) / 10 .. "兆"
  532. end
  533. return ""
  534. end
  535. function this.GetSampleNumberString2(num)
  536. if num < 10000 then
  537. --5位
  538. return num
  539. elseif num < 100000000 then
  540. --9位W
  541. return math.floor(num / 1000 + 0.5) / 10 .. "W"
  542. elseif num < 1000000000000 then
  543. --13位
  544. return math.floor(num / 10000000 + 0.5) / 10 .. "Y"
  545. elseif num < 10000000000000000 then
  546. --17位
  547. return math.floor(num / 100000000000 + 0.5) / 10 .. "Z"
  548. else
  549. return math.floor(num / 100000000000 + 0.5) / 10 .. "Z"
  550. end
  551. return ""
  552. end