Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MingSnake_241120
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
SparkProjects
MingSnake_241120
Commits
aa6d55ca
Commit
aa6d55ca
authored
Nov 20, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
614da85d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
82 deletions
+149
-82
MainGame.scene
assets/Bundles/MainGame/MainGame.scene
+137
-38
Animal.ts
assets/Scripts/Scenes/MainGame/Animal.ts
+4
-35
ExecutePreFrame.ts
assets/Scripts/Utils/ExecutePreFrame.ts
+8
-9
No files found.
assets/Bundles/MainGame/MainGame.scene
View file @
aa6d55ca
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
"_active": true,
"_active": true,
"_components": [],
"_components": [],
"_prefab": {
"_prefab": {
"__id__":
58
"__id__":
61
},
},
"_lpos": {
"_lpos": {
"__type__": "cc.Vec3",
"__type__": "cc.Vec3",
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
},
},
"autoReleaseAssets": false,
"autoReleaseAssets": false,
"_globals": {
"_globals": {
"__id__":
59
"__id__":
62
},
},
"_id": "53947ca7-3484-4b53-800d-509405063d68"
"_id": "53947ca7-3484-4b53-800d-509405063d68"
},
},
...
@@ -190,7 +190,7 @@
...
@@ -190,7 +190,7 @@
"_priority": 40000,
"_priority": 40000,
"_fov": 45,
"_fov": 45,
"_fovAxis": 0,
"_fovAxis": 0,
"_orthoHeight":
812
,
"_orthoHeight":
947.8725099601594
,
"_near": 0,
"_near": 0,
"_far": 2000,
"_far": 2000,
"_color": {
"_color": {
...
@@ -1309,7 +1309,7 @@
...
@@ -1309,7 +1309,7 @@
"__id__": 24
"__id__": 24
},
},
"LTips": {
"LTips": {
"__id__":
49
"__id__":
50
},
},
"camera": {
"camera": {
"__id__": 4
"__id__": 4
...
@@ -1327,7 +1327,7 @@
...
@@ -1327,7 +1327,7 @@
"_enabled": true,
"_enabled": true,
"__prefab": null,
"__prefab": null,
"handle": {
"handle": {
"__id__": 5
3
"__id__": 5
5
},
},
"_id": "0elywIxWZJC67+0JraRtKG"
"_id": "0elywIxWZJC67+0JraRtKG"
},
},
...
@@ -1341,26 +1341,29 @@
...
@@ -1341,26 +1341,29 @@
},
},
"_children": [
"_children": [
{
{
"__id__": 5
3
"__id__": 5
5
}
}
],
],
"_active": true,
"_active": true,
"_components": [
"_components": [
{
{
"__id__": 5
6
"__id__": 5
8
},
},
{
{
"__id__": 5
7
"__id__": 5
9
},
},
{
{
"__id__": 38
"__id__": 38
},
{
"__id__": 60
}
}
],
],
"_prefab": null,
"_prefab": null,
"_lpos": {
"_lpos": {
"__type__": "cc.Vec3",
"__type__": "cc.Vec3",
"x": -
194.414
,
"x": -
612
,
"y": -
552.498
,
"y": -
175
,
"z": 0
"z": 0
},
},
"_lrot": {
"_lrot": {
...
@@ -1405,19 +1408,19 @@
...
@@ -1405,19 +1408,19 @@
"__id__": 39
"__id__": 39
},
},
{
{
"__id__": 4
7
"__id__": 4
8
}
}
],
],
"_active": true,
"_active": true,
"_components": [
"_components": [
{
{
"__id__": 5
0
"__id__": 5
2
},
},
{
{
"__id__": 5
1
"__id__": 5
3
},
},
{
{
"__id__": 5
2
"__id__": 5
4
}
}
],
],
"_prefab": null,
"_prefab": null,
...
@@ -1509,7 +1512,7 @@
...
@@ -1509,7 +1512,7 @@
"_priority": 50000,
"_priority": 50000,
"_fov": 45,
"_fov": 45,
"_fovAxis": 0,
"_fovAxis": 0,
"_orthoHeight":
812
,
"_orthoHeight":
947.8725099601594
,
"_near": 1,
"_near": 1,
"_far": 2000,
"_far": 2000,
"_color": {
"_color": {
...
@@ -1560,13 +1563,16 @@
...
@@ -1560,13 +1563,16 @@
},
},
{
{
"__id__": 46
"__id__": 46
},
{
"__id__": 47
}
}
],
],
"_prefab": null,
"_prefab": null,
"_lpos": {
"_lpos": {
"__type__": "cc.Vec3",
"__type__": "cc.Vec3",
"x":
264.187
,
"x":
612
,
"y": -
552.498
,
"y": -
175
,
"z": 0
"z": 0
},
},
"_lrot": {
"_lrot": {
...
@@ -1604,8 +1610,8 @@
...
@@ -1604,8 +1610,8 @@
"__prefab": null,
"__prefab": null,
"_contentSize": {
"_contentSize": {
"__type__": "cc.Size",
"__type__": "cc.Size",
"width":
1
00,
"width":
2
00,
"height":
1
00
"height":
2
00
},
},
"_anchorPoint": {
"_anchorPoint": {
"__type__": "cc.Vec2",
"__type__": "cc.Vec2",
...
@@ -1668,6 +1674,36 @@
...
@@ -1668,6 +1674,36 @@
},
},
"_id": "cbuYoeJJBN/Z/dZ6F3l5A5"
"_id": "cbuYoeJJBN/Z/dZ6F3l5A5"
},
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 43
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 36,
"_target": null,
"_left": 0,
"_right": 100,
"_top": 0,
"_bottom": 100,
"_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": "df80urB71OA7+3JSH/ujkz"
},
{
{
"__type__": "cc.Node",
"__type__": "cc.Node",
"_name": "LTips",
"_name": "LTips",
...
@@ -1680,17 +1716,20 @@
...
@@ -1680,17 +1716,20 @@
"_active": true,
"_active": true,
"_components": [
"_components": [
{
{
"__id__": 4
8
"__id__": 4
9
},
},
{
{
"__id__": 49
"__id__": 50
},
{
"__id__": 51
}
}
],
],
"_prefab": null,
"_prefab": null,
"_lpos": {
"_lpos": {
"__type__": "cc.Vec3",
"__type__": "cc.Vec3",
"x":
253.913
,
"x":
712
,
"y":
-377.91
8,
"y":
249.
8,
"z": 0
"z": 0
},
},
"_lrot": {
"_lrot": {
...
@@ -1722,7 +1761,7 @@
...
@@ -1722,7 +1761,7 @@
"_objFlags": 0,
"_objFlags": 0,
"__editorExtras__": {},
"__editorExtras__": {},
"node": {
"node": {
"__id__": 4
7
"__id__": 4
8
},
},
"_enabled": true,
"_enabled": true,
"__prefab": null,
"__prefab": null,
...
@@ -1733,7 +1772,7 @@
...
@@ -1733,7 +1772,7 @@
},
},
"_anchorPoint": {
"_anchorPoint": {
"__type__": "cc.Vec2",
"__type__": "cc.Vec2",
"x":
0.5
,
"x":
1
,
"y": 0.5
"y": 0.5
},
},
"_id": "36UlLKql1OzYx2glz5wuM/"
"_id": "36UlLKql1OzYx2glz5wuM/"
...
@@ -1744,7 +1783,7 @@
...
@@ -1744,7 +1783,7 @@
"_objFlags": 0,
"_objFlags": 0,
"__editorExtras__": {},
"__editorExtras__": {},
"node": {
"node": {
"__id__": 4
7
"__id__": 4
8
},
},
"_enabled": true,
"_enabled": true,
"__prefab": null,
"__prefab": null,
...
@@ -1800,6 +1839,36 @@
...
@@ -1800,6 +1839,36 @@
"_shadowBlur": 2,
"_shadowBlur": 2,
"_id": "19rM5WBaxLeLzdAeJnwo00"
"_id": "19rM5WBaxLeLzdAeJnwo00"
},
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 48
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 33,
"_target": null,
"_left": 0,
"_right": 100,
"_top": 100,
"_bottom": -28.117999999999995,
"_horizontalCenter": 0,
"_verticalCenter": 0,
"_isAbsLeft": true,
"_isAbsRight": true,
"_isAbsTop": true,
"_isAbsBottom": true,
"_isAbsHorizontalCenter": true,
"_isAbsVerticalCenter": true,
"_originalWidth": 0,
"_originalHeight": 50.4,
"_alignMode": 2,
"_lockFlags": 0,
"_id": "ecH3oPhpZGbLylQqewE5v7"
},
{
{
"__type__": "cc.UITransform",
"__type__": "cc.UITransform",
"_name": "",
"_name": "",
...
@@ -1880,10 +1949,10 @@
...
@@ -1880,10 +1949,10 @@
"_active": true,
"_active": true,
"_components": [
"_components": [
{
{
"__id__": 5
4
"__id__": 5
6
},
},
{
{
"__id__": 5
5
"__id__": 5
7
}
}
],
],
"_prefab": null,
"_prefab": null,
...
@@ -1922,7 +1991,7 @@
...
@@ -1922,7 +1991,7 @@
"_objFlags": 0,
"_objFlags": 0,
"__editorExtras__": {},
"__editorExtras__": {},
"node": {
"node": {
"__id__": 5
3
"__id__": 5
5
},
},
"_enabled": true,
"_enabled": true,
"__prefab": null,
"__prefab": null,
...
@@ -1944,7 +2013,7 @@
...
@@ -1944,7 +2013,7 @@
"_objFlags": 0,
"_objFlags": 0,
"__editorExtras__": {},
"__editorExtras__": {},
"node": {
"node": {
"__id__": 5
3
"__id__": 5
5
},
},
"_enabled": true,
"_enabled": true,
"__prefab": null,
"__prefab": null,
...
@@ -2038,6 +2107,36 @@
...
@@ -2038,6 +2107,36 @@
"_atlas": null,
"_atlas": null,
"_id": "66XQUcIMlDkJvkLa8btCt/"
"_id": "66XQUcIMlDkJvkLa8btCt/"
},
},
{
"__type__": "cc.Widget",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 39
},
"_enabled": true,
"__prefab": null,
"_alignFlags": 12,
"_target": null,
"_left": 100,
"_right": 0,
"_top": 0,
"_bottom": 100,
"_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": "35Jp/KTfNHbqtc+8xUyurH"
},
{
{
"__type__": "cc.PrefabInfo",
"__type__": "cc.PrefabInfo",
"root": null,
"root": null,
...
@@ -2049,28 +2148,28 @@
...
@@ -2049,28 +2148,28 @@
{
{
"__type__": "cc.SceneGlobals",
"__type__": "cc.SceneGlobals",
"ambient": {
"ambient": {
"__id__": 6
0
"__id__": 6
3
},
},
"shadows": {
"shadows": {
"__id__": 6
1
"__id__": 6
4
},
},
"_skybox": {
"_skybox": {
"__id__": 6
2
"__id__": 6
5
},
},
"fog": {
"fog": {
"__id__": 6
3
"__id__": 6
6
},
},
"octree": {
"octree": {
"__id__": 6
4
"__id__": 6
7
},
},
"skin": {
"skin": {
"__id__": 6
5
"__id__": 6
8
},
},
"lightProbeInfo": {
"lightProbeInfo": {
"__id__": 6
6
"__id__": 6
9
},
},
"postSettings": {
"postSettings": {
"__id__":
67
"__id__":
70
},
},
"bakedWithStationaryMainLight": false,
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
"bakedWithHighpLightmap": false
...
...
assets/Scripts/Scenes/MainGame/Animal.ts
View file @
aa6d55ca
...
@@ -8,6 +8,7 @@ import { PoolManager } from "./PoolManager";
...
@@ -8,6 +8,7 @@ import { PoolManager } from "./PoolManager";
import
{
FoodType
,
DirectionType
}
from
"./Enums"
;
import
{
FoodType
,
DirectionType
}
from
"./Enums"
;
import
{
isIntersect
}
from
"./uitl"
;
import
{
isIntersect
}
from
"./uitl"
;
import
{
MainGame
}
from
"./MainGame"
;
import
{
MainGame
}
from
"./MainGame"
;
import
{
executePreFrame
,
getItemGenerator
}
from
"../../Utils/ExecutePreFrame"
;
const
{
ccclass
,
property
}
=
_decorator
;
const
{
ccclass
,
property
}
=
_decorator
;
...
@@ -472,19 +473,10 @@ export class Animal extends Component {
...
@@ -472,19 +473,10 @@ export class Animal extends Component {
);
);
}
}
/**
* 生成食物迭代器
*/
private
*
_getItemGenerator
(
count
:
number
)
{
for
(
let
i
=
0
;
i
<
count
;
i
++
)
{
yield
this
.
_initItem
(
i
);
}
}
/**
/**
* 初始化食物
* 初始化食物
*/
*/
private
_initItem
(
index
:
number
)
{
initItem
=
(
index
:
number
)
=>
{
this
.
b
=
this
.
Bodys
[
index
].
getPosition
();
this
.
b
=
this
.
Bodys
[
index
].
getPosition
();
MainGame
.
ins
.
fondManger
.
setFood
(
MainGame
.
ins
.
fondManger
.
setFood
(
math
.
randomRangeInt
(
this
.
b
.
x
-
10
,
this
.
b
.
x
+
11
),
math
.
randomRangeInt
(
this
.
b
.
x
-
10
,
this
.
b
.
x
+
11
),
...
@@ -497,31 +489,8 @@ export class Animal extends Component {
...
@@ -497,31 +489,8 @@ export class Animal extends Component {
* 初始化食物
* 初始化食物
*/
*/
async
initFond
(
count
:
number
)
{
async
initFond
(
count
:
number
)
{
await
this
.
executePreFrame
(
this
.
_getItemGenerator
(
count
),
1
);
await
executePreFrame
(
getItemGenerator
(
count
,
this
.
initItem
),
1
,
this
);
this
.
ready
=
true
;
}
}
/**
* 分帧执行
*/
executePreFrame
(
generator
:
Generator
,
frameTime
:
number
):
Promise
<
boolean
>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
iter
=
generator
;
const
next
=
()
=>
{
const
startTime
=
new
Date
().
getTime
();
for
(
let
result
=
iter
.
next
();
;
result
=
iter
.
next
())
{
if
(
!
result
||
result
.
done
)
{
resolve
(
true
);
return
;
}
if
(
new
Date
().
getTime
()
-
startTime
>
frameTime
)
{
this
.
scheduleOnce
(()
=>
{
next
();
});
return
;
}
}
};
next
();
});
}
}
}
\ No newline at end of file
assets/Scripts/Utils/ExecutePreFrame.ts
View file @
aa6d55ca
function
*
_getItemGenerator
(
length
:
number
)
{
import
{
Component
}
from
"cc"
;
export
function
*
getItemGenerator
(
length
:
number
,
func
:
(
index
:
number
)
=>
any
)
{
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
yield
this
.
_initItem
(
i
);
yield
func
(
i
);
}
}
this
.
ready
=
true
;
}
}
export
function
executePreFrame
(
generator
:
Generator
,
duration
:
number
,
context
:
Component
)
{
function
executePreFrame
(
generator
:
Generator
,
duration
:
number
)
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
return
new
Promise
<
void
>
((
resolve
,
reject
)
=>
{
let
gen
=
generator
;
let
gen
=
generator
;
// 创建执行函数
// 创建执行函数
let
execute
=
()
=>
{
let
execute
=
()
=>
{
// 执行之前,先记录开始时间戳
// 执行之前,先记录开始时间戳
let
startTime
=
new
Date
().
getTime
();
let
startTime
=
Date
.
now
();
// 然后一直从 Generator 中获取已经拆分好的代码段出来执行
// 然后一直从 Generator 中获取已经拆分好的代码段出来执行
for
(
let
iter
=
gen
.
next
();
;
iter
=
gen
.
next
())
{
for
(
let
iter
=
gen
.
next
();
;
iter
=
gen
.
next
())
{
...
@@ -28,10 +27,10 @@ function executePreFrame(generator: Generator, duration: number) {
...
@@ -28,10 +27,10 @@ function executePreFrame(generator: Generator, duration: number) {
// 每执行完一段小代码段,都检查一下是否
// 每执行完一段小代码段,都检查一下是否
// 已经超过我们分配给本帧,这些小代码端的最大可执行时间
// 已经超过我们分配给本帧,这些小代码端的最大可执行时间
if
(
new
Date
().
getTime
()
-
startTime
>
duration
)
{
if
(
Date
.
now
()
-
startTime
>
duration
)
{
// 如果超过了,那么本帧就不在执行,开定时器,让下一帧再执行
// 如果超过了,那么本帧就不在执行,开定时器,让下一帧再执行
this
.
scheduleOnce
(()
=>
{
context
.
scheduleOnce
(()
=>
{
execute
();
execute
();
});
});
return
;
return
;
...
...
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