Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
ngt14_czm
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
ngt14_czm
Commits
072d94db
Commit
072d94db
authored
Oct 26, 2022
by
Tt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
背景板生成
parent
7111a0d2
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1651 additions
and
281 deletions
+1651
-281
cocos_generator.fire
assets/cocos_generator/scene/cocos_generator.fire
+106
-141
cocos_generator.ts
assets/cocos_generator/scene/cocos_generator.ts
+27
-140
small.meta
assets/cocos_generator/scene/small.meta
+12
-0
layout_mouse.prefab
assets/cocos_generator/scene/small/layout_mouse.prefab
+508
-0
layout_mouse.prefab.meta
assets/cocos_generator/scene/small/layout_mouse.prefab.meta
+8
-0
ngt10_layout_mouse.ts
assets/cocos_generator/scene/small/ngt10_layout_mouse.ts
+200
-0
ngt10_layout_mouse.ts.meta
...ts/cocos_generator/scene/small/ngt10_layout_mouse.ts.meta
+9
-0
tool.meta
assets/cocos_generator/scene/tool.meta
+12
-0
Game.ts
assets/cocos_generator/scene/tool/Game.ts
+145
-0
Game.ts.meta
assets/cocos_generator/scene/tool/Game.ts.meta
+9
-0
pg.ts
assets/cocos_generator/scene/tool/pg.ts
+605
-0
pg.ts.meta
assets/cocos_generator/scene/tool/pg.ts.meta
+9
-0
creator.d.ts
creator.d.ts
+1
-0
No files found.
assets/cocos_generator/scene/cocos_generator.fire
View file @
072d94db
...
...
@@ -84,28 +84,28 @@
"__id__": 27
},
{
"__id__":
36
"__id__":
28
},
{
"__id__": 37
},
{
"__id__":
40
"__id__":
39
},
{
"__id__": 5
3
"__id__": 5
2
}
],
"_active": true,
"_components": [
{
"__id__": 5
5
"__id__": 5
4
},
{
"__id__": 5
6
"__id__": 5
5
},
{
"__id__": 5
7
"__id__": 5
6
}
],
"_prefab": null,
...
...
@@ -1307,6 +1307,64 @@
"_originalHeight": 0,
"_id": "89KZgyQntDip0vPVhp9mHY"
},
{
"__type__": "cc.Node",
"_name": "layout_question",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 750,
"height": 430
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
569.634,
211.71,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "aejNq4aJVKWYY+QQ4LI7/T"
},
{
"__type__": "cc.Node",
"_name": "block",
...
...
@@ -1316,16 +1374,16 @@
},
"_children": [
{
"__id__": 2
8
"__id__": 2
9
},
{
"__id__": 3
0
"__id__": 3
1
},
{
"__id__": 3
2
"__id__": 3
3
},
{
"__id__": 3
4
"__id__": 3
5
}
],
"_active": true,
...
...
@@ -1383,13 +1441,13 @@
"_name": "New Sprite(Splash)",
"_objFlags": 0,
"_parent": {
"__id__": 2
7
"__id__": 2
8
},
"_children": [],
"_active": true,
"_components": [
{
"__id__":
29
"__id__":
30
}
],
"_prefab": null,
...
...
@@ -1445,7 +1503,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 2
8
"__id__": 2
9
},
"_enabled": true,
"_materials": [
...
...
@@ -1477,13 +1535,13 @@
"_name": "img_undone",
"_objFlags": 0,
"_parent": {
"__id__": 2
7
"__id__": 2
8
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
1
"__id__": 3
2
}
],
"_prefab": null,
...
...
@@ -1539,7 +1597,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
0
"__id__": 3
1
},
"_enabled": true,
"_materials": [
...
...
@@ -1571,13 +1629,13 @@
"_name": "img_focus",
"_objFlags": 0,
"_parent": {
"__id__": 2
7
"__id__": 2
8
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 3
3
"__id__": 3
4
}
],
"_prefab": null,
...
...
@@ -1633,7 +1691,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
2
"__id__": 3
3
},
"_enabled": true,
"_materials": [
...
...
@@ -1665,13 +1723,13 @@
"_name": "img_focus2",
"_objFlags": 0,
"_parent": {
"__id__": 2
7
"__id__": 2
8
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 3
5
"__id__": 3
6
}
],
"_prefab": null,
...
...
@@ -1727,7 +1785,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
4
"__id__": 3
5
},
"_enabled": true,
"_materials": [
...
...
@@ -1754,64 +1812,6 @@
"_atlas": null,
"_id": "d3t9BYmZtDX5ZRYdEjEeyQ"
},
{
"__type__": "cc.Node",
"_name": "layout_question",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 750,
"height": 430
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
569.634,
211.71,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "aejNq4aJVKWYY+QQ4LI7/T"
},
{
"__type__": "cc.Node",
"_name": "layout_blocks",
...
...
@@ -1824,9 +1824,6 @@
"_components": [
{
"__id__": 38
},
{
"__id__": 39
}
],
"_prefab": null,
...
...
@@ -1904,38 +1901,6 @@
"_originalHeight": 0,
"_id": "2eff7tjBlDJ7D7iQfB9p1/"
},
{
"__type__": "cc.Layout",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 37
},
"_enabled": true,
"_layoutSize": {
"__type__": "cc.Size",
"width": 300,
"height": 200
},
"_resize": 0,
"_N$layoutType": 3,
"_N$cellSize": {
"__type__": "cc.Size",
"width": 40,
"height": 40
},
"_N$startAxis": 0,
"_N$paddingLeft": 0,
"_N$paddingRight": 0,
"_N$paddingTop": 0,
"_N$paddingBottom": 0,
"_N$spacingX": 9,
"_N$spacingY": 10,
"_N$verticalDirection": 1,
"_N$horizontalDirection": 0,
"_N$affectedByScale": false,
"_id": "aerObXwbhE/orxs3UGhz7l"
},
{
"__type__": "cc.Node",
"_name": "word",
...
...
@@ -1945,22 +1910,22 @@
},
"_children": [
{
"__id__": 4
1
"__id__": 4
0
},
{
"__id__": 4
3
"__id__": 4
2
},
{
"__id__": 4
5
"__id__": 4
4
},
{
"__id__": 4
7
"__id__": 4
6
},
{
"__id__": 4
9
"__id__": 4
8
},
{
"__id__": 5
1
"__id__": 5
0
}
],
"_active": true,
...
...
@@ -2018,13 +1983,13 @@
"_name": "img_keyboard_b",
"_objFlags": 0,
"_parent": {
"__id__":
40
"__id__":
39
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
2
"__id__": 4
1
}
],
"_prefab": null,
...
...
@@ -2080,7 +2045,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 4
1
"__id__": 4
0
},
"_enabled": true,
"_materials": [
...
...
@@ -2112,13 +2077,13 @@
"_name": "img_keyboard_o",
"_objFlags": 0,
"_parent": {
"__id__":
40
"__id__":
39
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 4
4
"__id__": 4
3
}
],
"_prefab": null,
...
...
@@ -2174,7 +2139,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 4
3
"__id__": 4
2
},
"_enabled": true,
"_materials": [
...
...
@@ -2206,13 +2171,13 @@
"_name": "img_keyboard_p",
"_objFlags": 0,
"_parent": {
"__id__":
40
"__id__":
39
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 4
6
"__id__": 4
5
}
],
"_prefab": null,
...
...
@@ -2268,7 +2233,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 4
5
"__id__": 4
4
},
"_enabled": true,
"_materials": [
...
...
@@ -2300,13 +2265,13 @@
"_name": "img_keyboard_g",
"_objFlags": 0,
"_parent": {
"__id__":
40
"__id__":
39
},
"_children": [],
"_active": false,
"_components": [
{
"__id__": 4
8
"__id__": 4
7
}
],
"_prefab": null,
...
...
@@ -2362,7 +2327,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 4
7
"__id__": 4
6
},
"_enabled": true,
"_materials": [
...
...
@@ -2394,13 +2359,13 @@
"_name": "img_keyboard_y",
"_objFlags": 0,
"_parent": {
"__id__":
40
"__id__":
39
},
"_children": [],
"_active": false,
"_components": [
{
"__id__":
50
"__id__":
49
}
],
"_prefab": null,
...
...
@@ -2456,7 +2421,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 4
9
"__id__": 4
8
},
"_enabled": true,
"_materials": [
...
...
@@ -2488,13 +2453,13 @@
"_name": "label",
"_objFlags": 0,
"_parent": {
"__id__":
40
"__id__":
39
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 5
2
"__id__": 5
1
}
],
"_prefab": null,
...
...
@@ -2550,7 +2515,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 5
1
"__id__": 5
0
},
"_enabled": true,
"_materials": [
...
...
@@ -2591,7 +2556,7 @@
"_active": true,
"_components": [
{
"__id__": 5
4
"__id__": 5
3
}
],
"_prefab": null,
...
...
@@ -2647,7 +2612,7 @@
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 5
3
"__id__": 5
2
},
"_enabled": false,
"alignMode": 1,
...
...
assets/cocos_generator/scene/cocos_generator.ts
View file @
072d94db
import
{
asyncDelay
,
onHomeworkFinish
}
from
"
../script/util
"
;
import
{
MyCocosSceneComponent
}
from
"
../script/MyCocosSceneComponent
"
;
import
pg
from
"
./tool/pg
"
;
import
{
GameNGT14
}
from
"
./tool/Game
"
;
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
...
...
@@ -26,161 +28,46 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
initData
();
this
.
initView
();
this
.
initListener
();
this
.
gameStart
();
}
_cantouch
=
null
;
initData
()
{
// 所有全局变量 默认都是null
this
.
_cantouch
=
true
;
GameNGT14
.
getIns
().
initData
(
this
.
data
);
GameNGT14
.
getIns
().
reset
();
let
data
=
GameNGT14
.
getIns
().
getCurrent
();
console
.
log
(
'
gamestart
'
,
data
)
}
initView
()
{
this
.
initBg
();
this
.
initPic
();
this
.
initBtn
();
this
.
initIcon
();
this
.
initBlocks
();
}
initBg
()
{
const
bgNode
=
cc
.
find
(
'
Canvas/bg
'
);
bgNode
.
scale
=
this
.
_mapScaleMax
;
}
pic1
=
null
;
pic2
=
null
;
initPic
()
{
const
canvas
=
cc
.
find
(
'
Canvas
'
);
const
maxW
=
canvas
.
width
*
0.7
;
this
.
getSprNodeByUrl
(
this
.
data
.
pic_url
,
(
sprNode
)
=>
{
const
picNode1
=
sprNode
;
picNode1
.
scale
=
maxW
/
picNode1
.
width
;
picNode1
.
baseX
=
picNode1
.
x
;
canvas
.
addChild
(
picNode1
);
this
.
pic1
=
picNode1
;
const
labelNode
=
new
cc
.
Node
();
labelNode
.
color
=
cc
.
Color
.
YELLOW
;
const
label
=
labelNode
.
addComponent
(
cc
.
Label
);
label
.
string
=
this
.
data
.
text
;
label
.
fontSize
=
60
;
label
.
lineHeight
=
60
;
label
.
font
=
cc
.
find
(
'
Canvas/res/font/BRLNSDB
'
).
getComponent
(
'
cc.Label
'
).
font
;
picNode1
.
addChild
(
labelNode
);
});
this
.
getSprNodeByUrl
(
this
.
data
.
pic_url_2
,
(
sprNode
)
=>
{
const
picNode2
=
sprNode
;
picNode2
.
scale
=
maxW
/
picNode2
.
width
;
canvas
.
addChild
(
picNode2
);
picNode2
.
x
=
canvas
.
width
;
picNode2
.
baseX
=
picNode2
.
x
;
this
.
pic2
=
picNode2
;
const
labelNode
=
new
cc
.
Node
();
const
label
=
labelNode
.
addComponent
(
cc
.
RichText
);
const
size
=
60
label
.
font
=
cc
.
find
(
'
Canvas/res/font/BRLNSDB
'
).
getComponent
(
cc
.
Label
).
font
;
label
.
string
=
`<outline color=#751e00 width=4><size=
${
size
}
><color=#ffffff>
${
this
.
data
.
text
}
</color></size></outline>`
label
.
lineHeight
=
size
;
picNode2
.
addChild
(
labelNode
);
});
}
initIcon
()
{
const
iconNode
=
this
.
getSprNode
(
'
icon
'
);
iconNode
.
zIndex
=
5
;
iconNode
.
anchorX
=
1
;
iconNode
.
anchorY
=
1
;
iconNode
.
parent
=
cc
.
find
(
'
Canvas
'
);
iconNode
.
x
=
iconNode
.
parent
.
width
/
2
-
10
;
iconNode
.
y
=
iconNode
.
parent
.
height
/
2
-
10
;
iconNode
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
this
.
playAudioByUrl
(
this
.
data
.
audio_url
);
})
}
curPage
=
null
;
initBtn
()
{
this
.
curPage
=
0
;
const
bottomPart
=
cc
.
find
(
'
Canvas/bottomPart
'
);
bottomPart
.
zIndex
=
5
;
// 提高层级
bottomPart
.
x
=
bottomPart
.
parent
.
width
/
2
;
bottomPart
.
y
=
-
bottomPart
.
parent
.
height
/
2
;
const
leftBtnNode
=
bottomPart
.
getChildByName
(
'
btn_left
'
);
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode
.
on
(
'
click
'
,
()
=>
{
if
(
!
this
.
_cantouch
)
{
return
;
}
if
(
this
.
curPage
==
0
)
{
return
;
}
this
.
curPage
=
0
this
.
leftMove
();
this
.
playLocalAudio
(
'
btn
'
);
})
initListener
()
{
const
rightBtnNode
=
bottomPart
.
getChildByName
(
'
btn_right
'
);
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode
.
on
(
'
click
'
,
()
=>
{
if
(
!
this
.
_cantouch
)
{
return
;
}
if
(
this
.
curPage
==
1
)
{
return
;
}
this
.
curPage
=
1
this
.
rightMove
();
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish
();
this
.
playLocalAudio
(
'
btn
'
);
})
private
layout_blocks
:
cc
.
Node
;
initBlocks
()
{
this
.
layout_blocks
=
pg
.
view
.
find
(
this
,
'
layout_blocks
'
);
this
.
layout_blocks
.
removeAllChildren
()
let
block
=
pg
.
view
.
find
(
this
,
'
block
'
);
//动态创建,并给每一个打上编号
let
space
=
{
x
:
9
+
80
,
y
:
10
+
80
}
for
(
let
y
=
0
;
y
<
9
;
y
++
)
{
for
(
let
x
=
0
;
x
<
12
;
x
++
)
{
let
node
=
cc
.
instantiate
(
block
);
let
data
=
{
x
,
y
};
node
.
data
=
data
;
node
.
x
=
-
495
+
space
.
x
*
x
;
node
.
y
=
365
-
space
.
y
*
y
;
node
.
active
=
!!
GameNGT14
.
getIns
().
getBlockVal
(
x
,
y
);
this
.
layout_blocks
.
addChild
(
node
);
}
leftMove
()
{
this
.
_cantouch
=
false
;
const
len
=
this
.
pic1
.
parent
.
width
;
cc
.
tween
(
this
.
pic1
)
.
to
(
1
,
{
x
:
this
.
pic1
.
baseX
},
{
easing
:
'
cubicInOut
'
})
.
start
();
cc
.
tween
(
this
.
pic2
)
.
to
(
1
,
{
x
:
this
.
pic2
.
baseX
},
{
easing
:
'
cubicInOut
'
})
.
call
(()
=>
{
this
.
_cantouch
=
true
;
})
.
start
();
}
rightMove
()
{
this
.
_cantouch
=
false
;
const
len
=
this
.
pic1
.
parent
.
width
;
cc
.
tween
(
this
.
pic1
)
.
to
(
1
,
{
x
:
this
.
pic1
.
baseX
-
len
},
{
easing
:
'
cubicInOut
'
})
.
start
();
cc
.
tween
(
this
.
pic2
)
.
to
(
1
,
{
x
:
this
.
pic2
.
baseX
-
len
},
{
easing
:
'
cubicInOut
'
})
.
call
(()
=>
{
this
.
_cantouch
=
true
;
})
.
start
();
}
// update (dt) {},
initListener
()
{
gameStart
()
{
}
playLocalAudio
(
audioName
)
{
...
...
assets/cocos_generator/scene/small.meta
0 → 100644
View file @
072d94db
{
"ver": "1.1.2",
"uuid": "4338bda3-228e-458d-974d-b89923efb091",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
assets/cocos_generator/scene/small/layout_mouse.prefab
0 → 100644
View file @
072d94db
[
{
"__type__": "cc.Prefab",
"_name": "",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"asyncLoadAssets": false,
"readonly": false
},
{
"__type__": "cc.Node",
"_name": "layout_mouse",
"_objFlags": 0,
"_parent": null,
"_children": [
{
"__id__": 2
}
],
"_active": true,
"_components": [
{
"__id__": 13
}
],
"_prefab": {
"__id__": 14
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 1,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "img",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [
{
"__id__": 3
},
{
"__id__": 6
},
{
"__id__": 9
}
],
"_active": false,
"_components": [],
"_prefab": {
"__id__": 12
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 0,
"height": 0
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "star_bg",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 4
}
],
"_prefab": {
"__id__": 5
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 59,
"height": 42
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 3
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": null,
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "564dd930-80a8-4d89-bf96-f0f5be1e92cb"
},
"fileId": "1a6bNni9hAzZuAOicd4es+",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "star",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 7
}
],
"_prefab": {
"__id__": 8
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 59,
"height": 42
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 6
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": null,
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "564dd930-80a8-4d89-bf96-f0f5be1e92cb"
},
"fileId": "0dcJdIc9BNfbQiPTRx9GVW",
"sync": false
},
{
"__type__": "cc.Node",
"_name": "icon_bigstar",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 10
}
],
"_prefab": {
"__id__": 11
},
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 59,
"height": 42
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": ""
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 9
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_spriteFrame": null,
"_type": 0,
"_sizeMode": 1,
"_fillType": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "564dd930-80a8-4d89-bf96-f0f5be1e92cb"
},
"fileId": "e8QBmuw8VOBYptnR5JD386",
"sync": false
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "564dd930-80a8-4d89-bf96-f0f5be1e92cb"
},
"fileId": "9eIg5jomZOV5E+Yzh+2uPU",
"sync": false
},
{
"__type__": "e9eaeH4ZsVKx4dSvhRwGuVF",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"position": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"bigStarClip": {
"__uuid__": "71b51036-3bca-4d2a-84e1-fedc216ba064"
},
"starCountClip": {
"__uuid__": "71b51036-3bca-4d2a-84e1-fedc216ba064"
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__uuid__": "564dd930-80a8-4d89-bf96-f0f5be1e92cb"
},
"fileId": "",
"sync": false
}
]
\ No newline at end of file
assets/cocos_generator/scene/small/layout_mouse.prefab.meta
0 → 100644
View file @
072d94db
{
"ver": "1.2.9",
"uuid": "564dd930-80a8-4d89-bf96-f0f5be1e92cb",
"optimizationPolicy": "AUTO",
"asyncLoadAssets": false,
"readonly": false,
"subMetas": {}
}
\ No newline at end of file
assets/cocos_generator/scene/small/ngt10_layout_mouse.ts
0 → 100644
View file @
072d94db
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.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
import
pg
from
"
../tool/pg
"
;
// import Game from "../../scene/Game";
const
{
ccclass
,
property
}
=
cc
.
_decorator
;
@
ccclass
export
default
class
Ngt_star_10
extends
cc
.
Component
{
// LIFE-CYCLE CALLBACKS:
onLoad
()
{
pg
.
event
.
on
(
"
mouse_10_add
"
,
(
isRight
=
true
)
=>
{
this
.
showBigStar
(
isRight
);
});
pg
.
event
.
on
(
"
mouse_10_num
"
,
(
max
:
number
)
=>
{
this
.
initStar
(
max
);
});
pg
.
event
.
on
(
"
mouse_10_add_error
"
,
(
isRight
=
true
)
=>
{
this
.
showErrorStar
();
});
}
init
(
max
)
{
}
reviceMouse
()
{
}
start
()
{
}
//-----------------------STAR-----------------------------
bigStarArr
:
cc
.
Node
[];
canvas
:
cc
.
Node
;
curGroupIndex
:
number
@
property
(
cc
.
Vec2
)
position
:
cc
.
Vec2
;
@
property
(
cc
.
AudioClip
)
bigStarClip
:
cc
.
AudioClip
;
@
property
(
cc
.
AudioClip
)
starCountClip
:
cc
.
AudioClip
;
//搭配res中的star_bg star等使用
initStar
(
max
)
{
this
.
curGroupIndex
=
0
;
this
.
canvas
=
cc
.
find
(
'
Canvas
'
);
const
gArr
=
[];
gArr
.
length
=
max
;
if
(
gArr
.
length
<
1
)
{
return
;
}
this
.
cleanStar
();
this
.
bigStarArr
=
[];
let
baseX
=
this
.
position
.
x
;
let
baseY
=
this
.
position
.
y
;
let
disW
=
80
;
// * this._mapScaleMin
// let disH = 80 * this._mapScaleMin;
let
disScale
=
1
;
if
(
gArr
.
length
>
5
)
{
// disH = (400 / gArr.length) * this._mapScaleMin;
// disScale = 5 / gArr.length;
}
for
(
let
i
=
0
;
i
<
gArr
.
length
;
i
++
)
{
const
starBg
=
this
.
getSprNode
(
'
star_bg
'
);
this
.
canvas
.
addChild
(
starBg
,
10
);
// starBg.x = baseX;
// starBg.y = baseY - i * disH;
starBg
.
x
=
baseX
-
i
*
disW
;
starBg
.
y
=
baseY
starBg
.
scale
=
disScale
;
const
starTop
=
this
.
getSprNode
(
'
star
'
);
starBg
.
addChild
(
starTop
);
starTop
.
active
=
false
;
starBg
.
star
=
starTop
;
const
starBig
=
this
.
getSprNode
(
'
icon_bigstar
'
);
starTop
.
addChild
(
starBig
);
starBig
.
angle
=
-
90
;
starBg
.
starBig
=
starBig
;
const
star_wrong
=
this
.
getSprNode
(
'
star_wrong
'
);
starTop
.
addChild
(
star_wrong
);
star_wrong
.
active
=
false
;
starBg
.
star_wrong
=
star_wrong
;
this
.
bigStarArr
.
push
(
starBg
);
}
console
.
log
(
"
bigStarArr:
"
,
this
.
bigStarArr
);
}
cleanStar
()
{
if
(
this
.
bigStarArr
&&
this
.
bigStarArr
.
length
>
0
)
{
for
(
let
i
=
0
;
i
<
this
.
bigStarArr
.
length
;
i
++
)
{
this
.
bigStarArr
[
i
].
removeFromParent
();
}
}
}
private
showErrorStar
()
{
if
(
!
this
.
bigStarArr
||
this
.
bigStarArr
.
length
<=
0
)
{
// this.checkGameEnd();
return
;
}
const
bigStarBg
=
this
.
bigStarArr
[
this
.
curGroupIndex
++
];
if
(
!
bigStarBg
)
return
;
const
star_wrong
=
bigStarBg
.
star_wrong
;
star_wrong
.
active
=
true
;
const
starBig
=
bigStarBg
.
starBig
;
// starBig.scale = 1;
starBig
.
active
=
false
;
const
star
=
bigStarBg
.
star
;
star
.
active
=
true
;
const
canvas
=
cc
.
find
(
'
Canvas
'
);
const
startPos
=
this
.
exchangeNodePos
(
star
.
parent
,
canvas
);
const
middlePos
=
this
.
exchangeNodePos
(
star
.
parent
,
canvas
);
star
.
x
=
0
;
star
.
y
=
0
;
star
.
scale
=
1
/
bigStarBg
.
scale
;
pg
.
event
.
emit
(
"
mouse_10_num_game_end
"
)
}
showBigStar
(
isRight
)
{
if
(
!
this
.
bigStarArr
||
this
.
bigStarArr
.
length
<=
0
)
{
// this.checkGameEnd();
return
;
}
const
bigStarBg
=
this
.
bigStarArr
[
this
.
curGroupIndex
++
];
if
(
!
bigStarBg
)
return
;
const
starBig
=
bigStarBg
.
starBig
;
starBig
.
scale
=
1
;
const
star
=
bigStarBg
.
star
;
star
.
active
=
true
;
star
.
scaleX
=
0.7
/
bigStarBg
.
scale
;
star
.
scaleY
=
1
/
bigStarBg
.
scale
;
star
.
angle
=
90
;
const
canvas
=
cc
.
find
(
'
Canvas
'
);
const
startPos
=
this
.
exchangeNodePos
(
star
.
parent
,
canvas
);
const
middlePos
=
this
.
exchangeNodePos
(
star
.
parent
,
canvas
);
star
.
x
=
startPos
.
x
;
star
.
y
=
startPos
.
y
-
starBig
.
height
;
console
.
log
(
'
middlePos =
'
+
JSON
.
stringify
(
middlePos
));
const
time
=
1
;
cc
.
tween
(
star
)
.
to
(
0.3
,
{
y
:
middlePos
.
y
+
80
},
{
easing
:
'
quadOut
'
})
.
to
(
0.1
,
{
y
:
middlePos
.
y
+
40
,
scaleX
:
1.2
/
bigStarBg
.
scale
,
scaleY
:
0.8
/
bigStarBg
.
scale
},
{
easing
:
'
quadOut
'
})
.
to
(
0.1
,
{
y
:
middlePos
.
y
,
scaleX
:
1
/
bigStarBg
.
scale
,
scaleY
:
1
/
bigStarBg
.
scale
},
{
easing
:
'
quadOut
'
})
.
delay
(
0.1
)
.
to
(
0.8
,
{
angle
:
-
720
,
scale
:
1
})
.
start
();
cc
.
tween
(
star
)
.
delay
(
0.6
)
.
to
(
0.8
,
{
x
:
0
},
{
easing
:
'
quadIn
'
})
.
start
();
cc
.
tween
(
star
)
.
delay
(
0.6
)
.
to
(
0.8
,
{
y
:
0
},
{
easing
:
'
quadOut
'
})
.
start
();
cc
.
tween
(
starBig
)
.
delay
(
0.6
)
.
to
(
0.8
,
{
scale
:
0
},
{
easing
:
'
quadOut
'
})
.
call
(()
=>
{
pg
.
event
.
emit
(
"
mouse_10_num_game_end
"
)
// this.playAudio(this.starCountClip);
})
.
start
();
this
.
playAudio
(
this
.
bigStarClip
);
}
//-----------------------STAR-----------------------------
getSprNode
(
resName
)
{
const
sf
=
pg
.
view
.
find
(
this
,
`img/
${
resName
}
`
).
getComponent
(
cc
.
Sprite
).
spriteFrame
;
const
node
=
new
cc
.
Node
();
node
.
addComponent
(
cc
.
Sprite
).
spriteFrame
=
sf
;
return
node
;
}
exchangeNodePos
(
baseNode
,
targetNode
)
{
return
baseNode
.
convertToNodeSpaceAR
(
targetNode
.
_parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
)));
}
playAudio
(
audioClip
,
cb
=
null
)
{
if
(
audioClip
)
{
const
audioId
=
cc
.
audioEngine
.
playEffect
(
audioClip
,
false
);
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
();
});
}
}
}
// update (dt) {}
}
assets/cocos_generator/scene/small/ngt10_layout_mouse.ts.meta
0 → 100644
View file @
072d94db
{
"ver": "1.0.8",
"uuid": "c6d2b333-2790-41e1-a04a-dea0262fa433",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
assets/cocos_generator/scene/tool.meta
0 → 100644
View file @
072d94db
{
"ver": "1.1.2",
"uuid": "ab1ef3e6-d935-41ee-abd1-950ab001fc13",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
assets/cocos_generator/scene/tool/Game.ts
0 → 100644
View file @
072d94db
export
enum
BLOCK_TYPE
{
IMG
=
'
img
'
,
TXT
=
'
txt
'
,
LINE
=
'
line
'
,
TAG
=
'
tag
'
}
export
enum
BOARD_STATE
{
DEFAULT
=
'
default
'
,
INPUT
=
'
input
'
,
RIGHT
=
'
right
'
,
ERROR
=
'
error
'
,
CHECK
=
'
check
'
}
export
class
Block
{
public
static
id
:
number
=
10000
;
public
id
:
number
;
public
type
:
BLOCK_TYPE
;
public
img
:
string
;
public
line
:
number
;
public
text
:
string
;
public
answer
:
string
;
//用户填写答案
public
tag
:
string
;
constructor
(
data
)
{
console
.
log
(
data
);
this
.
id
=
Block
.
id
++
;
this
.
type
=
data
.
type
;
this
.
img
=
data
.
image
;
this
.
text
=
data
.
text
;
this
.
tag
=
data
.
tag
;
this
.
line
=
Number
(
data
.
line
);
this
.
answer
=
''
;
}
addKeyBoard
(
val
)
{
if
(
!
this
.
answer
)
this
.
answer
=
''
this
.
answer
+=
val
;
}
deleteKeyBoard
()
{
if
(
!
this
.
answer
||
this
.
answer
==
''
)
{
this
.
answer
=
''
return
;
}
this
.
answer
=
this
.
answer
.
substring
(
0
,
this
.
answer
.
length
-
1
)
}
finished
()
{
if
(
this
.
type
==
BLOCK_TYPE
.
LINE
)
{
return
this
.
answer
.
length
!=
0
}
else
{
return
true
}
}
isRight
()
{
if
(
this
.
type
==
BLOCK_TYPE
.
LINE
)
{
return
this
.
answer
==
this
.
text
;
}
else
{
return
true
}
}
}
export
class
Option
{
public
static
id
:
number
=
10000
;
public
id
:
number
;
public
list
:
Array
<
Block
>
;
constructor
(
data
)
{
this
.
id
=
Option
.
id
++
;
console
.
log
(
data
);
this
.
list
=
data
.
blocks
.
map
(
block
=>
new
Block
(
block
));
}
isDoubleLine
()
{
return
this
.
list
.
some
(
block
=>
block
.
type
==
BLOCK_TYPE
.
IMG
)
}
getList
()
{
return
this
.
list
.
concat
();
}
finished
()
{
return
this
.
list
.
every
(
block
=>
block
.
finished
())
}
isRight
()
{
return
this
.
list
.
every
(
block
=>
block
.
isRight
())
}
}
export
class
Question
{
public
static
id
:
number
=
1000
;
public
id
:
number
;
public
list
:
Array
<
Option
>
;
public
submit
:
BOARD_STATE
;
constructor
(
data
)
{
this
.
id
=
Question
.
id
++
;
console
.
log
(
data
);
this
.
list
=
data
.
options
.
map
(
option
=>
new
Option
(
option
));
this
.
submit
=
BOARD_STATE
.
DEFAULT
}
setSubmit
(
state
)
{
this
.
submit
=
state
}
getSubmit
()
{
return
this
.
submit
;
}
getList
()
{
return
this
.
list
.
concat
();
}
finished
()
{
return
this
.
list
.
every
(
option
=>
option
.
finished
())
}
isRight
()
{
return
this
.
list
.
every
(
option
=>
option
.
isRight
())
}
}
export
class
GameNGT14
{
public
questions
:
Array
<
Question
>
public
blocks
:
Array
<
{
val
:
string
}
>
public
current
:
number
;
public
title
:
string
;
public
total
:
number
;
public
aniEnter
;
public
startAudio
;
constructor
()
{
this
.
current
=
0
;
this
.
questions
=
[];
}
reset
()
{
this
.
current
=
0
;
}
initData
(
data
)
{
console
.
log
(
data
);
this
.
questions
=
data
.
questions
[
0
].
parts
.
map
(
part
=>
new
Question
(
part
));
this
.
blocks
=
data
.
blocks
;
this
.
title
=
data
.
title
;
this
.
startAudio
=
data
.
startAudio
||
""
;
this
.
aniEnter
=
data
.
imgAni
;
}
getBlockVal
(
x
,
y
)
{
if
(
!
this
.
blocks
[
y
]
||
!
this
.
blocks
[
y
][
x
])
return
;
return
this
.
blocks
[
y
][
x
].
val
;
}
getCurrent
():
Question
{
return
this
.
questions
[
this
.
current
];
}
static
ins
:
GameNGT14
;
static
getIns
():
GameNGT14
{
if
(
!
GameNGT14
.
ins
)
GameNGT14
.
ins
=
new
GameNGT14
();
return
GameNGT14
.
ins
;
}
}
\ No newline at end of file
assets/cocos_generator/scene/tool/Game.ts.meta
0 → 100644
View file @
072d94db
{
"ver": "1.0.8",
"uuid": "52bbca66-7f98-4d59-83d2-e5fdd23b7de8",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
assets/cocos_generator/scene/tool/pg.ts
0 → 100644
View file @
072d94db
class
Emitter
{
static
instance
;
static
getInstance
()
{
if
(
!
Emitter
.
instance
)
{
Emitter
.
instance
=
new
Emitter
();
}
return
Emitter
.
instance
;
}
_name
:
any
;
_callbacks
:
any
;
constructor
(
name
=
""
)
{
this
.
_name
=
name
;
this
.
_callbacks
=
{};
return
this
;
}
clear
()
{
this
.
_callbacks
=
{};
}
on
(
event
,
fn
)
{
if
(
!
this
.
_callbacks
[
event
])
this
.
_callbacks
[
event
]
=
[];
this
.
_callbacks
[
event
].
push
(
fn
);
};
once
(
event
,
fn
)
{
function
on
()
{
this
.
off
(
event
,
on
);
fn
.
apply
(
this
,
arguments
);
}
on
.
fn
=
fn
;
this
.
on
(
event
,
on
);
};
off
(
event
,
fn
)
{
// all
if
(
0
==
arguments
.
length
)
{
this
.
_callbacks
=
{};
return
;
}
// specific event
let
callbacks
=
this
.
_callbacks
[
event
];
if
(
!
callbacks
)
return
;
// remove all handlers
if
(
1
==
arguments
.
length
)
{
delete
this
.
_callbacks
[
event
];
return
;
}
// remove specific handler
let
cb
;
for
(
let
i
=
0
;
i
<
callbacks
.
length
;
i
++
)
{
cb
=
callbacks
[
i
];
if
(
cb
===
fn
||
cb
.
fn
===
fn
)
{
callbacks
.
splice
(
i
,
1
);
break
;
}
}
return
;
}
emit
(
event
,
...
args
)
{
this
.
_callbacks
=
this
.
_callbacks
||
{};
// let args = [].slice.call(arguments, 1);
let
callbacks
=
this
.
_callbacks
[
event
];
if
(
callbacks
)
{
callbacks
=
callbacks
.
slice
(
0
);
for
(
let
i
=
0
,
len
=
callbacks
.
length
;
i
<
len
;
++
i
)
{
callbacks
[
i
].
apply
(
this
,
args
);
}
}
}
listeners
(
event
)
{
this
.
_callbacks
=
this
.
_callbacks
||
{};
return
this
.
_callbacks
[
event
]
||
[];
};
hasListeners
(
event
)
{
return
!!
this
.
listeners
(
event
).
length
;
};
}
class
TimeCtrl
{
private
current
:
number
;
constructor
()
{
this
.
current
=
0
;
}
fillTime
(
time
)
{
this
.
current
+=
(
time
*
1000
)
return
this
;
}
setTime
(
time
)
{
this
.
current
+=
(
time
*
1000
)
return
this
;
}
wait
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
lastTime
=
new
Date
().
getTime
();
let
id
=
setInterval
(()
=>
{
let
nowTime
=
new
Date
().
getTime
();
this
.
current
-=
(
nowTime
-
lastTime
);
lastTime
=
nowTime
;
if
(
this
.
current
<=
0
)
{
clearInterval
(
id
);
resolve
(
true
);
}
},
1
)
});
}
reset
()
{
this
.
current
=
0
;
return
this
;
}
}
let
pg
=
{
logger
:
{
d
:
function
(
str
)
{
cc
.
log
(
str
);
return
null
;
},
i
:
function
(
str
)
{
cc
.
log
(
str
);
return
null
;
},
w
:
function
(
str
)
{
cc
.
warn
(
str
);
return
null
;
}
},
view
:
{
//---------------------节点管理------------------------------
//创建节点
createNode
()
{
let
node
=
new
cc
.
Node
();
return
node
;
},
//添加节点
addChild
(
item
,
child
,
zIndex
)
{
if
(
!
child
)
return
console
.
log
(
"
addChild error ->请传入子节点
"
);
if
(
!
item
)
return
console
.
log
(
"
addChild error ->请传入父节点
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
node
)
return
console
.
log
(
"
addChild error ->请传入父节点
"
);
if
(
child
.
parent
)
return
pg
.
logger
.
w
(
"
此节点已经有父节点->
"
+
child
.
name
);
if
(
zIndex
>=
0
)
{
node
.
addChild
(
child
,
zIndex
)
}
else
{
node
.
addChild
(
child
);
}
return
true
;
},
//删除子节点
removeChild
(
item
,
child
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
节点remove失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
child
.
parent
&&
child
.
parent
==
node
)
{
node
.
removeChild
(
child
);
child
.
destroy
();
}
return
true
;
},
removeSelf
(
item
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
节点移除失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
node
.
removeFromParent
();
node
.
destroy
();
},
//删除所有子节点
removChildren
(
item
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
节点remove失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
node
.
parent
)
return
pg
.
logger
.
w
(
"
节点remove失败,传入了错误的item
"
);
node
.
removeAllChildren
();
return
true
;
},
//查找节点
find
(
item
,
childPath
):
cc
.
Node
{
if
(
typeof
item
==
"
string
"
)
{
childPath
=
item
;
item
=
null
;
}
if
(
!
childPath
||
childPath
==
''
||
typeof
childPath
!=
'
string
'
)
return
pg
.
logger
.
w
(
"
findChildByPath error->
"
+
"
请传入路径
"
);
let
child
=
null
;
if
(
item
)
{
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
node
.
children
||
node
.
children
.
length
==
0
)
return
pg
.
logger
.
w
(
"
findChild error->
"
+
"
找不到此节点,请检查层级路径:
"
+
childPath
);
child
=
cc
.
find
(
childPath
,
node
);
}
else
{
child
=
cc
.
find
(
childPath
);
}
if
(
!
child
)
return
pg
.
logger
.
w
(
"
findChildByPath error->
"
+
"
找不到此节点,请检查层级路径:
"
+
childPath
);
return
child
;
},
//--------------------触控事件--------------------------------
//添加监听
touchOn
(
item
,
callback
,
target
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
添加按钮响应失败,传入了错误的item
"
);
if
(
!
callback
||
!
target
)
return
pg
.
logger
.
w
(
"
添加按钮响应失败,传入了空回调
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
node
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
callback
,
target
);
return
true
;
},
//移除监听
touchOff
(
item
,
callback
,
target
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
移除按钮响应失败,传入了错误的item
"
);
if
(
!
callback
||
!
target
)
return
pg
.
logger
.
w
(
"
移除按钮响应失败,传入了空回调
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
node
||
!
node
.
parent
)
return
pg
.
logger
.
w
(
"
节点已移除
"
);
node
.
off
(
cc
.
Node
.
EventType
.
TOUCH_END
,
callback
,
target
);
return
true
;
},
//是否允许点击
touchEnable
(
item
,
isEnable
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
设置按钮响应失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
node
)
return
pg
.
logger
.
w
(
"
设置按钮响应失败,传入了错误的item
"
);
let
btn
=
node
.
getComponent
(
cc
.
Button
);
if
(
!
btn
)
return
pg
.
logger
.
w
(
"
当前节点没有添加button->
"
+
node
.
name
);
btn
.
interactable
=
isEnable
;
return
true
;
},
//-------------------渲染相关---------------------------------
//显示隐藏
visible
(
item
,
isVisible
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
节点显示失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
node
||
!
node
.
parent
)
return
pg
.
logger
.
w
(
"
节点已移除
"
);
node
.
active
=
isVisible
;
return
true
;
},
//更换图片
setImg
(
item
,
res
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的item
"
);
if
(
!
res
)
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的res
"
);
pg
.
load
.
loadImg
(
res
).
then
((
spriteFrame
:
cc
.
SpriteFrame
)
=>
{
if
(
!
cc
.
isValid
(
item
))
return
pg
.
logger
.
i
(
"
节点已销毁
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
i
(
"
节点已销毁
"
);
let
component
=
node
.
getComponent
(
cc
.
Sprite
);
let
{
width
,
height
}
=
spriteFrame
.
getRect
();
component
.
spriteFrame
=
spriteFrame
;
resolve
({
width
,
height
});
})
})
},
setNetImg
(
item
,
res
,
{
w
,
h
},
custom
=
true
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
res
)
{
if
(
node
)
node
.
active
=
false
;
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的res
"
);
}
if
(
!
node
)
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的item
"
);
if
(
node
.
net_url
==
res
)
return
;
node
.
active
=
false
;
//
pg
.
load
.
loadNetImg
(
res
).
then
((
texture
:
cc
.
Texture2D
)
=>
{
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
i
(
"
节点已销毁
"
);
let
nw
=
node
.
width
=
texture
.
width
;
let
nh
=
node
.
height
=
texture
.
height
;
let
component
=
node
.
getComponent
(
cc
.
Sprite
);
let
spriteFrame
=
new
cc
.
SpriteFrame
(
texture
);
component
.
spriteFrame
=
spriteFrame
;
node
.
net_url
=
res
;
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
i
(
"
节点已销毁
"
);
if
(
!
node
)
return
pg
.
logger
.
w
(
"
节点已销毁
"
);
if
(
w
&&
h
&&
custom
)
{
let
scaleX
=
w
/
nw
;
let
scaleY
=
h
/
nh
;
// let scale = scaleX <= scaleY ? scaleX : scaleY;
node
.
width
=
nw
*
scaleX
;
node
.
height
=
nh
*
scaleY
;
}
node
.
active
=
true
;
resolve
({
w
:
nw
,
h
:
nh
});
})
})
},
setNodeImg
(
item
,
target
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的item
"
);
let
spriteFrame
=
target
.
getComponent
(
cc
.
Sprite
).
spriteFrame
;
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
i
(
"
节点已销毁
"
);
let
component
=
node
.
getComponent
(
cc
.
Sprite
);
let
{
width
,
height
}
=
spriteFrame
.
getRect
();
component
.
spriteFrame
=
spriteFrame
;
resolve
({
width
,
height
});
})
},
switchMaterial
(
item
,
id0
=
0
,
id1
=
1
)
{
let
material0
=
item
.
getMaterial
(
id0
);
let
material1
=
item
.
getMaterial
(
id1
);
item
.
setMaterial
(
id0
,
material1
);
item
.
setMaterial
(
id1
,
material0
);
},
//更改文字
setString
(
item
,
text
,
count
=
0
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
节点text失败,传入了错误的item
"
);
if
(
count
>
0
)
{
let
parse_str
=
function
(
str
,
count
)
{
if
(
!
str
)
return
""
;
var
segmants
=
str
.
split
(
'
+
'
);
str
=
segmants
.
join
(
''
);
var
len
=
0
;
var
idx
=
0
;
for
(
var
i
=
0
;
i
<
str
.
length
;
i
++
)
{
var
p
=
/
[^
x00-xff
]
/g
;
var
a
=
str
.
charAt
(
i
);
if
(
p
.
test
(
a
))
{
len
+=
2
;
idx
++
;
}
else
{
len
+=
1
;
idx
++
;
}
if
(
len
>=
count
*
2
)
break
;
}
return
str
.
substr
(
0
,
idx
);
}
text
=
parse_str
(
text
,
count
);
}
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
node
)
return
;
let
component
=
node
.
getComponent
(
cc
.
Label
);
//组件功能 非node的功能
component
.
string
=
text
;
return
true
;
},
//更变颜色
setColor
(
item
,
color
,
outlineWidth
=
-
1
)
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
setColor warn->传入了错误的item
"
);
let
RGB
=
this
.
colorRgb
(
color
);
if
(
!
RGB
||
RGB
.
length
==
0
)
return
pg
.
logger
.
w
(
"
color ->传入了错误的color
"
);
item
.
color
=
new
cc
.
Color
(
RGB
[
0
],
RGB
[
1
],
RGB
[
2
]);
if
(
outlineWidth
<
0
)
return
;
let
LabelOutline
=
item
.
getComponent
(
cc
.
LabelOutline
);
if
(
!
LabelOutline
)
return
pg
.
logger
.
w
(
"
LabelOutline warn->未添加描边
"
);
LabelOutline
.
width
=
outlineWidth
;
},
colorRgb
(
color
)
{
var
reg
=
/^#
([
0-9a-fA-f
]{3}
|
[
0-9a-fA-f
]{6})
$/
;
var
sColor
=
color
;
if
(
sColor
&&
reg
.
test
(
sColor
))
{
if
(
sColor
.
length
===
4
)
{
var
sColorNew
=
"
#
"
;
for
(
var
i
=
1
;
i
<
4
;
i
+=
1
)
{
sColorNew
+=
sColor
.
slice
(
i
,
i
+
1
).
concat
(
sColor
.
slice
(
i
,
i
+
1
));
}
sColor
=
sColorNew
;
}
//处理六位的颜色值
var
sColorChange
=
[];
for
(
var
i
=
1
;
i
<
7
;
i
+=
2
)
{
sColorChange
.
push
(
parseInt
(
"
0x
"
+
sColor
.
slice
(
i
,
i
+
2
)));
}
return
sColorChange
;
}
else
{
return
sColor
;
}
},
//-------------------动画播放--------------------------------
playSpineAnimation
(
item
,
aniName
,
loop
)
{
if
(
!
item
||
!
cc
.
isValid
(
item
))
return
pg
.
logger
.
w
(
"
动画播放失败,传入了错误的item
"
);
if
(
!
aniName
)
return
pg
.
logger
.
w
(
"
动画播放失败,传入了错误的aniName
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
w
(
"
节点已销毁
"
);
let
skl
=
node
.
getComponent
(
sp
.
Skeleton
);
skl
.
setAnimation
(
0
,
aniName
,
loop
);
return
skl
;
},
playDBAnimation
(
item
,
aniName
,
loop
=
-
1
)
{
if
(
!
item
||
!
cc
.
isValid
(
item
))
return
pg
.
logger
.
w
(
"
动画播放失败,传入了错误的item
"
);
if
(
!
aniName
)
return
pg
.
logger
.
w
(
"
动画播放失败,传入了错误的aniName
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
w
(
"
节点已销毁
"
);
let
skl
:
dragonBones
.
ArmatureDisplay
=
node
.
getComponent
(
dragonBones
.
ArmatureDisplay
);
skl
.
playAnimation
(
aniName
,
loop
);
return
skl
;
},
clone
(
node
:
cc
.
Node
)
{
return
cc
.
instantiate
(
node
)
}
},
load
:
{
//资源加载
// loadBundle: function (bundleName) {
// return new Promise((resolve, reject) => {
// // let hallBundle = cc.assetManager.getBundle(`hall`);
// // hallBundle.releaseAll();
// // cc.assetManager.removeBundle(hallBundle);
// let bundle = cc.assetManager.getBundle(bundleName);
// if (bundle) return resolve('');
// cc.assetManager.loadBundle(bundleName, (err, bundle) => {
// if (err) return cc.error(err);
// resolve(bundle);
// });
// });
// },
loadRes
:
function
(
res
,
type
,
bundleName
)
{
//此处需要二次封装,新的存在assetbundle
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
loader
.
loadRes
(
res
,
type
,
(
err
,
data
)
=>
{
if
(
err
&&
!
data
)
return
resolve
(
pg
.
logger
.
d
(
'
loading loadRes error->
'
+
res
));
resolve
(
data
);
});
})
},
loadImg
:
function
(
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
loadRes
(
url
,
cc
.
SpriteFrame
).
then
((
data
)
=>
{
if
(
!
data
||
data
.
length
==
0
)
return
;
resolve
(
data
);
})
})
},
loadPrefab
:
function
(
path
=
""
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
url
=
"
/prefabs/
"
+
path
;
this
.
loadRes
(
url
,
cc
.
Prefab
).
then
((
data
)
=>
{
if
(
!
data
||
data
.
length
==
0
)
return
reject
();
return
resolve
(
cc
.
instantiate
(
data
));
})
})
},
loadNetImg
:
function
(
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
loader
.
load
({
url
},
(
err
,
texture
)
=>
{
if
(
err
&&
!
texture
)
return
resolve
(
pg
.
logger
.
w
(
'
loading loadRes warn->
'
+
texture
));
resolve
(
texture
);
});
})
},
loadDB
(
item
,
config
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
config
.
png
||
!
config
.
ske
||
!
config
.
tex
)
{
return
resolve
(
''
);
}
pg
.
load
.
loadNetRes
(
config
.
png
).
then
((
png
:
any
)
=>
{
pg
.
load
.
loadNetRes
(
config
.
ske
).
then
((
ske
:
any
)
=>
{
pg
.
load
.
loadNetRes
(
config
.
tex
).
then
((
tex
:
any
)
=>
{
var
atlas
=
new
dragonBones
.
DragonBonesAtlasAsset
();
atlas
.
atlasJson
=
JSON
.
stringify
(
tex
.
json
);
atlas
.
texture
=
png
;
var
asset
=
new
dragonBones
.
DragonBonesAsset
();
asset
.
dragonBonesJson
=
JSON
.
stringify
(
ske
.
json
);
let
dragonDisplay
=
item
.
getComponent
(
dragonBones
.
ArmatureDisplay
);
dragonDisplay
.
dragonAtlasAsset
=
atlas
;
dragonDisplay
.
dragonAsset
=
asset
;
//设置
let
defaultArmature
=
ske
.
json
.
armature
[
0
];
//aramture 所有的骨骼名称
dragonDisplay
.
armatureName
=
defaultArmature
.
name
;
resolve
(
defaultArmature
.
animation
[
0
].
name
);
})
})
})
});
},
loadNetRes
:
function
(
url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
url
,
(
err
,
info
)
=>
{
if
(
err
)
return
resolve
(
pg
.
logger
.
w
(
'
loading loadRes warn->
'
+
err
));
resolve
(
info
);
});
})
},
},
localStorage
:
{
//本地存储
setItem
:
function
(
key
,
val
)
{
cc
.
sys
.
localStorage
.
setItem
(
key
,
val
);
},
getItem
:
function
(
key
,
defVal
)
{
return
cc
.
sys
.
localStorage
.
getItem
(
key
)
||
defVal
;
}
},
http
:
{
//http访问
send
:
function
(
type
,
url
,
data
,
callback
)
{
return
new
Promise
((
resolve
)
=>
{
return
setTimeout
(()
=>
{
return
resolve
({
status
:
200
});
},
100
+
Math
.
random
()
*
300
);
let
xhr
=
cc
.
loader
.
getXMLHttpRequest
();
xhr
.
timeout
=
5000
;
xhr
.
responseType
=
"
text
"
;
xhr
.
open
(
type
,
url
,
true
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/x-www-form-urlencoded
"
);
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
!==
4
)
return
;
if
(
xhr
.
status
>=
200
&&
xhr
.
status
<
300
)
{
try
{
let
resp
=
xhr
.
responseText
;
pg
.
logger
.
d
(
"
resp->
"
+
JSON
.
stringify
(
resp
));
callback
(
resp
);
resolve
(
resp
);
}
catch
(
e
)
{
}
}
else
{
}
};
xhr
.
onerror
=
(
e
)
=>
{
pg
.
logger
.
w
(
"
onerror->
"
+
url
);
};
xhr
.
ontimeout
=
(
e
)
=>
{
pg
.
logger
.
w
(
"
ontimeout->
"
+
url
);
};
xhr
.
send
(
data
);
})
}
},
audio
:
{
playAudioByUrl
(
audio_url
,
cb
=
null
,
loadCb
=
null
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
audio_url
)
return
resolve
(
null
);
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
:
any
)
=>
{
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
&&
cb
();
resolve
(
audioId
);
});
loadCb
&&
loadCb
(
audioId
);
});
});
},
playBgAudioByUrl
(
audio_url
,
cb
=
null
,
loadCb
=
null
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
audio_url
)
return
resolve
(
null
);
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
:
any
)
=>
{
const
audioId
=
cc
.
audioEngine
.
playMusic
(
audioClip
,
true
);
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
&&
cb
();
});
loadCb
&&
loadCb
(
audioId
);
resolve
(
audioId
);
});
});
},
stopAudio
(
audioId
)
{
if
(
!
audioId
)
return
;
cc
.
audioEngine
.
stopEffect
(
audioId
);
},
playAudio
(
audioClip
,
cb
=
null
)
{
if
(
audioClip
)
{
const
audioId
=
cc
.
audioEngine
.
playEffect
(
audioClip
,
false
);
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
&&
cb
();
});
}
return
audioId
;
}
},
playLocalAudio
(
audio
:
cc
.
Node
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
id
=
cc
.
audioEngine
.
playEffect
(
audio
.
getComponent
(
cc
.
AudioSource
).
clip
,
false
);
cc
.
audioEngine
.
setFinishCallback
(
id
,
()
=>
{
resolve
(
id
);
});
})
},
getAudioClip
(
audio_url
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
audio_url
)
return
resolve
(
null
);
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
:
any
)
=>
{
resolve
(
audioClip
);
});
});
}
},
time
:
{
delay
(
time
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
resolve
(
''
);
},
time
*
1000
);
});
},
delayCtrl
():
TimeCtrl
{
return
new
TimeCtrl
();
}
},
hw
:
{
playLocalAudio
(
audioName
,
loop
=
false
)
{
console
.
log
(
"
play audio->
"
+
audioName
);
const
audio
=
cc
.
find
(
`Canvas/res/audio/
${
audioName
}
`
).
getComponent
(
cc
.
AudioSource
);
return
new
Promise
((
resolve
,
reject
)
=>
{
const
id
=
cc
.
audioEngine
.
playEffect
(
audio
.
clip
,
loop
);
resolve
(
id
);
})
}
},
event
:
Emitter
.
getInstance
()
};
export
default
pg
;
\ No newline at end of file
assets/cocos_generator/scene/tool/pg.ts.meta
0 → 100644
View file @
072d94db
{
"ver": "1.0.8",
"uuid": "5fd84819-61ef-41a9-82f6-b9db5dcfb6bd",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
creator.d.ts
View file @
072d94db
...
...
@@ -4588,6 +4588,7 @@ declare namespace cc {
/** !#en Returns a normalized vector representing the forward direction (Z axis) of the node in world space.
!#zh 获取节点正前方(z 轴)面对的方向,返回值为世界坐标系下的归一化向量 */
forward
:
Vec3
;
data
:
{
x
:
number
;
y
:
number
;
};
/**
@param name name
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