Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
unit_demo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
unit_demo
Commits
5a8a6069
Commit
5a8a6069
authored
Sep 28, 2021
by
huoshizhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 页面跳转逻辑
parent
9885859f
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
66 additions
and
98 deletions
+66
-98
ButtonsNode.js
play/assets/unit_demo/resources/prefabs/ButtonsNode.js
+16
-36
ButtonsNode.prefab
play/assets/unit_demo/resources/prefabs/ButtonsNode.prefab
+2
-5
demo_01_showFireworks.fire
play/assets/unit_demo/scene/demo_01_showFireworks.fire
+0
-1
demo_02_scoreStars.fire
play/assets/unit_demo/scene/demo_02_scoreStars.fire
+12
-14
demo_03_fireworks_2.fire
play/assets/unit_demo/scene/demo_03_fireworks_2.fire
+8
-10
demo_04_playAudio.fire
play/assets/unit_demo/scene/demo_04_playAudio.fire
+8
-8
demo_05_alphaClick.fire
play/assets/unit_demo/scene/demo_05_alphaClick.fire
+8
-9
unit_demo.fire
play/assets/unit_demo/scene/unit_demo.fire
+5
-5
unit_demo.js
play/assets/unit_demo/scene/unit_demo.js
+7
-10
No files found.
play/assets/unit_demo/resources/prefabs/ButtonsNode.js
View file @
5a8a6069
// Learn cc.Class:
// - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
cc
.
Class
({
extends
:
cc
.
Component
,
...
...
@@ -29,51 +22,38 @@ cc.Class({
BtnPrevious
.
active
=
true
;
if
(
!
this
.
_dataList
[
this
.
_currentIdx
+
1
])
{
console
.
log
(
'
汪汪汪
'
)
BtnNext
.
active
=
false
;
}
if
(
!
this
.
_dataList
[
this
.
_currentIdx
-
1
])
{
console
.
log
(
'
喵喵喵
'
)
BtnPrevious
.
active
=
false
;
}
cc
.
resources
.
load
(
'
prefabs/ButtonsNode
'
,
cc
.
Prefab
,
(
err
,
ButtonsNode
)
=>
{
const
dataList
=
this
.
_dataList
;
const
currentIdx
=
this
.
_currentIdx
;
BtnNext
.
on
(
'
click
'
,
()
=>
{
let
demoItem
=
this
.
_dataList
[
this
.
_currentIdx
+
1
];
cc
.
director
.
loadScene
(
demoItem
.
sceneName
,
()
=>
{
const
newButtonNode
=
cc
.
instantiate
(
ButtonsNode
);
newButtonNode
.
parent
=
cc
.
find
(
'
Canvas
'
);
newButtonNode
.
x
=
0
;
newButtonNode
.
y
=
0
;
newButtonNode
.
getComponent
(
'
ButtonsNode
'
).
setDataList
(
dataList
,
currentIdx
+
1
);
this
.
node
.
getComponent
(
'
ButtonsNode
'
).
setDataList
(
this
.
_dataList
,
this
.
_currentIdx
+
1
);
});
});
BtnPrevious
.
on
(
'
click
'
,
()
=>
{
let
demoItem
=
this
.
_dataList
[
this
.
_currentIdx
-
1
];
cc
.
director
.
loadScene
(
demoItem
.
sceneName
,
()
=>
{
const
newButtonNode
=
cc
.
instantiate
(
ButtonsNode
);
newButtonNode
.
parent
=
cc
.
find
(
'
Canvas
'
);
newButtonNode
.
x
=
0
;
newButtonNode
.
y
=
0
;
newButtonNode
.
getComponent
(
'
ButtonsNode
'
).
setDataList
(
dataList
,
currentIdx
-
1
);
this
.
node
.
getComponent
(
'
ButtonsNode
'
).
setDataList
(
this
.
_dataList
,
this
.
_currentIdx
-
1
);
});
});
BtnBack
.
on
(
'
click
'
,
()
=>
{
cc
.
game
.
removePersistRootNode
(
this
.
node
);
this
.
node
.
active
=
false
;
cc
.
director
.
loadScene
(
'
unit_demo
'
);
});
});
},
setDataList
(
dataList
,
currentIdx
)
{
console
.
log
(
'
dataList =
'
+
JSON
.
stringify
(
dataList
));
console
.
log
(
'
currentIdx =
'
+
JSON
.
stringify
(
currentIdx
));
this
.
_dataList
=
dataList
;
this
.
_currentIdx
=
currentIdx
;
this
.
initListeners
();
},
// update (dt) {},
});
play/assets/unit_demo/resources/prefabs/ButtonsNode.prefab
View file @
5a8a6069
...
...
@@ -307,7 +307,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "NEXT --->",
"_N$string": "NEXT --->",
"_fontSize": 20,
...
...
@@ -748,7 +747,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "<---PREVIOUS",
"_N$string": "<---PREVIOUS",
"_fontSize": 20,
...
...
@@ -1189,7 +1187,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "back",
"_N$string": "back",
"_fontSize": 20,
...
...
@@ -1417,7 +1414,7 @@
"__id__": 1
},
"_children": [],
"_active":
fals
e,
"_active":
tru
e,
"_components": [
{
"__id__": 36
...
...
@@ -1534,7 +1531,7 @@
"asset": {
"__uuid__": "ffa620db-880d-4ed4-8dd1-00133559ac52"
},
"fileId": "
d7OJrcCmJLEIoN3nqNXoZJ
",
"fileId": "",
"sync": false
}
]
\ No newline at end of file
play/assets/unit_demo/scene/demo_01_showFireworks.fire
View file @
5a8a6069
...
...
@@ -448,7 +448,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "发射",
"_N$string": "发射",
"_fontSize": 20,
...
...
play/assets/unit_demo/scene/demo_02_scoreStars.fire
View file @
5a8a6069
...
...
@@ -107,8 +107,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -119,8 +119,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
48
0,
3
2
0,
64
0,
3
6
0,
0,
0,
0,
...
...
@@ -169,8 +169,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -282,8 +282,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
44
0,
28
0,
60
0,
32
0,
0,
0,
0,
...
...
@@ -411,7 +411,7 @@
"ctor": "Float64Array",
"array": [
200,
-
27
0,
-
31
0,
0,
0,
0,
...
...
@@ -581,7 +581,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "播放",
"_N$string": "播放",
"_fontSize": 20,
...
...
@@ -813,7 +812,7 @@
"ctor": "Float64Array",
"array": [
-200,
-
27
0,
-
31
0,
0,
0,
0,
...
...
@@ -983,7 +982,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "增加星星",
"_N$string": "增加星星",
"_fontSize": 20,
...
...
@@ -1180,8 +1178,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_fitWidth": false,
"_fitHeight": true,
...
...
play/assets/unit_demo/scene/demo_03_fireworks_2.fire
View file @
5a8a6069
...
...
@@ -110,8 +110,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -122,8 +122,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
48
0,
3
2
0,
64
0,
3
6
0,
0,
0,
0,
...
...
@@ -172,8 +172,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -504,7 +504,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "(点击屏幕撒花)",
"_N$string": "(点击屏幕撒花)",
"_fontSize": 40,
...
...
@@ -735,7 +734,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "全屏撒花",
"_N$string": "全屏撒花",
"_fontSize": 20,
...
...
@@ -905,8 +903,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_fitWidth": false,
"_fitHeight": true,
...
...
play/assets/unit_demo/scene/demo_04_playAudio.fire
View file @
5a8a6069
...
...
@@ -101,8 +101,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -113,8 +113,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
48
0,
3
2
0,
64
0,
3
6
0,
0,
0,
0,
...
...
@@ -163,8 +163,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -341,8 +341,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_fitWidth": false,
"_fitHeight": true,
...
...
play/assets/unit_demo/scene/demo_05_alphaClick.fire
View file @
5a8a6069
...
...
@@ -101,8 +101,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -113,8 +113,8 @@
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
48
0,
3
2
0,
64
0,
3
6
0,
0,
0,
0,
...
...
@@ -163,8 +163,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
...
...
@@ -407,7 +407,6 @@
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_useOriginalSize": false,
"_string": "点击字母A白色的部分,触发事件;\n点击透明的部分,不触发。",
"_N$string": "点击字母A白色的部分,触发事件;\n点击透明的部分,不触发。",
"_fontSize": 40,
...
...
@@ -436,8 +435,8 @@
"_enabled": true,
"_designResolution": {
"__type__": "cc.Size",
"width":
96
0,
"height":
64
0
"width":
128
0,
"height":
72
0
},
"_fitWidth": false,
"_fitHeight": true,
...
...
play/assets/unit_demo/scene/unit_demo.fire
View file @
5a8a6069
...
...
@@ -2078,9 +2078,9 @@
"_opacity": 100,
"_color": {
"__type__": "cc.Color",
"r":
0
,
"g":
112
,
"b": 2
44
,
"r":
255
,
"g":
255
,
"b": 2
55
,
"a": 255
},
"_contentSize": {
...
...
@@ -2090,8 +2090,8 @@
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0
.5
,
"y": 0
.5
"x": 0,
"y": 0
},
"_trs": {
"__type__": "TypedArray",
...
...
play/assets/unit_demo/scene/unit_demo.js
View file @
5a8a6069
...
...
@@ -22,7 +22,7 @@ cc.Class({
preloadItem
()
{
this
.
preload
();
this
.
onLoadFinish
();
this
.
initView
();
},
preload
()
{
...
...
@@ -36,7 +36,7 @@ cc.Class({
}
},
onLoadFinish
()
{
initView
()
{
const
demoList
=
[{
sceneName
:
'
demo_01_showFireworks
'
,
...
...
@@ -55,6 +55,9 @@ cc.Class({
label
:
'
透明判断
'
}];
const
buttonsNode
=
cc
.
find
(
'
ButtonsNode
'
);
cc
.
game
.
addPersistRootNode
(
buttonsNode
);
demoList
.
forEach
((
demoItem
,
idx
)
=>
{
const
button
=
cc
.
instantiate
(
cc
.
find
(
'
Canvas/New Button
'
));
const
label
=
cc
.
find
(
'
Background/Label
'
,
button
);
...
...
@@ -69,14 +72,8 @@ cc.Class({
button
.
on
(
'
click
'
,
()
=>
{
cc
.
director
.
loadScene
(
demoItem
.
sceneName
,
()
=>
{
cc
.
resources
.
load
(
'
prefabs/ButtonsNode
'
,
cc
.
Prefab
,
function
(
err
,
ButtonsNode
)
{
const
newButtonNode
=
cc
.
instantiate
(
ButtonsNode
);
newButtonNode
.
getComponent
(
'
ButtonsNode
'
).
setDataList
(
demoList
,
idx
);
newButtonNode
.
parent
=
cc
.
find
(
'
Canvas
'
);
newButtonNode
.
x
=
0
;
newButtonNode
.
y
=
0
;
});
buttonsNode
.
active
=
true
;
buttonsNode
.
getComponent
(
'
ButtonsNode
'
).
setDataList
(
demoList
,
idx
);
});
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment