Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱码士兄弟
UnityXFramework
提交
00e36dc3
U
UnityXFramework
项目概览
爱码士兄弟
/
UnityXFramework
与 Fork 源项目一致
Fork自
林新发 / UnityXFramework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
UnityXFramework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
00e36dc3
编写于
3月 25, 2022
作者:
林
林新发
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
树界面节点逻辑优化
上级
3fae9d03
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
36 deletion
+66
-36
Assets/LuaFramework/Lua/Logic/Tree/TreeLogic.lua
Assets/LuaFramework/Lua/Logic/Tree/TreeLogic.lua
+11
-3
Assets/LuaFramework/Lua/View/Tree/TreePanel.lua
Assets/LuaFramework/Lua/View/Tree/TreePanel.lua
+55
-33
未找到文件。
Assets/LuaFramework/Lua/Logic/Tree/TreeLogic.lua
浏览文件 @
00e36dc3
...
...
@@ -34,6 +34,8 @@ function TreeLogic.Init()
-- 根节点
this
.
root
=
TreeNode
.
New
(
"Root"
)
this
.
root
=
this
.
MakeTree
(
data_table
,
this
.
root
)
-- 打印树
local
str
=
''
str
=
this
.
TreeToString
(
this
.
root
,
str
)
log
(
str
)
...
...
@@ -67,18 +69,24 @@ function TreeLogic.MakeTree(tb, parent)
return
parent
end
-- 把树转为字符串
function
TreeLogic
.
TreeToString
(
node
,
str
)
if
nil
~=
node
.
value
then
local
tabspace
=
''
for
i
=
1
,
node
.
tab
do
tabspace
=
tabspace
..
' '
end
if
'table'
==
type
(
node
.
value
)
then
str
=
str
..
string.format
(
'▼ %s :'
,
node
.
name
)
str
=
str
..
string.format
(
'%s▼ %s :\n'
,
tabspace
,
node
.
name
)
else
str
=
str
..
string.format
(
'
● %s : %s'
,
node
.
name
,
tostring
(
node
.
value
))
str
=
str
..
string.format
(
'
%s● %s : %s\n'
,
tabspace
,
node
.
name
,
tostring
(
node
.
value
))
end
end
if
nil
~=
node
.
child
then
for
_
,
child_node
in
pairs
(
node
.
child
)
do
str
=
str
..
this
.
TreeToString
(
child_node
,
str
)
-- 递归
str
=
this
.
TreeToString
(
child_node
,
str
)
end
end
return
str
...
...
Assets/LuaFramework/Lua/View/Tree/TreePanel.lua
浏览文件 @
00e36dc3
...
...
@@ -4,6 +4,7 @@ TreePanel.__index = TreePanel
local
this
=
TreePanel
local
instance
=
nil
this
.
uiNodeTb
=
nil
function
TreePanel
.
Show
()
instance
=
UITool
.
CreatePanelObj
(
instance
,
TreePanel
,
'TreePanel'
,
PANEL_ID
.
TREE_PANEL_ID
,
GlobalObjs
.
s_gamePanel
)
...
...
@@ -16,6 +17,7 @@ end
function
TreePanel
:
OnShow
(
parent
)
local
panelObj
=
UITool
.
Instantiate
(
parent
,
16
)
self
.
panelObj
=
panelObj
this
.
uiNodeTb
=
{}
local
binder
=
panelObj
:
GetComponent
(
"PrefabBinder"
)
self
:
SetUi
(
binder
)
end
...
...
@@ -26,9 +28,10 @@ function TreePanel:SetUi(binder)
self
.
Hide
()
end
)
local
tree
=
TreeLogic
.
GetTree
()
this
.
tiemForClone
=
binder
:
GetObj
(
"itemForClone"
)
LuaUtil
.
SafeActiveObj
(
this
.
tiemForClone
,
false
)
local
tree
=
TreeLogic
.
GetTree
()
this
.
ExpanNode
(
tree
)
end
...
...
@@ -40,60 +43,79 @@ function TreePanel.ExpanNode(node)
end
local
index
=
1
for
_
,
child_node
in
pairs
(
node
.
child
)
do
local
item
=
LuaUtil
.
CloneObj
(
this
.
tiemForClone
)
local
uiUnit
=
{}
if
this
.
uiNodeTb
[
child_node
]
then
-- 从缓存中取ui对象
uiUnit
=
this
.
uiNodeTb
[
child_node
]
-- 显示
LuaUtil
.
SafeActiveObj
(
uiUnit
.
obj
,
true
)
if
child_node
.
isopen
then
-- 递归, 展开子节点
this
.
ExpanNode
(
child_node
)
end
else
-- 创建节点的UI对象
uiUnit
.
obj
=
LuaUtil
.
CloneObj
(
this
.
tiemForClone
)
uiUnit
.
text
=
uiUnit
.
obj
.
transform
:
GetChild
(
0
):
GetComponent
(
"Text"
)
uiUnit
.
btn
=
uiUnit
.
obj
:
GetComponent
(
"Button"
)
-- 坐标缩进
uiUnit
.
text
.
transform
.
localPosition
=
uiUnit
.
text
.
transform
.
localPosition
+
Vector3
.
New
((
child_node
.
tab
-
1
)
*
50
,
0
,
0
)
child_node
.
uiObj
=
uiUnit
.
obj
if
not
LuaUtil
.
IsNilOrNull
(
node
.
uiObj
)
then
-- 子节点塞在父节点下面
local
siblingIndex
=
node
.
uiObj
:
GetComponent
(
"RectTransform"
):
GetSiblingIndex
()
child_node
.
uiObj
:
GetComponent
(
"RectTransform"
):
SetSiblingIndex
(
siblingIndex
+
index
)
index
=
index
+
1
end
uiUnit
.
btn
.
onClick
:
AddListener
(
function
()
local
text
=
item
.
transform
:
GetChild
(
0
):
GetComponent
(
"Text"
)
child_node
.
uiObj
=
item
if
not
child_node
.
isopen
then
child_node
.
isopen
=
true
-- 递归, 展开子节点
this
.
ExpanNode
(
child_node
)
else
-- 关闭子节点
this
.
CloseNode
(
child_node
,
false
)
end
if
not
LuaUtil
.
IsNilOrNull
(
node
.
uiObj
)
then
-- 子节点塞在父节点下面
local
siblingIndex
=
node
.
uiObj
:
GetComponent
(
"RectTransform"
):
GetSiblingIndex
()
child_node
.
uiObj
:
GetComponent
(
"RectTransform"
):
SetSiblingIndex
(
siblingIndex
+
index
)
index
=
index
+
1
if
type
(
child_node
.
value
)
==
'table'
then
uiUnit
.
text
.
text
=
(
child_node
.
isopen
and
'▼ '
or
'► '
)
..
child_node
.
name
end
end
)
this
.
uiNodeTb
[
child_node
]
=
uiUnit
end
-- 更新展开文本
if
type
(
child_node
.
value
)
==
'table'
then
text
.
text
=
(
child_node
.
isopen
and
'▼ '
or
'► '
)
..
child_node
.
name
uiUnit
.
text
.
text
=
(
child_node
.
isopen
and
'▼ '
or
'► '
)
..
child_node
.
name
else
text
.
text
=
'● '
..
child_node
.
name
..
': '
..
child_node
.
value
uiUnit
.
text
.
text
=
'● '
..
child_node
.
name
..
': '
..
child_node
.
value
end
-- 坐标缩进
text
.
transform
.
localPosition
=
text
.
transform
.
localPosition
+
Vector3
.
New
((
child_node
.
tab
-
1
)
*
50
,
0
,
0
)
item
:
GetComponent
(
"Button"
).
onClick
:
AddListener
(
function
()
if
not
child_node
.
isopen
then
child_node
.
isopen
=
true
-- 递归, 展开子节点
this
.
ExpanNode
(
child_node
)
else
-- 关闭子节点
this
.
CloseNode
(
child_node
)
end
if
type
(
child_node
.
value
)
==
'table'
then
text
.
text
=
(
child_node
.
isopen
and
'▼ '
or
'► '
)
..
child_node
.
name
end
end
)
end
end
-- 关闭子节点
function
TreePanel
.
CloseNode
(
node
)
function
TreePanel
.
CloseNode
(
node
,
onlyHide
)
if
LuaUtil
.
IsNilOrNull
(
node
.
child
)
then
return
end
node
.
isopen
=
false
if
not
onlyHide
then
node
.
isopen
=
false
end
for
_
,
child
in
pairs
(
node
.
child
)
do
child
.
isopen
=
false
LuaUtil
.
SafeDestroyObj
(
child
.
uiObj
)
LuaUtil
.
SafeActiveObj
(
child
.
uiObj
,
false
)
if
nil
~=
child
.
child
then
-- 递归关闭子节点
this
.
CloseNode
(
child
)
this
.
CloseNode
(
child
,
true
)
end
end
end
function
TreePanel
:
OnHide
()
LuaUtil
.
SafeDestroyObj
(
self
.
panelObj
)
this
.
uiNodeTb
=
nil
instance
=
nil
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录