FloatNode = {} local floatingEffect = "FloatingText" local buffFloatingEffect = "BuffFloatingText" local floor = math.floor -- 普通文字 TextFloatingColor = { Blue = 1, Red = 2, Purple = 3, Green = 4, DarkGreen=5, } local _FloatingTypeToColor = { [TextFloatingColor.Blue] = Color.New(31, 237, 255, 255) / 255, [TextFloatingColor.Red] = Color.New(236, 4, 4, 255) / 255, [TextFloatingColor.Purple] = Color.New(235, 17, 255, 255) / 255, [TextFloatingColor.Green] = Color.New(17, 255, 17, 255) / 255, [TextFloatingColor.DarkGreen] = Color.New(56, 127, 46, 255) / 255, } -- 艺术字 ArtFloatingType = { CritDamage = 1, -- 暴击 Damage = 2, Treat = 3, FireDamage = 4, PoisonDamage = 5, yujiaAdd = 6, } local ArtFloatingAnim = { [1] = "Crit_Attack_Float", [2] = "Normal_Attack_Float", [3] = "floatingTextAnim", [4] = "floatingTextAnim", [5] = "floatingTextAnim", } --角色受到的暴击伤害(无论什么类型) - 红色字体 (字符顺序:40-49 ,0-9)(110, -)(111, +)(33, 暴击)(35, 灼烧) --角色造成的点击技伤害 - 白色字体 (字符顺序:50-59 ,0-9)(112, -)(113, +) --角色造成的滑动技伤害 - 黄色字体 (字符顺序:60-69 ,0-9)(114, -)(115, +) --角色恢复量 - 绿色字体 (字符顺序:70-79 ,0-9)(116, -)(117, +) --角色造成的异妖技伤害 - 紫色字体 (字符顺序:80-89 ,0-9)(118, -)(119, +)(34, 中毒) ArtFloatingColor = { Red = 0, White = 1, Yellow = 2, Green = 3, Purple = 4, Poison = 5, Fire = 6, } function FloatNode.New(unit, root, node) local o = {} setmetatable(o, {__index = FloatNode}) o:ctor(unit, root, node) return o end function FloatNode:ctor(unit, root, node) self.spLoader = SpriteLoader.New() self.owner = unit self.RootPanel = root self.GameObject = node self.LastBuffTextTime = Time.realtimeSinceStartup self.BuffTextCount = 0 self.LastFloatingTime = Time.realtimeSinceStartup self.FloatingCount = 0 end function FloatNode:Dispose() self.spLoader:Destroy() end function FloatNode:TextBuffFloating(type, text) local color = _FloatingTypeToColor[type] local go = BattleManager.LoadAsset(buffFloatingEffect) local baseY = 0 go.transform:SetParent(self.RootPanel.transform) go.transform.localScale = Vector3.one go.transform.position = self.GameObject.transform.position go:SetActive(true) if Time.realtimeSinceStartup - self.LastBuffTextTime < BattleLogic.GameDeltaTime then self.BuffTextCount = self.BuffTextCount + 1 else self.BuffTextCount = 0 end self.LastBuffTextTime = Time.realtimeSinceStartup local v2 = go:GetComponent("RectTransform").anchoredPosition go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0,baseY + self.BuffTextCount * 60) local battleSorting = BattleManager.GetBattleSorting() Util.GetGameObject(go, "anim"):GetComponent("Canvas").sortingOrder = battleSorting + 200 Util.GetGameObject(go, "anim/text"):SetActive(true) Util.GetGameObject(go, "anim/text"):GetComponent("Text").text = text Util.GetGameObject(go, "anim/text"):GetComponent("Text").color = color Util.GetGameObject(go, "anim/grid"):SetActive(false) BattleManager.AddDelayRecycleRes(buffFloatingEffect, go, 1.3) end -- function FloatNode:ImageBuffFloating(textImg, numImg, numTxt,type,isPurple) local go = BattleManager.LoadAsset(buffFloatingEffect) local baseY = 0 go.transform:SetParent(self.RootPanel.transform) go.transform.localScale = Vector3.one go.transform.position = self.GameObject.transform.position go:SetActive(true) if Time.realtimeSinceStartup - self.LastBuffTextTime < BattleLogic.GameDeltaTime then self.BuffTextCount = self.BuffTextCount + 1 else self.BuffTextCount = 0 end self.LastBuffTextTime = Time.realtimeSinceStartup local v2 = go:GetComponent("RectTransform").anchoredPosition go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0,baseY + self.BuffTextCount * 60) local battleSorting = BattleManager.GetBattleSorting() Util.GetGameObject(go, "anim"):GetComponent("Canvas").sortingOrder = battleSorting + 200 Util.GetGameObject(go, "anim/text"):SetActive(false) Util.GetGameObject(go, "anim/grid"):SetActive(true) local img1 = Util.GetGameObject(go, "anim/grid/Image1"):GetComponent("Image") local img2 = Util.GetGameObject(go, "anim/grid/Image2"):GetComponent("Image") local txt3 = Util.GetGameObject(go, "anim/grid/Text"):GetComponent("Text") local txt4 = Util.GetGameObject(go, "anim/grid/Text1"):GetComponent("Text") if textImg then img1.gameObject:SetActive(true) if type~=nil and type~=0 then local list = string.split(textImg, "#") if list and LengthOfTable(list)>1 then textImg=list[type] end end img1.sprite = self.spLoader:LoadSprite(textImg) img1:SetNativeSize() else img1.gameObject:SetActive(false) end if numImg then img2.gameObject:SetActive(true) img2.sprite = self.spLoader:LoadSprite(numImg) img2:SetNativeSize() else img2.gameObject:SetActive(false) end if numTxt then txt3.gameObject:SetActive(true) if isPurple then txt4.gameObject:SetActive(true) txt3.gameObject:SetActive(false) else txt4.gameObject:SetActive(false) txt3.gameObject:SetActive(true) end txt3.text = numTxt txt4.text = numTxt else txt3.gameObject:SetActive(false) txt4.gameObject:SetActive(false) end BattleManager.AddDelayRecycleRes(buffFloatingEffect, go, 1.3) end function FloatNode:GetArtText(type, color, value) local sp = "" local text = "" value=floor(value) if type == ArtFloatingType.CritDamage then sp = "r_zhandou_baoji_zh" -- 暴击 text = text .. string.char((color*2)+110) -- 减号 elseif type == ArtFloatingType.Damage then text = text .. string.char((color*2)+110) -- 减号 elseif type == ArtFloatingType.Treat then text = text..string.char((color*2)+111) -- 加号 elseif type == ArtFloatingType.FireDamage then sp = "z_zhandou_zhuoshao_zh" -- 灼烧 -- text = text .. string.char(35) -- 灼烧文字 text = text .. string.char((color*2)+110) -- 减号 elseif type == ArtFloatingType.PoisonDamage then sp = "z_zhandou_zhongdu_zh" -- 灼烧 -- text = text .. string.char(34) -- 中毒文字 text = text .. string.char((color*2)+110) -- 减号 elseif type == ArtFloatingType.yujiaAdd then sp = "z_zhandou_yujia_zh" --御甲 text = text .. string.char((color*2)+111) -- 减号 end -- 数字 local str = tostring(value) for i=1,#str do text = text..string.char((string.byte(str,i) - 48) + color*10 + 40) end return sp, text end function FloatNode:ArtFloating(type, color, value,frameColor) local go = BattleManager.LoadAsset(floatingEffect) go.transform:SetParent(self.RootPanel.transform) go.transform.localScale = Vector3.one * 0.7 go.transform.position = self.GameObject.transform.position go:SetActive(true) if Time.realtimeSinceStartup - self.LastFloatingTime < BattleLogic.GameDeltaTime then self.FloatingCount = self.FloatingCount + 1 else self.FloatingCount = 0 end self.LastFloatingTime = Time.realtimeSinceStartup local v2 = go:GetComponent("RectTransform").anchoredPosition v2 = v2 + Vector2.New(0, self.owner.role.camp * 100 + 100) go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0, 50) * (self.FloatingCount+1) local sp, text = self:GetArtText(type, color, value) local anim = Util.GetGameObject(go, "anim") -- 伤害文字 local img = Util.GetGameObject(anim, "Image"):GetComponent("Image") if sp and sp ~= "" then img.sprite = self.spLoader:LoadSprite(sp) img.gameObject:SetActive(true) else img.gameObject:SetActive(false) end -- 伤害数值 local animTxt = Util.GetGameObject(go, "anim/anim") local animTxtC = animTxt:GetComponent("Text") animTxtC.text = text --主要用于给白色字体染色成其他颜色,color 参数只能填白色 -- 层级和动画 anim:GetComponent("Canvas").sortingOrder = BattleManager.GetBattleSorting() + 100 anim:GetComponent("Animator"):Play(ArtFloatingAnim[type]) BattleManager.AddDelayRecycleRes(floatingEffect, go, 2) end return FloatNode