大幅提高编辑状态时的性能

1.大幅提高编辑状态时的性能
2.更方便记录自定义组件
This commit is contained in:
cheney2013 2023-06-06 14:17:42 +08:00
parent 964befe06e
commit 09f8c3b46b
6 changed files with 762 additions and 228 deletions

View File

@ -180,7 +180,7 @@
"_priority": 0, "_priority": 0,
"_fov": 45, "_fov": 45,
"_fovAxis": 0, "_fovAxis": 0,
"_orthoHeight": 592.3774954627949, "_orthoHeight": 813.9650872817955,
"_near": 0, "_near": 0,
"_far": 1000, "_far": 1000,
"_color": { "_color": {
@ -292,8 +292,8 @@
"__type__": "cc.Quat", "__type__": "cc.Quat",
"x": 0, "x": 0,
"y": 0, "y": 0,
"z": -0.09771317388476722, "z": 0,
"w": 0.995214617883683 "w": 1
}, },
"_lscale": { "_lscale": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
@ -307,7 +307,7 @@
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 0, "y": 0,
"z": -11.215 "z": 0
}, },
"_id": "b5DhQMg8ZDBYEyXztSbxBs" "_id": "b5DhQMg8ZDBYEyXztSbxBs"
}, },
@ -322,7 +322,7 @@
"__prefab": null, "__prefab": null,
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 240, "width": 210,
"height": 50.4 "height": 50.4
}, },
"_anchorPoint": { "_anchorPoint": {
@ -342,10 +342,10 @@
"_enabled": true, "_enabled": true,
"__prefab": null, "__prefab": null,
"_lineHeight": 40, "_lineHeight": 40,
"_string": "<color=#ff0000>五</color><color=#00ff00>彩</color><color=#0000ff>斑</color><color=#f700f5>斓</color><color=#f6f600>的</color><color=#0fffff>黑</color>", "_string": "我是外层的背景",
"_horizontalAlign": 0, "_horizontalAlign": 0,
"_verticalAlign": 0, "_verticalAlign": 0,
"_fontSize": 40, "_fontSize": 30,
"_maxWidth": 0, "_maxWidth": 0,
"_fontFamily": "Arial", "_fontFamily": "Arial",
"_font": null, "_font": null,
@ -543,7 +543,7 @@
"__id__": 14 "__id__": 14
} }
], ],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 17 "__id__": 17
@ -639,7 +639,7 @@
"node": { "node": {
"__id__": 14 "__id__": 14
}, },
"_enabled": true, "_enabled": false,
"__prefab": null, "__prefab": null,
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
@ -660,7 +660,7 @@
"node": { "node": {
"__id__": 14 "__id__": 14
}, },
"_enabled": true, "_enabled": false,
"__prefab": null, "__prefab": null,
"_customMaterial": null, "_customMaterial": null,
"_srcBlendFactor": 2, "_srcBlendFactor": 2,
@ -776,7 +776,7 @@
"__id__": 9 "__id__": 9
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 21 "__id__": 21
@ -882,7 +882,7 @@
"__id__": 9 "__id__": 9
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 24 "__id__": 24
@ -988,7 +988,7 @@
"__id__": 9 "__id__": 9
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 27 "__id__": 27
@ -1094,7 +1094,7 @@
"__id__": 9 "__id__": 9
}, },
"_children": [], "_children": [],
"_active": false, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 30 "__id__": 30
@ -1264,7 +1264,7 @@
"levelUp", "levelUp",
"fullLevel" "fullLevel"
], ],
"_state": 0, "_state": 1,
"_records": { "_records": {
"0": [ "0": [
{ {
@ -1277,14 +1277,14 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"width": 120, "width": 120,
"height": 50.4, "height": 50.4,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5,
"enabled": true "enabled": true
}, },
"Label": { "cc.Label": {
"color": "329646", "color": "329646",
"string": "已满级", "string": "已满级",
"horizontalAlign": 1, "horizontalAlign": 1,
@ -1307,14 +1307,14 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"width": 300, "width": 300,
"height": 15, "height": 15,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5,
"enabled": true "enabled": true
}, },
"Sprite": { "cc.Sprite": {
"color": "ffffff", "color": "ffffff",
"spriteFrame": "9fd900dd-221b-4f89-8f2c-fba34243c835@f9941", "spriteFrame": "9fd900dd-221b-4f89-8f2c-fba34243c835@f9941",
"grayscale": false, "grayscale": false,
@ -1334,14 +1334,14 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"width": 31.12, "width": 31.12,
"height": 50.4, "height": 50.4,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5,
"enabled": true "enabled": true
}, },
"Label": { "cc.Label": {
"color": "000000", "color": "000000",
"string": "1级", "string": "1级",
"horizontalAlign": 1, "horizontalAlign": 1,
@ -1367,14 +1367,14 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"width": 62, "width": 62,
"height": 34, "height": 34,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5,
"enabled": true "enabled": true
}, },
"Sprite": { "cc.Sprite": {
"color": "ffffff", "color": "ffffff",
"spriteFrame": "88b7887e-b33d-40bb-9eb0-76fd4b99feca@f9941", "spriteFrame": "88b7887e-b33d-40bb-9eb0-76fd4b99feca@f9941",
"grayscale": false, "grayscale": false,
@ -1394,14 +1394,14 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"width": 31.12, "width": 31.12,
"height": 50.4, "height": 50.4,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5,
"enabled": true "enabled": true
}, },
"Label": { "cc.Label": {
"color": "000000", "color": "000000",
"string": "2级", "string": "2级",
"horizontalAlign": 1, "horizontalAlign": 1,
@ -1419,6 +1419,61 @@
"node": { "node": {
"__id__": 26 "__id__": 26
} }
},
{
"node": {
"__id__": 9
},
"active": true,
"x": 0,
"y": -68.485,
"angle": 0,
"scaleX": 1,
"scaleY": 1
},
{
"node": {
"__id__": 10
},
"active": true,
"x": -214.096,
"y": 133.719,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"cc.UITransform": {
"enabled": true,
"width": 120,
"height": 50.4,
"anchorX": 0.5,
"anchorY": 0.5
},
"cc.Label": {
"enabled": true,
"color": "000000",
"string": "我是内层的框",
"horizontalAlign": 1,
"verticalAlign": 1,
"fontSize": 20,
"fontFamily": "Arial",
"lineHeight": 40,
"overflow": 0,
"isBold": false,
"isItalic": false,
"isUnderline": false,
"underlineHeight": 2
}
},
{
"node": {
"__id__": 14
},
"active": true,
"x": -150,
"y": 0,
"angle": 0,
"scaleX": 1,
"scaleY": 1
} }
], ],
"1": [ "1": [
@ -1429,14 +1484,15 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"enabled": true,
"width": 120, "width": 120,
"height": 50.4, "height": 50.4,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5
"enabled": true
}, },
"Label": { "cc.Label": {
"enabled": true,
"color": "329646", "color": "329646",
"string": "已满级", "string": "已满级",
"horizontalAlign": 1, "horizontalAlign": 1,
@ -1448,8 +1504,7 @@
"isBold": false, "isBold": false,
"isItalic": false, "isItalic": false,
"isUnderline": false, "isUnderline": false,
"underlineHeight": 2, "underlineHeight": 2
"enabled": true
}, },
"node": { "node": {
"__id__": 29 "__id__": 29
@ -1465,21 +1520,21 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"enabled": true,
"width": 300, "width": 300,
"height": 15, "height": 15,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5
"enabled": true
}, },
"Sprite": { "cc.Sprite": {
"enabled": true,
"color": "ffffff", "color": "ffffff",
"spriteFrame": "9fd900dd-221b-4f89-8f2c-fba34243c835@f9941", "spriteFrame": "9fd900dd-221b-4f89-8f2c-fba34243c835@f9941",
"grayscale": false, "grayscale": false,
"sizeMode": 0, "sizeMode": 0,
"type": 1, "type": 1,
"trim": true, "trim": true
"enabled": true
} }
}, },
{ {
@ -1492,14 +1547,15 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"enabled": true,
"width": 31.12, "width": 31.12,
"height": 50.4, "height": 50.4,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5
"enabled": true
}, },
"Label": { "cc.Label": {
"enabled": true,
"color": "000000", "color": "000000",
"string": "1级", "string": "1级",
"horizontalAlign": 1, "horizontalAlign": 1,
@ -1511,8 +1567,7 @@
"isBold": false, "isBold": false,
"isItalic": false, "isItalic": false,
"isUnderline": false, "isUnderline": false,
"underlineHeight": 2, "underlineHeight": 2
"enabled": true
} }
}, },
{ {
@ -1525,21 +1580,21 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"enabled": true,
"width": 62, "width": 62,
"height": 34, "height": 34,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5
"enabled": true
}, },
"Sprite": { "cc.Sprite": {
"enabled": true,
"color": "ffffff", "color": "ffffff",
"spriteFrame": "88b7887e-b33d-40bb-9eb0-76fd4b99feca@f9941", "spriteFrame": "88b7887e-b33d-40bb-9eb0-76fd4b99feca@f9941",
"grayscale": false, "grayscale": false,
"sizeMode": 1, "sizeMode": 1,
"type": 0, "type": 0,
"trim": true, "trim": true
"enabled": true
} }
}, },
{ {
@ -1552,14 +1607,15 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"enabled": true,
"width": 31.12, "width": 31.12,
"height": 50.4, "height": 50.4,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5
"enabled": true
}, },
"Label": { "cc.Label": {
"enabled": true,
"color": "000000", "color": "000000",
"string": "2级", "string": "2级",
"horizontalAlign": 1, "horizontalAlign": 1,
@ -1571,8 +1627,62 @@
"isBold": false, "isBold": false,
"isItalic": false, "isItalic": false,
"isUnderline": false, "isUnderline": false,
"underlineHeight": 2, "underlineHeight": 2
"enabled": true }
},
{
"active": true,
"x": 0,
"y": -68.485,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"node": {
"__id__": 9
}
},
{
"active": true,
"x": -214.096,
"y": 133.719,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"node": {
"__id__": 10
},
"cc.UITransform": {
"enabled": true,
"width": 120,
"height": 50.4,
"anchorX": 0.5,
"anchorY": 0.5
},
"cc.Label": {
"enabled": true,
"color": "000000",
"string": "我是内层的框",
"horizontalAlign": 1,
"verticalAlign": 1,
"fontSize": 20,
"fontFamily": "Arial",
"lineHeight": 40,
"overflow": 0,
"isBold": false,
"isItalic": false,
"isUnderline": false,
"underlineHeight": 2
}
},
{
"active": true,
"x": -150,
"y": 0,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"node": {
"__id__": 14
} }
} }
] ]
@ -1694,7 +1804,7 @@
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
"_name": "Label", "_name": "cccLabel",
"_objFlags": 512, "_objFlags": 512,
"_parent": { "_parent": {
"__id__": 37 "__id__": 37
@ -1750,7 +1860,7 @@
"__prefab": null, "__prefab": null,
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 160, "width": 171.12,
"height": 50.4 "height": 50.4
}, },
"_anchorPoint": { "_anchorPoint": {
@ -1761,7 +1871,7 @@
"_id": "580tLaJFRPaYhXLsOp/Nxz" "_id": "580tLaJFRPaYhXLsOp/Nxz"
}, },
{ {
"__type__": "cc.Label", "__type__": "8154aeTa6xKYo/6cBryQ/EG",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
@ -1779,7 +1889,7 @@
"b": 255, "b": 255,
"a": 255 "a": 255
}, },
"_string": "点我切换外层状态", "_string": "点我切换外层状态2",
"_horizontalAlign": 1, "_horizontalAlign": 1,
"_verticalAlign": 1, "_verticalAlign": 1,
"_actualFontSize": 20, "_actualFontSize": 20,
@ -1787,7 +1897,7 @@
"_fontFamily": "Arial", "_fontFamily": "Arial",
"_lineHeight": 40, "_lineHeight": 40,
"_overflow": 0, "_overflow": 0,
"_enableWrapText": false, "_enableWrapText": true,
"_font": null, "_font": null,
"_isSystemFontUsed": true, "_isSystemFontUsed": true,
"_spacingX": 0, "_spacingX": 0,
@ -1796,7 +1906,8 @@
"_isUnderline": false, "_isUnderline": false,
"_underlineHeight": 2, "_underlineHeight": 2,
"_cacheMode": 0, "_cacheMode": 0,
"_id": "2dStRy2CdOfKSDyimgKLmU" "customProp": "test2",
"_id": "c33L+0hhFOfZC6VvYXFguE"
}, },
{ {
"__type__": "cc.UITransform", "__type__": "cc.UITransform",
@ -2285,6 +2396,40 @@
"_state": 1, "_state": 1,
"_records": { "_records": {
"0": [ "0": [
{
"active": true,
"x": 0,
"y": 3,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"cc.UITransform": {
"enabled": true,
"width": 171.12,
"height": 50.4,
"anchorX": 0.5,
"anchorY": 0.5
},
"node": {
"__id__": 38
},
"CustomLabel": {
"enabled": true,
"customProp": "test1",
"color": "ffffff",
"string": "点我切换外层状态1",
"horizontalAlign": 1,
"verticalAlign": 1,
"fontSize": 20,
"fontFamily": "Arial",
"lineHeight": 40,
"overflow": 0,
"isBold": false,
"isItalic": false,
"isUnderline": false,
"underlineHeight": 2
}
},
{ {
"active": true, "active": true,
"x": 0, "x": 0,
@ -2292,56 +2437,62 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"enabled": true,
"width": 720, "width": 720,
"height": 1560, "height": 1560,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5
"enabled": true
}, },
"Sprite": { "cc.Sprite": {
"enabled": true,
"color": "ffffff", "color": "ffffff",
"spriteFrame": "475bdcef-71c8-422c-9ac0-76197650e12b@f9941", "spriteFrame": "475bdcef-71c8-422c-9ac0-76197650e12b@f9941",
"grayscale": false, "grayscale": false,
"sizeMode": 1, "sizeMode": 1,
"type": 0, "type": 0,
"trim": true, "trim": true
"enabled": true
}, },
"node": { "node": {
"__id__": 5 "__id__": 5
} }
},
{
"active": true,
"x": 0,
"y": 382.95,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"UITransform": {
"width": 210,
"height": 50.4,
"anchorX": 0.5,
"anchorY": 0.5,
"enabled": true
},
"RichText": {
"string": "我是外层的背景",
"horizontalAlign": 0,
"verticalAlign": 0,
"fontSize": 30,
"fontFamily": "Arial",
"maxWidth": 0,
"lineHeight": 40,
"enabled": true
},
"node": {
"__id__": 6
}
} }
], ],
"1": [ "1": [
{
"active": true,
"x": 0,
"y": 3,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"cc.UITransform": {
"enabled": true,
"width": 171.12,
"height": 50.4,
"anchorX": 0.5,
"anchorY": 0.5
},
"node": {
"__id__": 38
},
"CustomLabel": {
"enabled": true,
"customProp": "test2",
"color": "ffffff",
"string": "点我切换外层状态2",
"horizontalAlign": 1,
"verticalAlign": 1,
"fontSize": 20,
"fontFamily": "Arial",
"lineHeight": 40,
"overflow": 0,
"isBold": false,
"isItalic": false,
"isUnderline": false,
"underlineHeight": 2
}
},
{ {
"node": { "node": {
"__id__": 5 "__id__": 5
@ -2352,49 +2503,21 @@
"angle": 0, "angle": 0,
"scaleX": 1, "scaleX": 1,
"scaleY": 1, "scaleY": 1,
"UITransform": { "cc.UITransform": {
"enabled": true,
"width": 720, "width": 720,
"height": 1560, "height": 1560,
"anchorX": 0.5, "anchorX": 0.5,
"anchorY": 0.5, "anchorY": 0.5
"enabled": true
}, },
"Sprite": { "cc.Sprite": {
"enabled": true,
"color": "ffffff", "color": "ffffff",
"spriteFrame": "bde4de98-18d7-47fa-ae16-b5c0651b5ab3@f9941", "spriteFrame": "bde4de98-18d7-47fa-ae16-b5c0651b5ab3@f9941",
"grayscale": false, "grayscale": false,
"sizeMode": 1, "sizeMode": 1,
"type": 0, "type": 0,
"trim": true, "trim": true
"enabled": true
}
},
{
"node": {
"__id__": 6
},
"active": true,
"x": 0,
"y": 382.95,
"angle": 0,
"scaleX": 1,
"scaleY": 1,
"UITransform": {
"width": 180,
"height": 50.4,
"anchorX": 0.5,
"anchorY": 0.5,
"enabled": true
},
"RichText": {
"string": "<color=#ff0000>五</color><color=#00ff00>彩</color><color=#0000ff>斑</color><color=#f700f5>斓</color><color=#f6f600>的</color><color=#0fffff>黑</color>",
"horizontalAlign": 0,
"verticalAlign": 0,
"fontSize": 30,
"fontFamily": "Arial",
"maxWidth": 0,
"lineHeight": 40,
"enabled": true
} }
} }
] ]

370
assets/scene/scene-2d.scene Normal file
View File

@ -0,0 +1,370 @@
[
{
"__type__": "cc.SceneAsset",
"_name": "scene-2d",
"_objFlags": 0,
"_native": "",
"scene": {
"__id__": 1
}
},
{
"__type__": "cc.Scene",
"_name": "scene-2d",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [],
"_prefab": null,
"autoReleaseAssets": false,
"_globals": {
"__id__": 8
},
"_id": "c77ecaa8-c936-46c4-a5b0-98692673ed87"
},
{
"__type__": "cc.Node",
"_name": "Canvas",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
}
],
"_active": true,
"_components": [
{
"__id__": 5
},
{
"__id__": 6
},
{
"__id__": 7
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 480,
"y": 320.00000000000006,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "beI88Z2HpFELqR4T5EMHpg"
},
{
"__type__": "cc.Node",
"_name": "Camera",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 1073741824,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "ebFwiq8gBFaYpqYbdoDODe"
},
{
"__type__": "cc.Camera",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
},
"_enabled": true,
"__prefab": null,
"_projection": 0,
"_priority": 0,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 10,
"_near": 0,
"_far": 1000,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_depth": 1,
"_stencil": 0,
"_clearFlags": 7,
"_rect": {
"__type__": "cc.Rect",
"x": 0,
"y": 0,
"width": 1,
"height": 1
},
"_aperture": 19,
"_shutter": 7,
"_iso": 0,
"_screenScale": 1,
"_visibility": 1108344832,
"_targetTexture": null,
"_id": "63WIch3o5BEYRlXzTT0oWc"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 960,
"height": 640
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "d6rUX5yfhMlKoWX2bSbawx"
},
{
"__type__": "cc.Canvas",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_cameraComponent": {
"__id__": 4
},
"_alignCanvasWithScreen": true,
"_id": "12O/ljcVlEqLmVm3U2gEOQ"
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 45,
"_target": null,
"_left": 0,
"_right": 0,
"_top": 5.684341886080802e-14,
"_bottom": 5.684341886080802e-14,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 0,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "c5V1EV8IpMtrIvY1OE9t2u"
},
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 9
},
"shadows": {
"__id__": 10
},
"_skybox": {
"__id__": 11
},
"fog": {
"__id__": 12
},
"octree": {
"__id__": 13
}
},
{
"__type__": "cc.AmbientInfo",
"_skyColorHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyColor": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0.520833125
},
"_skyIllumHDR": 20000,
"_skyIllum": 20000,
"_groundAlbedoHDR": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_groundAlbedo": {
"__type__": "cc.Vec4",
"x": 0,
"y": 0,
"z": 0,
"w": 0
},
"_skyColorLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.5,
"z": 0.8,
"w": 1
},
"_skyIllumLDR": 20000,
"_groundAlbedoLDR": {
"__type__": "cc.Vec4",
"x": 0.2,
"y": 0.2,
"z": 0.2,
"w": 1
}
},
{
"__type__": "cc.ShadowsInfo",
"_enabled": false,
"_type": 0,
"_normal": {
"__type__": "cc.Vec3",
"x": 0,
"y": 1,
"z": 0
},
"_distance": 0,
"_shadowColor": {
"__type__": "cc.Color",
"r": 76,
"g": 76,
"b": 76,
"a": 255
},
"_maxReceived": 4,
"_size": {
"__type__": "cc.Vec2",
"x": 512,
"y": 512
}
},
{
"__type__": "cc.SkyboxInfo",
"_envLightingType": 0,
"_envmapHDR": null,
"_envmap": null,
"_envmapLDR": null,
"_diffuseMapHDR": null,
"_diffuseMapLDR": null,
"_enabled": false,
"_useHDR": true
},
{
"__type__": "cc.FogInfo",
"_type": 0,
"_fogColor": {
"__type__": "cc.Color",
"r": 200,
"g": 200,
"b": 200,
"a": 255
},
"_enabled": false,
"_fogDensity": 0.3,
"_fogStart": 0.5,
"_fogEnd": 300,
"_fogAtten": 5,
"_fogTop": 1.5,
"_fogRange": 1.2,
"_accurate": false
},
{
"__type__": "cc.OctreeInfo",
"_enabled": false,
"_minPos": {
"__type__": "cc.Vec3",
"x": -1024,
"y": -1024,
"z": -1024
},
"_maxPos": {
"__type__": "cc.Vec3",
"x": 1024,
"y": 1024,
"z": 1024
},
"_depth": 8
}
]

View File

@ -0,0 +1,11 @@
{
"ver": "1.1.43",
"importer": "scene",
"imported": true,
"uuid": "baf162cd-abd4-45af-982a-9891aff69e7a",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@ -0,0 +1,9 @@
import { Label, _decorator } from "cc";
const { ccclass, property } = _decorator;
@ccclass
export class CustomLabel extends Label{
@property
customProp:string = "test";
}

View File

@ -0,0 +1,9 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "8154a793-6bac-4a62-8ffa-701af243f106",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@ -14,7 +14,7 @@ import {
Enum, Enum,
Label, Label,
Node, Node,
RichText, Sprite, SpriteFrame, UIRenderer, RichText, Sprite, SpriteFrame,
Widget, Widget,
_decorator, assetManager _decorator, assetManager
} from "cc"; } from "cc";
@ -30,15 +30,15 @@ enum States {
* *
*/ */
const COMP_ATTR_RECORD = <const>{ const COMP_ATTR_RECORD = <const>{
"UITransform": ["width", "height", "anchorX", "anchorY"], "cc.UITransform": ["width", "height", "anchorX", "anchorY"],
"Widget": ["isAlignBottom", "isAlignTop", "isAlignLeft", "isAlignRight", "isAlignVerticalCenter", "isAlignHorizontalCenter", "cc.Widget": ["isAlignBottom", "isAlignTop", "isAlignLeft", "isAlignRight", "isAlignVerticalCenter", "isAlignHorizontalCenter",
"isAbsoluteTop", "isAbsoluteBottom", "isAbsoluteLeft", "isAbsoluteRight", "isAbsoluteHorizontalCenter", "isAbsoluteVerticalCenter", "isAbsoluteTop", "isAbsoluteBottom", "isAbsoluteLeft", "isAbsoluteRight", "isAbsoluteHorizontalCenter", "isAbsoluteVerticalCenter",
"left", "right", "top", "bottom", "horizontalCenter", "verticalCenter", "alignMode", "alignFlags"], "left", "right", "top", "bottom", "horizontalCenter", "verticalCenter", "alignMode", "alignFlags"],
"UIOpacity": ["opacity"], "cc.UIOpacity": ["opacity"],
"UIRenderer": ["color"], "cc.Label": ["color", "string", "horizontalAlign", "verticalAlign", "fontSize", "fontFamily", "lineHeight", "overflow", "isBold", "isItalic", "isUnderline", "underlineHeight"],
"Label": ["color", "string", "horizontalAlign", "verticalAlign", "fontSize", "fontFamily", "lineHeight", "overflow", "isBold", "isItalic", "isUnderline", "underlineHeight"], "cc.RichText": ["string", "horizontalAlign", "verticalAlign", "fontSize", "fontFamily", "maxWidth", "lineHeight"],
"RichText": ["string", "horizontalAlign", "verticalAlign", "fontSize", "fontFamily", "maxWidth", "lineHeight"], "cc.Sprite": ["color", "spriteFrame", "grayscale", "sizeMode", "type", "trim"],
"Sprite": ["color", "spriteFrame", "grayscale", "sizeMode", "type", "trim"] "CustomLabel": ["customProp"]
} }
type KEY_OF_COMP_ATTR_RECORD = keyof typeof COMP_ATTR_RECORD; type KEY_OF_COMP_ATTR_RECORD = keyof typeof COMP_ATTR_RECORD;
@ -124,7 +124,6 @@ export default class UIState extends Component {
if (REAL_EDITOR) { if (REAL_EDITOR) {
this.walkNode(this.node, child => { this.walkNode(this.node, child => {
this.recordBeforeStateChange(child); this.recordBeforeStateChange(child);
// this.removeListener(child);
}); });
} }
@ -202,11 +201,6 @@ export default class UIState extends Component {
CCClass.Attr.setClassAttr(this, "state", "enumList", enumList); CCClass.Attr.setClassAttr(this, "state", "enumList", enumList);
} }
onDestroy() {
if (REAL_EDITOR) this.saveCurrentState();
}
/** /**
* *
*/ */
@ -246,60 +240,50 @@ export default class UIState extends Component {
} }
if (node === this.node) continue; if (node === this.node) continue;
node.active = record.active!;
node.angle = record.angle; node.angle = record.angle;
node.setScale(record.scaleX, record.scaleY); node.setScale(record.scaleX, record.scaleY);
// 在编辑器模式下设置属性会有额外的操作,比如很多组件的属性都会影响 Widget 的属性 node.components.forEach(comp=>{
// 为了避免异常,先从节点树移除 const compName = (comp as any).__proto__.__classname__ as keyof KEY_OF_COMP_ATTR_RECORD;
let temp:Node; const recordCompAttr = record[compName as keyof RecordProps];
let tempSiblingIndex:number;
if (REAL_EDITOR){ if (!recordCompAttr) return;
tempSiblingIndex = node.getSiblingIndex();
temp = node.parent; const registerComps = this.getNeedRecordComps(comp);
node.parent = null;
} if (!registerComps.length) return;
Object.keys(COMP_ATTR_RECORD).forEach(compName=>{
const comp = node.getComponent(`cc.${compName}`); registerComps.forEach(compName=>{
if (comp){ let compAttrs:string[] = COMP_ATTR_RECORD[compName];
const recordCompAttr = record[compName as keyof RecordProps]; switch(compName){
if (recordCompAttr) { case "cc.Label":
switch(compName){ Object.values(compAttrs).forEach(attr => {
case "Label": this.applyLabelAttr(attr, comp as Label, recordCompAttr);
Object.keys(recordCompAttr).forEach(attr => { });
this.applyLabelAttr(attr, comp as Label, recordCompAttr); break;
}); case "cc.Sprite":
break; Object.values(compAttrs).forEach(attr => {
case "Sprite": this.applySpriteAttr(attr, comp as Sprite, recordCompAttr);
Object.keys(recordCompAttr).forEach(attr => { });
this.applySpriteAttr(attr, comp as Sprite, recordCompAttr); break;
}); default:
break; Object.values(compAttrs).forEach(attr => {
case "UIRenderer": comp[attr] = recordCompAttr[attr];
Object.keys(recordCompAttr).forEach(attr => { });
this.applyUIRendererAttr(attr, comp as UIRenderer, recordCompAttr); break;
});
break;
case "Widget":
Object.assign(comp, recordCompAttr);
break;
default:
Object.assign(comp, recordCompAttr);
break;
}
} }
} });
if (record[(comp as any).__proto__.__classname__])
comp.enabled = record[(comp as any).__proto__.__classname__].enabled;
}); });
if (REAL_EDITOR){ node.active = record.active!;
temp.insertChild(node, tempSiblingIndex);
}
// 应用组件启用状态 // 应用组件启用状态
node.components.forEach((comp, index) => { node.components.forEach((comp, index) => {
const compName = (comp as any).__proto__.constructor.name as keyof RecordProps; const compName = (comp as any).__proto__.__classname__ as keyof RecordProps;
const recordCompAttr = record[compName]; const recordCompAttr = record[compName];
// 没有记录且没在 COMP_ATTR_RECORD 中表明是在其他状态新增的组件,那么在当前状态就需要禁用 // 没有记录且没在 COMP_ATTR_RECORD 中表明是在其他状态新增的组件,那么在当前状态就需要禁用
if(!recordCompAttr && COMP_ATTR_RECORD[compName as KEY_OF_COMP_ATTR_RECORD]){ if(!recordCompAttr && this.isNeedRecordComp(comp)){
comp.enabled = false; comp.enabled = false;
} }
}); });
@ -341,31 +325,38 @@ export default class UIState extends Component {
// 记录组件启用状态 // 记录组件启用状态
node.components.forEach(comp => { node.components.forEach(comp => {
const compName = (comp as any).__proto__.constructor.name as KEY_OF_COMP_ATTR_RECORD; const registerComps = this.getNeedRecordComps(comp);
if (COMP_ATTR_RECORD[compName]){ let recordCompAttr:any;
const compAttrs = COMP_ATTR_RECORD[compName].slice(); if (!registerComps.length)
// 记录组件的 enabled return;
compAttrs.push("enabled" as never);
const recordCompAttr:any = {}; recordCompAttr = {
record![compName] = recordCompAttr; enabled: comp.enabled
switch(compName){ };
case "Label": record[(comp as any).__proto__.__classname__] = recordCompAttr;
compAttrs.forEach(attr => {
this.recordLabelAttr(attr, comp as Label, recordCompAttr); registerComps.forEach(compName=>{
}); let compAttrs = COMP_ATTR_RECORD[compName];
break; if (compAttrs){
case "Sprite": switch(compName){
compAttrs.forEach(attr => { case "cc.Label":
this.recordSpriteAttr(attr, comp as Sprite, recordCompAttr); compAttrs.forEach(attr => {
}); this.recordLabelAttr(attr, comp as Label, recordCompAttr);
break; });
default: break;
compAttrs.forEach(attr => { case "cc.Sprite":
recordCompAttr[attr] = comp[attr as keyof typeof comp]; compAttrs.forEach(attr => {
}); this.recordSpriteAttr(attr, comp as Sprite, recordCompAttr);
break; });
break;
default:
compAttrs.forEach(attr => {
recordCompAttr[attr] = comp[attr as keyof typeof comp];
});
break;
}
} }
} });
}); });
return record; return record;
@ -440,18 +431,6 @@ export default class UIState extends Component {
} }
} }
private applyUIRendererAttr(attr:string, comp:UIRenderer, recordCompAttr:any){
switch(attr){
case "color":
comp.color.fromHEX(recordCompAttr[attr]);
(comp as any)["_updateColor"]();
break;
default:
(comp as any)[attr] = recordCompAttr[attr];
break;
}
}
/** /**
* *
* *
@ -472,7 +451,7 @@ export default class UIState extends Component {
let record = this._uuidRecordMap?.get(node.uuid); let record = this._uuidRecordMap?.get(node.uuid);
// 清理已经删除的组件 // 清理已经删除的组件
Object.keys(COMP_ATTR_RECORD).some(compName=>{ Object.keys(COMP_ATTR_RECORD).some(compName=>{
if (node.getComponent(`cc.${compName}`)) return false; if (node.getComponent(compName)) return false;
if (defaultNodeState[compName as keyof RecordProps]){ if (defaultNodeState[compName as keyof RecordProps]){
isModify = true; isModify = true;
@ -499,12 +478,10 @@ export default class UIState extends Component {
if (!isModify) if (!isModify)
// 检查节点是否有增加或修改 // 检查节点是否有增加或修改
isModify = node.components.some(component =>{ isModify = node.components.some(component =>{
const compName = (component as any).__proto__.constructor.name as keyof RecordProps;
// 不在 COMP_ATTR_RECORD 里的组件不记录 // 不在 COMP_ATTR_RECORD 里的组件不记录
if (!COMP_ATTR_RECORD[compName as KEY_OF_COMP_ATTR_RECORD]) if (!this.isNeedRecordComp(component)) return false;
return false;
const compName = (component as any).__proto__.__classname__ as keyof RecordProps;
// 新增的组件 // 新增的组件
if (!defaultNodeState[compName]) if (!defaultNodeState[compName])
return true; return true;
@ -542,6 +519,41 @@ export default class UIState extends Component {
} }
} }
/**
* COMP_ATTR_RECORD
* @param component
* @returns
*/
private isNeedRecordComp(component: Component): boolean{
let isRegister = false;
let compProto = (component as any).__proto__;
while(compProto){
const compName = compProto.__classname__ as keyof KEY_OF_COMP_ATTR_RECORD;
if (COMP_ATTR_RECORD[compName]){
isRegister = true;
break;
}
compProto = compProto.__proto__;
}
return isRegister;
}
/**
*
* @param component
* @returns
*/
private getNeedRecordComps(component:Component):string[]{
const ret = [];
let compProto = (component as any).__proto__;
while(compProto){
const compName = compProto.__classname__ as keyof KEY_OF_COMP_ATTR_RECORD;
if (COMP_ATTR_RECORD[compName]) ret.push(compName);
compProto = compProto.__proto__;
}
return ret;
}
/** /**
* UIState的子节点 * UIState的子节点
* @param node * @param node