ZombieKitty b8a3a5897b 移除一些不必要的日志
添加打印Table的LUA 函数
2025-01-26 04:56:43 +08:00

270 lines
8.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
-- 作者: gzg
-- 日期: 2019-04-11
-- 文件: UnityUtils.lua
-- 模块: UnityUtils
-- 描述: 操纵Unity对象的一些公共函数
------------------------------------------------
local CSUIUtility = CS.Thousandto.Plugins.Common.UIUtility
local CSUnityUtils = CS.Thousandto.Core.Base.UnityUtils;
local CSLuaUnityUtility = CS.LuaUnityUtility;
local L_SetParent = CSLuaUnityUtility.SetParent;
local L_SetParentAndReset = CSLuaUnityUtility.SetParentAndReset;
local L_ResetTransform = CSLuaUnityUtility.ResetTransform;
local L_Clone = CSUIUtility.Clone;
local L_GetObjct2Int = CSLuaUnityUtility.GetObjct2Int;
local L_GetObjct2Byte = CSLuaUnityUtility.GetObjct2Byte;
local L_RequireComponent = CSLuaUnityUtility.RequireComponent;
local L_RequireLuaBehaviour = CSLuaUnityUtility.RequireLuaBehaviour;
local L_GetComponentInChildren = CSLuaUnityUtility.GetComponentInChildren;
local L_GetComponentsInChildren = CSLuaUnityUtility.GetComponentsInChildren;
local L_SetLocalPosition = CSLuaUnityUtility.SetLocalPosition;
local L_SetLocalPositionX = CSLuaUnityUtility.SetLocalPositionX;
local L_SetLocalPositionY = CSLuaUnityUtility.SetLocalPositionY;
local L_SetLocalPositionZ = CSLuaUnityUtility.SetLocalPositionZ;
local L_SetLocalRotation = CSLuaUnityUtility.SetLocalRotation;
local L_SetLocalEulerAngles = CSLuaUnityUtility.SetLocalEulerAngles;
local L_SetLocalScale = CSLuaUnityUtility.SetLocalScale;
local L_SetPosition = CSLuaUnityUtility.SetPosition;
local L_SetRotation = CSLuaUnityUtility.SetRotation;
local L_SetAulerAngles = CSLuaUnityUtility.SetAulerAngles;
local L_SetForward = CSLuaUnityUtility.SetForward;
local L_SetUp = CSLuaUnityUtility.SetUp;
local L_SetRight = CSLuaUnityUtility.SetRight;
local L_SetTweenPositionFrom = CSLuaUnityUtility.SetTweenPositionFrom;
local L_SetTweenPositionTo = CSLuaUnityUtility.SetTweenPositionTo;
local L_SetLayer = CSLuaUnityUtility.SetLayer;
local L_WorldPosToHudPos = CSLuaUnityUtility.WorldPosToHudPos;
local L_IsUseUsePCMOdel = CSLuaUnityUtility.IsUseUsePCMOdel;
local L_UNITY_WINDOWS = CSLuaUnityUtility.UNITY_WINDOWS;
local UnityUtils = {}
local L_IsUseKeyCode = nil;
-- 设置父物体
function UnityUtils.SetParent(child, parent)
L_SetParent(child, parent);
end
-- 设置父物体并重置Transform
function UnityUtils.SetParentAndReset(child, parent)
L_SetParentAndReset(child, parent);
end
-- 把Transform的本地位置,大小和角度都复位为0
function UnityUtils.ResetTransform(trans)
L_ResetTransform(trans)
end
-- 克隆 gameObject [,parent, isReset]
function UnityUtils.Clone(gameObject, parent, isReset)
if parent then
return L_Clone(gameObject, parent, not (not isReset))
else
return L_Clone(gameObject, not (not isReset))
end
end
-- 是否使用宏USE_NEW_CFG
function UnityUtils.USE_NEW_CFG()
return CSLuaUnityUtility.USE_NEW_CFG()
end
-- c#的获取类型
function UnityUtils.GetType(obj)
return CSLuaUnityUtility.GetType(obj)
end
-- object类型转int类型枚举类型转int可以用此函数
function UnityUtils.GetObjct2Int(obj)
if type(obj) == "number" then
return obj
end
return L_GetObjct2Int(obj)
end
-- object类型转byte类型枚举类型转byte可以用此函数
function UnityUtils.GetObjct2Byte(obj)
return L_GetObjct2Byte(obj)
end
-- 根据类型名增加组件strType空间名+类名) --暂时屏蔽
-- function UnityUtils.RequireComponent(trans,strType)
-- return L_RequireComponent(trans,strType)
-- end
-- 增加 LuaBehaviour 组件
function UnityUtils.RequireLuaBehaviour(trans)
return L_RequireLuaBehaviour(trans)
end
-- 获取子节点的第一个组件
function UnityUtils.GetComponentInChildren(trans, strType)
return L_GetComponentInChildren(trans, strType)
end
-- 获取子节点Components
function UnityUtils.GetComponentsInChildren(trans, compType, ...)
return L_GetComponentsInChildren(trans, compType, ...)
end
--------------------------------------[对Transform的操作]------------------------------------------------
-- 设置Transform的localPosition
function UnityUtils.SetLocalPosition(trans, x, y, z)
L_SetLocalPosition(trans, x, y, z)
end
-- 设置Transform的localPositionY
function UnityUtils.SetLocalPositionX(trans, x)
L_SetLocalPositionX(trans, x)
end
-- 设置Transform的localPositionY
function UnityUtils.SetLocalPositionY(trans, y)
L_SetLocalPositionY(trans, y)
end
-- 设置Transform的localPositionY
function UnityUtils.SetLocalPositionZ(trans, z)
L_SetLocalPositionZ(trans, z)
end
-- 设置Transform的Localrotation
function UnityUtils.SetLocalRotation(trans, x, y, z, w)
L_SetLocalRotation(trans, x, y, z, w)
end
-- 设置Transform的LocalEulerAngles
function UnityUtils.SetLocalEulerAngles(trans, x, y, z)
L_SetLocalEulerAngles(trans, x, y, z)
end
-- 设置Transform的localScale
function UnityUtils.SetLocalScale(trans, x, y, z)
L_SetLocalScale(trans, x, y, z)
end
-- 设置Transform的position
function UnityUtils.SetPosition(trans, x, y, z)
L_SetPosition(trans, x, y, z)
end
-- 设置Transform的rotation
function UnityUtils.SetRotation(trans, x, y, z, w)
L_SetRotation(trans, x, y, z, w)
end
-- 设置Transform的eulerAngles
function UnityUtils.SetAulerAngles(trans, x, y, z)
L_SetAulerAngles(trans, x, y, z)
end
-- 设置Transform的forward
function UnityUtils.SetForward(trans, x, y, z)
L_SetForward(trans, x, y, z)
end
-- 设置Transform的up
function UnityUtils.SetUp(trans, x, y, z)
L_SetUp(trans, x, y, z)
end
-- 设置Transform的right
function UnityUtils.SetRight(trans, x, y, z)
L_SetRight(trans, x, y, z)
end
-- 设置TweenPosition的from
function UnityUtils.SetTweenPositionFrom(tweenPos, x, y, z)
L_SetTweenPositionFrom(tweenPos, x, y, z)
end
-- 设置TweenPosition的to
function UnityUtils.SetTweenPositionTo(tweenPos, x, y, z)
L_SetTweenPositionTo(tweenPos, x, y, z)
end
-- 调用组件函数
-- 调用UIScrollView.ResetPosition()
function UnityUtils.ScrollResetPosition(trans)
CSLuaUnityUtility.ScrollResetPosition(trans)
end
-- 调用UIGrid.Reposition()
function UnityUtils.GridResetPosition(trans)
CSLuaUnityUtility.GridResetPosition(trans)
end
-- copy text 到剪贴板
function UnityUtils.CopyToClipboard(str)
CSUIUtility.CopyToClipboard(str)
end
-- UNITY_EDITOR
function UnityUtils.UNITY_EDITOR()
return CSLuaUnityUtility.UNITY_EDITOR()
end
function UnityUtils.SetLayer(trans, layer, recursive)
L_SetLayer(trans, layer, recursive);
end
function UnityUtils.WorldPosToHudPos(mainCamera, uiCamera, worldPos)
return L_WorldPosToHudPos(mainCamera, uiCamera, worldPos);
end
-- 是否使用Profiler界面
function UnityUtils.IsUseKeyCode()
if L_IsUseKeyCode == nil then
L_IsUseKeyCode = CSLuaUnityUtility.IsUseKeyCode()
end
return L_IsUseKeyCode;
end
-- 通过名字,查找当前场景的第一层节点的GameObject
function UnityUtils.FindSceneRoot(name)
return CSUnityUtils.FindSceneRoot(name);
end
-- 是否使用pc模式
function UnityUtils.IsUseUsePCMOdel()
return L_IsUseUsePCMOdel()
end
--是否是windows版本
function UnityUtils.UNITY_WINDOWS()
return L_UNITY_WINDOWS()
end
-- 打印table
function print_r ( t )
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
print(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
print(indent..string.rep(" ",string.len(pos)+6).."}")
elseif (type(val)=="string") then
print(indent.."["..pos..'] => "'..val..'"')
else
print(indent.."["..pos.."] => "..tostring(val))
end
end
else
print(indent..tostring(t))
end
end
end
if (type(t)=="table") then
print(tostring(t).." {")
sub_print_r(t," ")
print("}")
else
sub_print_r(t," ")
end
print()
end
return UnityUtils