------------------------------------------------ -- 作者: gzg -- 日期: 2019-04-11 -- 文件: UIUtils.lua -- 模块: UIUtils -- 描述: 处理UI的一些常用函数 ------------------------------------------------ local UIUtils = {}; local UIUtility = CS.Thousandto.Plugins.Common.UIUtility; local EventDelegate = CS.EventDelegate local L_GetSize = UIUtility.GetSize; local L_GetSizeX = UIUtility.GetSizeX; local L_GetSizeY = UIUtility.GetSizeY; local L_RotationToForward = UIUtility.RotationToForward; local L_MiniMapPosToWorldPos = UIUtility.MiniMapPosToWorldPos; local L_WorldPosToMiniMapPos = UIUtility.WorldPosToMiniMapPos; local L_RequireUIItem = UIUtility.RequireUIItem; local L_RequireUIListMenu = UIUtility.RequireUIListMenu; local L_RequireUIRoleSkinCompoent = UIUtility.RequireUIRoleSkinCompoent; local L_RequireUIPlayerSkinCompoent = UIUtility.RequireUIPlayerSkinCompoent; local L_RequireUIVfxSkinCompoent = UIUtility.RequireUIVfxSkinCompoent; local L_RequireUIShandowPlane = UIUtility.RequireUIShandowPlane; local L_RequireUIIcon = UIUtility.RequireUIIcon; local L_RequireUIIconBase = UIUtility.RequireUIIconBase; local L_RequireSpringPanel = UIUtility.RequireSpringPanel; local L_RequireTweenPosition = UIUtility.RequireTweenPosition; local L_RequireLoopMoveSceneScript = UIUtility.RequireLoopMoveSceneScript; local L_RequireUIVideoTexture = UIUtility.RequireUIVideoTexture; local L_RequireAnimListBaseScript = UIUtility.RequireAnimListBaseScript; local L_RequireAnimator = UIUtility.RequireAnimator; local L_SetColor = UIUtility.SetColor; local L_SetEffectColor = UIUtility.SetEffectColor; local L_SetColorByQuality = UIUtility.SetColorByQuality; local L_SetSprGenColor = UIUtility.SetSprGenColor; local L_SetAllChildColorGray = UIUtility.SetAllChildColorGray; local L_RequireUIPlayerHead = UIUtility.RequireUIPlayerHead; local L_RequireUISpriteAnimation = UIUtility.RequireUISpriteAnimation; local L_RequireUIPolygonScript = UIUtility.RequireUIPolygonScript; local L_RequireUIPlayerBagItem = require ("UI.Components.UIPlayerBagItem") local L_RequireNatureVfxEffect = UIUtility.RequireNatureVfxEffect; local L_RequireUILoopScrollViewBase = UIUtility.RequireUILoopScrollViewBase local L_RequireUISelectEquipItem = UIUtility.RequireUISelectEquipItem local L_RequireCamera = UIUtility.RequireCamera local L_RequireUIMoneyForm = UIUtility.RequireUIMoneyForm local L_RequireUIFrameAnimation = UIUtility.RequireUIFrameAnimation local L_SetTextByMessageStringID = UIUtility.SetTextByMessageStringID local L_SetTextByStringDefinesID = UIUtility.SetTextByStringDefinesID local L_SetTextByNumber = UIUtility.SetTextByNumber local L_SetTextByBigNumber = UIUtility.SetTextByBigNumber local L_SetTextByString = UIUtility.SetTextByString local L_ClearText = UIUtility.ClearText local L_SetTextFormat = UIUtility.SetTextFormat local L_SetTextByProgress = UIUtility.SetTextByProgress local L_SetTextByPercent = UIUtility.SetTextByPercent local L_SetTextMMSS = UIUtility.SetTextMMSS local L_SetTextHHMMSS = UIUtility.SetTextHHMMSS local L_SetTextDDHHMMSS = UIUtility.SetTextDDHHMMSS local L_SetTextYYMMDDHHMMSS = UIUtility.SetTextYYMMDDHHMMSS local L_SetTextYYMMDDHHMMSSNotZone = UIUtility.SetTextYYMMDDHHMMSSNotZone local L_GetText = UIUtility.GetText local L_SetGameObjectNameByNumber = UIUtility.SetGameObjectNameByNumber local L_PanelClipOffsetToZero = UIUtility.PanelClipOffsetToZero local L_FindBtn = UIUtility.FindBtn local L_FindPanel = UIUtility.FindPanel local L_FindLabel = UIUtility.FindLabel local L_FindTex = UIUtility.FindTex local L_RequireTex = UIUtility.RequireTex local L_FindSpr = UIUtility.FindSpr local L_FindWid = UIUtility.FindWid local L_FindGrid = UIUtility.FindGrid local L_FindTable = UIUtility.FindTable local L_FindToggle = UIUtility.FindToggle local L_FindScrollView = UIUtility.FindScrollView local L_FindProgressBar = UIUtility.FindProgressBar local L_FindSlider = UIUtility.FindSlider local L_FindInput = UIUtility.FindInput local L_FindTweenPosition = UIUtility.FindTweenPosition local L_FindTweenColor = UIUtility.FindTweenColor local L_FindTweenScale = UIUtility.FindTweenScale local L_FindTweenRotation = UIUtility.FindTweenRotation local L_FindTweenAlpha = UIUtility.FindTweenAlpha local L_FindCamera = UIUtility.FindCamera local L_FindBoxCollider = UIUtility.FindBoxCollider local L_FindScrollBar = UIUtility.FindScrollBar local L_FindLuaForm = UIUtility.FindLuaForm local L_FindExtendLuaForm = UIUtility.FindExtendLuaForm local L_FindEventListener = UIUtility.FindEventListener local L_FindTweenTransform = UIUtility.FindTweenTransform local L_SetTextByPropName = UIUtility.SetTextByPropName local L_SetTextByPropValue = UIUtility.SetTextByPropValue local L_SetTextByPropNameAndValue = UIUtility.SetTextByPropNameAndValue local L_SetTextFormatById = UIUtility.SetTextFormatById local L_FindPlayableDirector = UIUtility.FindPlayableDirector local L_FindSutureTex = UIUtility.FindSutureTex local L_RequireUIBlinkCompoent = UIUtility.RequireUIBlinkCompoent local L_RequireUISpriteSelectEffect = UIUtility.RequireUISpriteSelectEffect local L_StripLanSymbol = UIUtility.StripLanSymbol local L_RequireDragScrollView = UIUtility.RequireDragScrollView local L_SearchHierarchy = UIUtility.SearchHierarchy local L_FindFRealObjectScript = UIUtility.FindFRealObjectScript -- 获取Label的texts function UIUtils.GetText(label) if not label then return; end return L_GetText(label) end -- 设置label文本(参数:MessageString配置中的枚举) function UIUtils.SetTextByEnum(label, enum, ...) if not label or not enum then return; end local _id = DataConfig.DataMessageString.GetKey(enum); if _id then L_SetTextByMessageStringID(label, _id, ...); else Debug.LogError("MessageString中不存在该Enum = ", enum) end end -- 设置label文本(参数:MessageString配置中的id) function UIUtils.SetTextByMessageStringID(label, id, ...) L_SetTextByMessageStringID(label, id, ...); end -- 设置label文本(参数:StringDefines配置中的id) function UIUtils.SetTextByStringDefinesID(label, id, ...) if not label or not id then return; end L_SetTextByStringDefinesID(label, id, ...); end -- 设置label文本(参数:数值类型),isUseBigUnit:是否使用大单位 function UIUtils.SetTextByNumber(label, number, isUseBigUnit, validCount) if not label or not number then return; end L_SetTextByNumber(label, number, not (not isUseBigUnit), validCount or 0); end -- 设置label文本(参数:数值类型),isUseBigUnit:是否使用大单位 function UIUtils.SetTextByBigNumber(label, number, isUseBigUnit, validCount) if not label or not number then return; end L_SetTextByBigNumber(label, number, not (not isUseBigUnit), validCount or 0); end -- 设置label文本(参数:字符串类型) function UIUtils.SetTextByString(label, str) if not label or not str then return; end L_SetTextByString(label, str); end -- 清除label文本 function UIUtils.ClearText(label) if not label then return; end return L_ClearText(label); end function UIUtils.SetTextFormatById(label, formatId, id) if not label then return; end return L_SetTextFormatById(label, formatId, id) end -- 设置label文本 function UIUtils.SetTextFormat(label, csFormatStr, ...) if not label or not csFormatStr then return; end L_SetTextFormat(label, csFormatStr, ...); end -- 设置时间类型的Label function UIUtils.SetTextMMSS(label, second) if not label or not second then return; end L_SetTextMMSS(label, second); end -- 设置时间类型的Label function UIUtils.SetTextHHMMSS(label, second) if not label or not second then return; end L_SetTextHHMMSS(label, second); end -- 设置时间类型的Label function UIUtils.SetTextDDHHMMSS(label, second) if not label or not second then return; end L_SetTextDDHHMMSS(label, second); end function UIUtils.SetTextYYMMDDHHMMSS(label, second) if not label or not second then return; end L_SetTextYYMMDDHHMMSS(label, second) end function UIUtils.SetTextYYMMDDHHMMSSNotZone(label, second) if not label or not second then return; end L_SetTextYYMMDDHHMMSSNotZone(label, second) end -- 设置进度{0}/{1}类型的Label ,isUseBigUnit:是否使用大单位 function UIUtils.SetTextByProgress(label, num1, num2, isUseBigUnit, validCount) if label and num1 and num2 then L_SetTextByProgress(label, num1, num2, not (not isUseBigUnit), validCount or 0) end end -- 设置百分比{0}%类型的Label function UIUtils.SetTextByPercent(label, num) if label and num then L_SetTextByPercent(label, num) end end --设置属性名字 function UIUtils.SetTextByPropName(label, proId, formatString) L_SetTextByPropName(label, proId, formatString) end --设置属性值 function UIUtils.SetTextByPropValue(label, proId, proValue, formatString) L_SetTextByPropValue(label, proId, proValue, formatString) end --设置属性名字和值 function UIUtils.SetTextByPropNameAndValue(label, proId, proValue, formatString) L_SetTextByPropNameAndValue(label, proId, proValue, formatString) end -- lua端调用c#的string.Format函数 function UIUtils.CSFormat(original, ...) return UIUtility.Format(original, ...); end -- lua端调用c#的string.Format(String format, params object[] args )函数 function UIUtils.CSFormatLuaTable(original, t) return UIUtility.FormatLuatable(original, t); end -- 添加按钮事件 function UIUtils.AddBtnEvent(btn, method, caller, data) btn.onClick:Clear(); EventDelegate.Add(btn.onClick, Utils.Handler(method, caller, data)); end -- 添加按钮双击事件 function UIUtils.AddBtnDoubleClickEvent(btn, method, caller, data) btn.onDoubleClick:Clear() EventDelegate.Add(btn.onDoubleClick, Utils.Handler(method, caller, data)) end -- 添加改变事件--适合所有带有onChange事件的UI组件 function UIUtils.AddOnChangeEvent(uiComp, method, caller, data) uiComp.onChange:Clear(); EventDelegate.Add(uiComp.onChange, Utils.Handler(method, caller, data)); end -- 增加各种事件,eventDelegateList = List function UIUtils.AddEventDelegate(eventDelegateList, method, caller, data) eventDelegateList:Clear() EventDelegate.Add(eventDelegateList, Utils.Handler(method, caller, data)) end -- 获取控件size function UIUtils.GetSize(trans) return L_GetSize(trans); end -- 获取控件size.x function UIUtils.GetSizeX(trans) return L_GetSizeX(trans); end -- 获取控件size.y function UIUtils.GetSizeY(trans) return L_GetSizeY(trans); end -- 旋转到正面 function UIUtils.RotationToForward(trans, angle) return L_RotationToForward(trans, angle) end -- 根据地图UI上的坐标获取在世界坐标 function UIUtils.MiniMapPosToWorldPos(camYaw, uiSizeX, uiSizeY, mapSizeX, mapSizeY, camPosX, camPosY, clickPosX, clickPosY, clickPosZ) return L_MiniMapPosToWorldPos(camYaw, uiSizeX, uiSizeY, mapSizeX, mapSizeY, camPosX, camPosY, clickPosX, clickPosY, clickPosZ) end -- 根据世界坐标获取在地图UI上的坐标 function UIUtils.WorldPosToMiniMapPos(camYaw, uiSizeX, uiSizeY, mapSizeX, mapSizeY, camPosX, camPosY, worldPosX, worldPosY, worldPosZ) return L_WorldPosToMiniMapPos(camYaw, uiSizeX, uiSizeY, mapSizeX, mapSizeY, camPosX, camPosY, worldPosX, worldPosY, worldPosZ) end -- 查找trans function UIUtils.FindTrans(trans, path) if path then return trans:Find(path); else return trans; end end -- 查找gameobject function UIUtils.FindGo(trans, path) local _trans = UIUtils.FindTrans(trans, path) if _trans ~= nil then return _trans.gameObject; end return nil end -- 查找button function UIUtils.FindBtn(trans, path) return L_FindBtn(trans, path) end -- 查找Panel function UIUtils.FindPanel(trans, path) return L_FindPanel(trans, path) end -- 查找label function UIUtils.FindLabel(trans, path) return L_FindLabel(trans, path) end -- 查找texture function UIUtils.FindTex(trans, path) return L_FindTex(trans, path) end function UIUtils.RequireTex(trans, path) return L_RequireTex(trans, path) end -- 查找sprite function UIUtils.FindSpr(trans, path) return L_FindSpr(trans, path) end -- 查找widget function UIUtils.FindWid(trans, path) return L_FindWid(trans, path) end -- 查找grid function UIUtils.FindGrid(trans, path) return L_FindGrid(trans, path) end -- 查找table function UIUtils.FindTable(trans, path) return L_FindTable(trans, path) end -- 查找toggle function UIUtils.FindToggle(trans, path) return L_FindToggle(trans, path) end -- 查找ScrollView function UIUtils.FindScrollView(trans, path) return L_FindScrollView(trans, path) end -- 查找进度条 function UIUtils.FindProgressBar(trans, path) return L_FindProgressBar(trans, path) end -- 查找可调节的进度条. function UIUtils.FindSlider(trans, path) return L_FindSlider(trans, path) end -- 查找Input 组件 function UIUtils.FindInput(trans, path) return L_FindInput(trans, path) end -- 查找TweenPosition组件 function UIUtils.FindTweenPosition(trans, path) return L_FindTweenPosition(trans, path) end -- 查找TweenColor组件 function UIUtils.FindTweenColor(trans, path) return L_FindTweenColor(trans, path) end -- 查找TweenScale组件 function UIUtils.FindTweenScale(trans, path) return L_FindTweenScale(trans, path) end -- 查找TweenRotation组件 function UIUtils.FindTweenRotation(trans, path) return L_FindTweenRotation(trans, path) end -- 查找TweenAlpha组件 function UIUtils.FindTweenAlpha(trans, path) return L_FindTweenAlpha(trans, path) end -- 查找TweenAlpha组件 function UIUtils.FindCamera(trans, path) return L_FindCamera(trans, path) end function UIUtils.FindBoxCollider(trans, path) return L_FindBoxCollider(trans, path) end function UIUtils.FindScrollBar(trans, path) return L_FindScrollBar(trans, path) end function UIUtils.FindLuaForm(trans, path) return L_FindLuaForm(trans, path) end function UIUtils.FindExtendLuaForm(trans, path) return L_FindExtendLuaForm(trans, path) end function UIUtils.FindEventListener(trans, path) return L_FindEventListener(trans, path) end function UIUtils.FindTweenTransform(trans, path) return L_FindTweenTransform(trans, path) end function UIUtils.FindPlayableDirector(trans, path) return L_FindPlayableDirector(trans, path) end function UIUtils.FindSutureTex(trans, path) return L_FindSutureTex(trans, path) end function UIUtils.FindFRealObjectScript(trans, path) return L_FindFRealObjectScript(trans, path) end function UIUtils.SearchHierarchy(trans, name, ignoreCase) if not ignoreCase then ignoreCase = false end return L_SearchHierarchy(trans, name, ignoreCase) end -- 增加 UIListMenu 组件 function UIUtils.RequireUIListMenu(trans) return L_RequireUIListMenu(trans); end -- 增加 UIRoleSkinCompoent 组件 function UIUtils.RequireUIRoleSkinCompoent(trans) return UIRoleSkinManager:GetWrap(L_RequireUIRoleSkinCompoent(trans)); end -- 增加 UIPlayerSkinCompoent 组件 function UIUtils.RequireUIPlayerSkinCompoent(trans) return UIRoleSkinManager:GetWrap(L_RequireUIPlayerSkinCompoent(trans)); end -- 增加UIVfxSkinCompoent function UIUtils.RequireUIVfxSkinCompoent(trans) return L_RequireUIVfxSkinCompoent(trans); end -- 增加ui阴影组件 function UIUtils.RequireUIShandowPlane(trans) return L_RequireUIShandowPlane(trans); end -- 增加 UIIcon 组件 function UIUtils.RequireUIIcon(trans) return L_RequireUIIcon(trans); end -- 增加 UIIconBase 组件 function UIUtils.RequireUIIconBase(trans) return L_RequireUIIconBase(trans); end -- 增加 SpringPanel 组件 function UIUtils.RequireSpringPanel(trans) return L_RequireSpringPanel(trans); end -- 增加TweenPosition组件 function UIUtils.RequireTweenPosition(trans) return L_RequireTweenPosition(trans); end -- 增加LoopMoveSceneScript组件 function UIUtils.RequireLoopMoveSceneScript(trans) return L_RequireLoopMoveSceneScript(trans); end -- 增加UIVideoTexture组件 function UIUtils.RequireUIVideoTexture(trans) return L_RequireUIVideoTexture(trans); end -- 注册动画脚本 function UIUtils.RequireAnimListBaseScript(trans) return L_RequireAnimListBaseScript(trans); end -- 注册动画脚本 function UIUtils.RequireUISpriteAnimation(trans) return L_RequireUISpriteAnimation(trans) end -- 注册职业脚本 function UIUtils.RequireUIPolygonScript(trans) return L_RequireUIPolygonScript(trans) end -- 注册背包脚本 function UIUtils.RequireUIPlayerBagItem(trans) return L_RequireUIPlayerBagItem:New(trans) end -- 注册造化特效脚本 function UIUtils.RequireNatureVfxEffect(trans) return L_RequireNatureVfxEffect(trans) end -- 注册循环滑动脚本 function UIUtils.RequireUILoopScrollViewBase(trans) return L_RequireUILoopScrollViewBase(trans) end -- 注册选择装备脚本 function UIUtils.RequireUISelectEquipItem(trans) return L_RequireUISelectEquipItem(trans) end -- 注册金币窗体 function UIUtils.RequireUIMoneyForm(trans) return L_RequireUIMoneyForm(trans) end -- 注册帧动画脚本 function UIUtils.RequireUIFrameAnimation(trans) return L_RequireUIFrameAnimation(trans) end -- 注册摄像机的脚本 function UIUtils.RequireCamera(trans) return L_RequireCamera(trans) end -- 增加UIPlayerHead组件 function UIUtils.RequireUIPlayerHead(trans) return L_RequireUIPlayerHead(trans); end -- 注册animator脚本 function UIUtils.RequireAnimator(trans) return L_RequireAnimator(trans); end function UIUtils.RequireUIBlinkCompoent(trans) return L_RequireUIBlinkCompoent(trans) end function UIUtils.RequireUISpriteSelectEffect(trans) return L_RequireUISpriteSelectEffect(trans) end function UIUtils.RequireDragScrollView(trans) return L_RequireDragScrollView(trans) end -- 设置颜色(UILable、UITexture、UISprite) function UIUtils.SetColor(obj, r, g, b, a) L_SetColor(obj, r, g, b, a); end function UIUtils.SetEffectColor(label, r, g, b, a) L_SetEffectColor(label, r, g, b, a) end function UIUtils.SetColorByQuality(label, quality) L_SetColorByQuality(label, quality) end -- 设置颜色(UILable、UITexture、UISprite) function UIUtils.SetColorByString(obj, str) L_SetColor(obj, str); end -- 设置颜色 function UIUtils.SetColorByType(obj, colorType) if colorType == ColorType.White then L_SetColor(obj, 1, 1, 1, 1); elseif colorType == ColorType.Black then L_SetColor(obj, 0, 0, 0, 1); elseif colorType == ColorType.Red then L_SetColor(obj, 1, 0, 0, 1); elseif colorType == ColorType.Blue then L_SetColor(obj, 0, 0, 1, 1); elseif colorType == ColorType.Green then L_SetColor(obj, 0, 1, 0, 1); elseif colorType == ColorType.Yellow then L_SetColor(obj, 1, 0.92, 0.016, 1); elseif colorType == ColorType.Gray then L_SetColor(obj, 0.5, 0.5, 0.5, 1); elseif colorType == ColorType.Clear then L_SetColor(obj, 0, 0, 0, 0); end end -- 设置白色 function UIUtils.SetWhite(obj) L_SetColor(obj, 1, 1, 1, 1); end -- 设置灰色 function UIUtils.SetGray(obj) L_SetColor(obj, 0.5, 0.5, 0.5, 1); end -- 设置红色 function UIUtils.SetRed(obj) L_SetColor(obj, 1, 0, 0, 1); end -- 设置绿色 function UIUtils.SetGreen(obj) L_SetColor(obj, 0, 1, 0, 1); end -- 设置蓝色 function UIUtils.SetBlue(obj) L_SetColor(obj, 0, 0, 1, 1); end -- 设置黄色 function UIUtils.SetYellow(obj) L_SetColor(obj, 1, 0.92, 0.016, 1); end -- 设置图片渐变色 function UIUtils.SetSprGenColor(spr, quality) L_SetSprGenColor(spr, quality) end -- 设置子物体全部为灰色,且不能点击 function UIUtils.SetAllChildColorGray(trs, isGray) L_SetAllChildColorGray(trs, isGray) end -- 设置gameobject的name function UIUtils.SetGameObjectNameByNumber(go, number) L_SetGameObjectNameByNumber(go, number) end -- 把Panel的ClipOffset设置为0 function UIUtils.PanelClipOffsetToZero(panel) L_PanelClipOffsetToZero(panel) end -- 隐藏多余的(元素必须要有Gobj) function UIUtils.HideNeedless(list, showCnt) local _listCnt = list:Count() local _needHideCnt = _listCnt - showCnt for i = _listCnt, _listCnt - _needHideCnt + 1, -1 do if list[i].Gobj then list[i].Gobj:SetActive(false) end end end --获取语言的符号 function UIUtils.StripLanSymbol(text,lan) return L_StripLanSymbol(text,lan); end return UIUtils;