Commit aa6d55ca authored by haiyoucuv's avatar haiyoucuv

init

parent 614da85d
......@@ -26,7 +26,7 @@
"_active": true,
"_components": [],
"_prefab": {
"__id__": 58
"__id__": 61
},
"_lpos": {
"__type__": "cc.Vec3",
......@@ -57,7 +57,7 @@
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 59
"__id__": 62
},
"_id": "53947ca7-3484-4b53-800d-509405063d68"
},
......@@ -190,7 +190,7 @@
"_priority": 40000,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 812,
"_orthoHeight": 947.8725099601594,
"_near": 0,
"_far": 2000,
"_color": {
......@@ -1309,7 +1309,7 @@
"__id__": 24
},
"LTips": {
"__id__": 49
"__id__": 50
},
"camera": {
"__id__": 4
......@@ -1327,7 +1327,7 @@
"_enabled": true,
"__prefab": null,
"handle": {
"__id__": 53
"__id__": 55
},
"_id": "0elywIxWZJC67+0JraRtKG"
},
......@@ -1341,26 +1341,29 @@
},
"_children": [
{
"__id__": 53
"__id__": 55
}
],
"_active": true,
"_components": [
{
"__id__": 56
"__id__": 58
},
{
"__id__": 57
"__id__": 59
},
{
"__id__": 38
},
{
"__id__": 60
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": -194.414,
"y": -552.498,
"x": -612,
"y": -175,
"z": 0
},
"_lrot": {
......@@ -1405,19 +1408,19 @@
"__id__": 39
},
{
"__id__": 47
"__id__": 48
}
],
"_active": true,
"_components": [
{
"__id__": 50
"__id__": 52
},
{
"__id__": 51
"__id__": 53
},
{
"__id__": 52
"__id__": 54
}
],
"_prefab": null,
......@@ -1509,7 +1512,7 @@
"_priority": 50000,
"_fov": 45,
"_fovAxis": 0,
"_orthoHeight": 812,
"_orthoHeight": 947.8725099601594,
"_near": 1,
"_far": 2000,
"_color": {
......@@ -1560,13 +1563,16 @@
},
{
"__id__": 46
},
{
"__id__": 47
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 264.187,
"y": -552.498,
"x": 612,
"y": -175,
"z": 0
},
"_lrot": {
......@@ -1604,8 +1610,8 @@
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
"width": 200,
"height": 200
},
"_anchorPoint": {
"__type__": "cc.Vec2",
......@@ -1668,6 +1674,36 @@
},
"_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",
"_name": "LTips",
......@@ -1680,17 +1716,20 @@
"_active": true,
"_components": [
{
"__id__": 48
"__id__": 49
},
{
"__id__": 49
"__id__": 50
},
{
"__id__": 51
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 253.913,
"y": -377.918,
"x": 712,
"y": 249.8,
"z": 0
},
"_lrot": {
......@@ -1722,7 +1761,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 47
"__id__": 48
},
"_enabled": true,
"__prefab": null,
......@@ -1733,7 +1772,7 @@
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"x": 1,
"y": 0.5
},
"_id": "36UlLKql1OzYx2glz5wuM/"
......@@ -1744,7 +1783,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 47
"__id__": 48
},
"_enabled": true,
"__prefab": null,
......@@ -1800,6 +1839,36 @@
"_shadowBlur": 2,
"_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",
"_name": "",
......@@ -1880,10 +1949,10 @@
"_active": true,
"_components": [
{
"__id__": 54
"__id__": 56
},
{
"__id__": 55
"__id__": 57
}
],
"_prefab": null,
......@@ -1922,7 +1991,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 53
"__id__": 55
},
"_enabled": true,
"__prefab": null,
......@@ -1944,7 +2013,7 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 53
"__id__": 55
},
"_enabled": true,
"__prefab": null,
......@@ -2038,6 +2107,36 @@
"_atlas": null,
"_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",
"root": null,
......@@ -2049,28 +2148,28 @@
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 60
"__id__": 63
},
"shadows": {
"__id__": 61
"__id__": 64
},
"_skybox": {
"__id__": 62
"__id__": 65
},
"fog": {
"__id__": 63
"__id__": 66
},
"octree": {
"__id__": 64
"__id__": 67
},
"skin": {
"__id__": 65
"__id__": 68
},
"lightProbeInfo": {
"__id__": 66
"__id__": 69
},
"postSettings": {
"__id__": 67
"__id__": 70
},
"bakedWithStationaryMainLight": false,
"bakedWithHighpLightmap": false
......
......@@ -8,6 +8,7 @@ import { PoolManager } from "./PoolManager";
import { FoodType, DirectionType } from "./Enums";
import { isIntersect } from "./uitl";
import { MainGame } from "./MainGame";
import { executePreFrame, getItemGenerator } from "../../Utils/ExecutePreFrame";
const { ccclass, property } = _decorator;
......@@ -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();
MainGame.ins.fondManger.setFood(
math.randomRangeInt(this.b.x - 10, this.b.x + 11),
......@@ -497,31 +489,8 @@ export class Animal extends Component {
* 初始化食物
*/
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
function* _getItemGenerator(length: number) {
import { Component } from "cc";
export function* getItemGenerator(length: number, func: (index: number) => any) {
for (let i = 0; i < length; i++) {
yield this._initItem(i);
yield func(i);
}
this.ready = true;
}
function executePreFrame(generator: Generator, duration: number) {
export function executePreFrame(generator: Generator, duration: number, context: Component) {
return new Promise<void>((resolve, reject) => {
let gen = generator;
// 创建执行函数
let execute = () => {
// 执行之前,先记录开始时间戳
let startTime = new Date().getTime();
let startTime = Date.now();
// 然后一直从 Generator 中获取已经拆分好的代码段出来执行
for (let iter = gen.next(); ; iter = gen.next()) {
......@@ -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();
});
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment