utils = {}
--点击事件绑定
function utils.addclickevent(go, func, args)
LuaListener.Get(go, args).onClick = func
end
--拖拽事件绑定
function utils.addonPointerDown(go, func)
--按下
DragListener.Get(go).onPointerDown = func
end
function utils.addonPointerUp(go, func)
--抬起
DragListener.Get(go).onPointerUp = func
end
function utils.addonDrag(go, func)
DragListener.Get(go).onDrag = func
end
function utils.addonBeginDrag(go, func)
DragListener.Get(go).onBeginDrag = func
end
function utils.addonEndDrag(go, func)
DragListener.Get(go).onEndDrag = func
end
function utils.addchangeevent(go, func, id)
Util.AddChangeEvent(go, id or 0, func)
end
function utils.addsubmitevent(go, func)
Util.AddEditEndEvent(go.gameObject, func)
end
-- 拖曳的时候转换坐标用的
-- eventData是拖曳的时候的生成的,类型是UnityEngine.EventSystems.PointerEventData
-- rect_transform是需要转换坐标的的目标rectTransform
-- 最后返回转换后的一个Vector2
function utils.ScreenPointToLocalPointInRectangle(eventData, rect_transform)
local Vector2 = Util.ScreenPointToLocalPointInRectangle(eventData, rect_transform)
return Vector2
end
-- 增加spine骨骼动画完成事件回调
function utils.AddSpineEvent(go, func)
Util.AddSpineEvent(go, func)
end
-- 以异常捕获的方式执行指定函数
function utils.xpcall(func, ...)
if not LOGGABLE then
func()
return
end
local ok, msg = xpcall(func, debug.traceback, ...)
if not ok then
logerror(msg)
end
end
-- 获得指定秒数的日时分秒
function utils.second2DHMS(second)
if second <= 0 then
return 0, 0, 0, 0
end
local d = math.floor(second / 86400)
second = second - d * 86400
local h = math.floor(second / 3600)
second = second - h * 3600
local m = math.floor(second / 60)
second = second - m * 60
local s = second
return d, h, m, s
end
--设置子物体在服务体位置
function utils.setsiblingindex(trans, index)
trans:SetSiblingIndex(index)
end
--设置子物体在父物体的最上层
function utils.settopindex(trans)
local childcount = trans.parent.childCount
trans:SetSiblingIndex(childcount)
end
--设置指定物体的Postion3D值
function utils.setobjpostion(go, x, y, z)
if go then
go.transform.localPosition = Vector3.New(x, y, z)
end
end
--设置指定物体的激活状态
function utils.setactive(go, ac)
if go then
if go.SetActive then
go:SetActive(ac)
else
go.gameObject:SetActive(ac)
end
end
end
--判断物体的激活状态,并返回一个bool值
function utils.isactive(go)
if go then
return go.activeSelf
end
return false
end
-- 组件是否可用
function utils.interactable(com,inter)
if com then
com.interactable = inter
end
end
--添加子物体到父物体上,并设定一个层级位置
function utils.addchild(parent, prefab, index)
if prefab == nil or parent == nil then
log("Failed to add child!!")
return nil
end
local go = GameObject.Instantiate(prefab)
go.transform:SetParent(parent.transform)
go.transform.localScale = prefab.transform.localScale