@cjhd/cj-ecs 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/common/component/MoveComponent.d.ts +141 -0
- package/assets/common/component/NodeComponent.d.ts +98 -0
- package/assets/common/system/MoveSystem.d.ts +17 -0
- package/assets/ecs/EcsComponent.d.ts +89 -0
- package/assets/ecs/{EcsDirty.ts → EcsDirty.d.ts} +340 -459
- package/assets/ecs/EcsEntity.d.ts +148 -0
- package/assets/ecs/EcsSingleton.d.ts +3 -0
- package/assets/ecs/EcsSystem.d.ts +96 -0
- package/assets/ecs.d.ts +126 -0
- package/assets/lib/EcsCache.d.ts +24 -0
- package/assets/lib/EcsFilter.d.ts +57 -0
- package/assets/lib/EcsManager.d.ts +251 -0
- package/assets/lib/{EcsObject.ts → EcsObject.d.ts} +360 -422
- package/assets/lib/EcsTimer.d.ts +119 -0
- package/assets/lib/EcsTween.d.ts +168 -0
- package/assets/lib/EcsUtils.d.ts +82 -0
- package/dist/cocos/assets/common/component/MoveComponent.js +4 -0
- package/dist/cocos/assets/common/component/NodeComponent.js +4 -0
- package/dist/cocos/assets/common/system/MoveSystem.js +2 -0
- package/dist/cocos/assets/ecs/EcsComponent.js +4 -0
- package/dist/cocos/assets/ecs/EcsDirty.js +4 -0
- package/dist/cocos/assets/ecs/EcsEntity.js +4 -0
- package/dist/cocos/assets/ecs/EcsSingleton.js +4 -0
- package/dist/cocos/assets/ecs/EcsSystem.js +2 -0
- package/dist/cocos/assets/ecs.js +2 -0
- package/dist/cocos/assets/lib/EcsCache.js +2 -0
- package/dist/cocos/assets/lib/EcsFilter.js +2 -0
- package/dist/cocos/assets/lib/EcsManager.js +4 -0
- package/dist/cocos/assets/lib/EcsObject.js +4 -0
- package/dist/cocos/assets/lib/EcsTimer.js +4 -0
- package/dist/cocos/assets/lib/EcsTween.js +4 -0
- package/dist/cocos/assets/lib/EcsUtils.js +2 -0
- package/dist/cocos/index.js +4 -0
- package/{index.ts → index.d.ts} +14 -33
- package/package.json +27 -7
- package/assets/common/component/MoveComponent.ts +0 -292
- package/assets/common/component/MoveComponent.ts.meta +0 -9
- package/assets/common/component/NodeComponent.ts +0 -315
- package/assets/common/component/NodeComponent.ts.meta +0 -9
- package/assets/common/component.meta +0 -12
- package/assets/common/system/MoveSystem.ts +0 -108
- package/assets/common/system/MoveSystem.ts.meta +0 -9
- package/assets/common/system.meta +0 -12
- package/assets/common.meta +0 -12
- package/assets/ecs/EcsComponent.ts +0 -244
- package/assets/ecs/EcsComponent.ts.meta +0 -9
- package/assets/ecs/EcsDirty.ts.meta +0 -9
- package/assets/ecs/EcsEntity.ts +0 -430
- package/assets/ecs/EcsEntity.ts.meta +0 -9
- package/assets/ecs/EcsSingleton.ts +0 -6
- package/assets/ecs/EcsSingleton.ts.meta +0 -9
- package/assets/ecs/EcsSystem.ts +0 -191
- package/assets/ecs/EcsSystem.ts.meta +0 -9
- package/assets/ecs.meta +0 -12
- package/assets/ecs.ts +0 -339
- package/assets/ecs.ts.meta +0 -9
- package/assets/lib/EcsCache.ts +0 -43
- package/assets/lib/EcsCache.ts.meta +0 -9
- package/assets/lib/EcsFilter.ts +0 -210
- package/assets/lib/EcsFilter.ts.meta +0 -9
- package/assets/lib/EcsManager.ts +0 -502
- package/assets/lib/EcsManager.ts.meta +0 -9
- package/assets/lib/EcsObject.ts.meta +0 -9
- package/assets/lib/EcsTimer.ts +0 -239
- package/assets/lib/EcsTimer.ts.meta +0 -9
- package/assets/lib/EcsTween.ts +0 -486
- package/assets/lib/EcsTween.ts.meta +0 -9
- package/assets/lib/EcsUtils.ts +0 -352
- package/assets/lib/EcsUtils.ts.meta +0 -9
- package/assets/lib.meta +0 -12
- package/assets.meta +0 -9
- package/index.ts.meta +0 -9
- package/package.json.meta +0 -11
- /package/{.cj-ecs.md → README.md} +0 -0
package/assets/lib/EcsTween.ts
DELETED
|
@@ -1,486 +0,0 @@
|
|
|
1
|
-
import { math } from 'cc';
|
|
2
|
-
import { EcsComponent } from '../ecs/EcsComponent';
|
|
3
|
-
|
|
4
|
-
// 将Base(类)对应实例中所有值为Type类型的key去除,返回string的复合类型(被过滤后的key)
|
|
5
|
-
type KeyofFilterType<Base, ExcludedType> = {
|
|
6
|
-
[key in keyof Base]: Base[key] extends ExcludedType ? never : key;
|
|
7
|
-
}[keyof Base];
|
|
8
|
-
|
|
9
|
-
// 将Base(类)对应实例中所有键为Key类型的key去除,返回string的复合类型(被过滤后的key)
|
|
10
|
-
type KeyofFilterKey<Base, ExcludedKey> = {
|
|
11
|
-
[key in keyof Base]: key extends ExcludedKey ? never : key;
|
|
12
|
-
}[keyof Base];
|
|
13
|
-
|
|
14
|
-
type ExcludedKey = keyof EcsComponent; //| keyof INodeReadonly;
|
|
15
|
-
type PropType<Base> = Partial<
|
|
16
|
-
Pick<Base, KeyofFilterType<
|
|
17
|
-
Pick<Base, KeyofFilterKey<Base, ExcludedKey>>,
|
|
18
|
-
Function | string | object
|
|
19
|
-
>>
|
|
20
|
-
>;
|
|
21
|
-
|
|
22
|
-
interface ITweenOption {
|
|
23
|
-
/**
|
|
24
|
-
* @en
|
|
25
|
-
* Easing function, you can pass in a string or custom function.
|
|
26
|
-
* @zh
|
|
27
|
-
* 缓动函数,可以使用已有的,也可以传入自定义的函数。
|
|
28
|
-
*/
|
|
29
|
-
easing?: ((k: number) => number);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
type IObject = { [key: string]: any };
|
|
33
|
-
|
|
34
|
-
enum ActionType {
|
|
35
|
-
None,
|
|
36
|
-
To,
|
|
37
|
-
By
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// 动作基类
|
|
41
|
-
class Action {
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// 属性动作
|
|
45
|
-
class PropAction extends Action {
|
|
46
|
-
type: ActionType = ActionType.None;
|
|
47
|
-
/**进度 */
|
|
48
|
-
ratio: number = 0;
|
|
49
|
-
/**时间 */
|
|
50
|
-
time: number = 0;
|
|
51
|
-
/**结束属性 */
|
|
52
|
-
end: { [key: string]: any } | null = null;
|
|
53
|
-
/**开始属性 */
|
|
54
|
-
start: { [key: string]: any } | null = null;
|
|
55
|
-
/**缓动函数 */
|
|
56
|
-
easing: ITweenOption['easing'] | null = null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 贝塞尔属性动作
|
|
60
|
-
class BezierPropAction extends PropAction {
|
|
61
|
-
/**控制位属性 */
|
|
62
|
-
control: { [key: string]: any } | null = null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// 等待动作
|
|
66
|
-
class DelayAction extends Action {
|
|
67
|
-
delay: number = 0;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 回调动作
|
|
71
|
-
class CallAction extends Action {
|
|
72
|
-
callback: Function | null = null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let tid = 0;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 缓动
|
|
79
|
-
*/
|
|
80
|
-
export class Tween<T extends EcsComponent> {
|
|
81
|
-
static step(tween: Tween<EcsComponent>, dt: number) {
|
|
82
|
-
const action = tween.actions[0];
|
|
83
|
-
if (action instanceof DelayAction) {
|
|
84
|
-
action.delay -= dt;
|
|
85
|
-
if (action.delay <= 0) {
|
|
86
|
-
tween.actions.shift();
|
|
87
|
-
}
|
|
88
|
-
} else if (action instanceof CallAction) {
|
|
89
|
-
if (action.callback) {
|
|
90
|
-
tween.actions.shift();
|
|
91
|
-
action.callback();
|
|
92
|
-
}
|
|
93
|
-
} else if (action instanceof PropAction) {
|
|
94
|
-
if (tween.target.isValid) {
|
|
95
|
-
// 整体进度
|
|
96
|
-
action.ratio = Math.min(action.ratio + dt / action.time, 1);
|
|
97
|
-
// 完成移除
|
|
98
|
-
if (action.ratio >= 1) {
|
|
99
|
-
tween.actions.shift();
|
|
100
|
-
}
|
|
101
|
-
// 应用缓动函数后的进度
|
|
102
|
-
const ratio = action.easing ? action.easing(action.ratio) : action.ratio;
|
|
103
|
-
// 计算动态数值
|
|
104
|
-
if (!action.start) {
|
|
105
|
-
// 初始化起点坐标
|
|
106
|
-
action.start = Tween.getStartValue(action.end!, tween.target);
|
|
107
|
-
if (action.type === ActionType.By) {
|
|
108
|
-
if (action instanceof BezierPropAction) {
|
|
109
|
-
action.end = Tween.getEndValue(action.end!, tween.target);
|
|
110
|
-
action.control = Tween.getStartValue(action.control!, tween.target);
|
|
111
|
-
} else {
|
|
112
|
-
action.end = Tween.getEndValue(action.end!, tween.target);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
// 插值运算
|
|
117
|
-
if (action instanceof BezierPropAction) {
|
|
118
|
-
Tween.bezier(ratio, action.start, action.control!, action.end!, tween.target);
|
|
119
|
-
} else {
|
|
120
|
-
Tween.lerp(ratio, action.start, action.end!, tween.target);
|
|
121
|
-
}
|
|
122
|
-
} else {
|
|
123
|
-
tween.actions.shift();
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
tween.actions.shift();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return tween.actions.length > 0;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private _id = ++tid;
|
|
133
|
-
public get id() {
|
|
134
|
-
return this._id;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**动作列表 */
|
|
138
|
-
private actions: Action[] = [];
|
|
139
|
-
|
|
140
|
-
private _target!: T;
|
|
141
|
-
public get target(): T {
|
|
142
|
-
return this._target;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
constructor(target: T) {
|
|
146
|
-
this._target = target;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 等待
|
|
151
|
-
* @param delay
|
|
152
|
-
* @returns
|
|
153
|
-
*/
|
|
154
|
-
delay(delay: number) {
|
|
155
|
-
const action = new DelayAction();
|
|
156
|
-
action.delay = delay;
|
|
157
|
-
this.actions.push(action);
|
|
158
|
-
return this;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 执行
|
|
163
|
-
* @param callback
|
|
164
|
-
* @returns
|
|
165
|
-
*/
|
|
166
|
-
call(callback: Function) {
|
|
167
|
-
const action = new CallAction();
|
|
168
|
-
action.callback = callback;
|
|
169
|
-
this.actions.push(action);
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* 绝对缓动
|
|
175
|
-
* @param time 时间
|
|
176
|
-
* @param props 属性(只能是简单类型)
|
|
177
|
-
* @param opts 选项
|
|
178
|
-
* @returns
|
|
179
|
-
*/
|
|
180
|
-
to(time: number, props: PropType<T>, opts?: ITweenOption) {
|
|
181
|
-
const action = new PropAction();
|
|
182
|
-
action.type = ActionType.To;
|
|
183
|
-
action.ratio = 0;
|
|
184
|
-
action.time = Math.max(time, 0);
|
|
185
|
-
action.end = Tween.getCopyValue(props);
|
|
186
|
-
action.start = null;// 运行时动态计算
|
|
187
|
-
action.easing = opts?.easing || null;
|
|
188
|
-
this.actions.push(action);
|
|
189
|
-
return this;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* 相对缓动
|
|
194
|
-
* @param time 时间
|
|
195
|
-
* @param props 属性(只能是简单类型)
|
|
196
|
-
* @param opts 选项
|
|
197
|
-
* @returns
|
|
198
|
-
*/
|
|
199
|
-
by<T extends EcsComponent>(time: number, target: T, props: PropType<T>, opts?: ITweenOption) {
|
|
200
|
-
const action = new PropAction();
|
|
201
|
-
action.type = ActionType.By;
|
|
202
|
-
action.ratio = 0;
|
|
203
|
-
action.time = Math.max(time, 0);
|
|
204
|
-
action.end = Tween.getCopyValue(props);// 运行时动态计算
|
|
205
|
-
action.start = null;// 运行时动态计算
|
|
206
|
-
action.easing = opts?.easing || null;
|
|
207
|
-
this.actions.push(action);
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* 绝对贝塞尔缓动
|
|
213
|
-
* @param time 时间
|
|
214
|
-
* @param target 目标
|
|
215
|
-
* @param props 属性(只能是简单类型)
|
|
216
|
-
* @param control 控制值(影响曲线幅度)
|
|
217
|
-
* @param opts 选项
|
|
218
|
-
* @returns
|
|
219
|
-
*/
|
|
220
|
-
bezierTo<T extends EcsComponent, K extends PropType<T>>(time: number, target: T, props: K, control: Required<K>, opts?: ITweenOption) {
|
|
221
|
-
const action = new BezierPropAction();
|
|
222
|
-
action.type = ActionType.To;
|
|
223
|
-
action.ratio = 0;
|
|
224
|
-
action.time = Math.max(time, 0);
|
|
225
|
-
action.control = Tween.getStartValue(props, control);
|
|
226
|
-
action.end = Tween.getCopyValue(props);
|
|
227
|
-
action.start = null;// 运行时动态计算
|
|
228
|
-
action.easing = opts?.easing || null;
|
|
229
|
-
this.actions.push(action);
|
|
230
|
-
return this;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* 相对贝塞尔缓动
|
|
235
|
-
* @param time 时间
|
|
236
|
-
* @param target 目标
|
|
237
|
-
* @param props 属性(只能是简单类型)
|
|
238
|
-
* @param control 控制值(影响曲线幅度)
|
|
239
|
-
* @param opts 选项
|
|
240
|
-
*/
|
|
241
|
-
bezierBy<T extends EcsComponent, K extends PropType<T>>(time: number, target: T, props: K, control: Required<K>, opts?: ITweenOption) {
|
|
242
|
-
const action = new BezierPropAction();
|
|
243
|
-
action.type = ActionType.By;
|
|
244
|
-
action.ratio = 0;
|
|
245
|
-
action.time = Math.max(time, 0);
|
|
246
|
-
action.end = Tween.getCopyValue(props);// 运行时动态计算
|
|
247
|
-
action.control = Tween.getCopyValue(control);// 运行时动态计算
|
|
248
|
-
action.start = null;// 运行时动态计算
|
|
249
|
-
action.easing = opts?.easing || null;
|
|
250
|
-
this.actions.push(action);
|
|
251
|
-
this.actions.push(action);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* 拷贝数值
|
|
256
|
-
*/
|
|
257
|
-
private static getCopyValue(props: IObject) {
|
|
258
|
-
const copy: IObject = {};
|
|
259
|
-
|
|
260
|
-
for (const key in props) {
|
|
261
|
-
if (Object.prototype.hasOwnProperty.call(props, key)) {
|
|
262
|
-
if (typeof props[key] === 'number' || typeof props[key] === 'boolean') {
|
|
263
|
-
copy[key] = props[key];
|
|
264
|
-
} else if (props[key] && typeof props[key] === 'object') {
|
|
265
|
-
copy[key] = this.getCopyValue(props[key]);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return copy;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* 获取目标值
|
|
274
|
-
* @param props 差值
|
|
275
|
-
* @param target 原始值
|
|
276
|
-
*/
|
|
277
|
-
private static getEndValue(props: IObject, target: IObject = {}) {
|
|
278
|
-
const end: IObject = {};
|
|
279
|
-
|
|
280
|
-
for (const key in props) {
|
|
281
|
-
if (Object.prototype.hasOwnProperty.call(props, key)) {
|
|
282
|
-
if (typeof props[key] === 'number') {
|
|
283
|
-
end[key] = props[key] + (target[key] || 0);
|
|
284
|
-
} else if (typeof props[key] === 'boolean') {
|
|
285
|
-
end[key] = props[key];
|
|
286
|
-
} else if (props[key] && typeof props[key] === 'object') {
|
|
287
|
-
end[key] = this.getEndValue(props[key], target[key]);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return end;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* 获取初始值
|
|
296
|
-
* @param props 作为过滤使用
|
|
297
|
-
* @param target 原始值
|
|
298
|
-
*/
|
|
299
|
-
private static getStartValue(props: IObject, target: IObject = {}) {
|
|
300
|
-
const start: IObject = {};
|
|
301
|
-
|
|
302
|
-
for (const key in props) {
|
|
303
|
-
if (Object.prototype.hasOwnProperty.call(props, key)) {
|
|
304
|
-
if (typeof props[key] === 'number') {
|
|
305
|
-
start[key] = target[key] || 0;
|
|
306
|
-
} else if (typeof props[key] === 'boolean') {
|
|
307
|
-
start[key] = target[key] || false;
|
|
308
|
-
} else if (props[key] && typeof props[key] === 'object') {
|
|
309
|
-
start[key] = this.getStartValue(props[key], target[key]);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return start;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
private static lerp(ratio: number, start: IObject, end: IObject, data: IObject = {}) {
|
|
317
|
-
for (const key in start) {
|
|
318
|
-
if (Object.prototype.hasOwnProperty.call(start, key)) {
|
|
319
|
-
if (typeof start[key] === 'number') {
|
|
320
|
-
data[key] = math.lerp(start[key], end[key], ratio);
|
|
321
|
-
} else if (typeof start[key] === 'boolean') {
|
|
322
|
-
data[key] = ratio >= 1 ? end[key] : start[key];
|
|
323
|
-
} else if (start[key] && typeof start[key] === 'object') {
|
|
324
|
-
this.lerp(ratio, start[key], end[key], data[key]);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
private static bezier(ratio: number, start: IObject, control: IObject, end: IObject, data: IObject = {}) {
|
|
331
|
-
for (const key in start) {
|
|
332
|
-
if (Object.prototype.hasOwnProperty.call(start, key)) {
|
|
333
|
-
if (typeof start[key] === 'number') {
|
|
334
|
-
const n1 = math.lerp(start[key], control[key], ratio);
|
|
335
|
-
const n2 = math.lerp(control[key], end[key], ratio);
|
|
336
|
-
data[key] = math.lerp(n1, n2, ratio);
|
|
337
|
-
} else if (typeof start[key] === 'boolean') {
|
|
338
|
-
data[key] = ratio >= 1 ? end[key] : start[key];
|
|
339
|
-
} else if (start[key] && typeof start[key] === 'object') {
|
|
340
|
-
this.lerp(ratio, start[key], end[key], data[key]);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* 创建一个缓动
|
|
349
|
-
*/
|
|
350
|
-
export function tween<T extends EcsComponent>(target: T) {
|
|
351
|
-
return new Tween<T>(target);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* 缓动管理器
|
|
356
|
-
*/
|
|
357
|
-
export class TweenManager {
|
|
358
|
-
private map = new Map<number, Tween<EcsComponent>>();
|
|
359
|
-
private pausing = new Map<number, true>();
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* 添加tween
|
|
363
|
-
* @param tween
|
|
364
|
-
* @returns id 永远大于0
|
|
365
|
-
*/
|
|
366
|
-
add(tween: Tween<EcsComponent>) {
|
|
367
|
-
this.map.set(tween.id, tween);
|
|
368
|
-
return tween.id;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* 移除指定的tween
|
|
373
|
-
* @param id
|
|
374
|
-
*/
|
|
375
|
-
remove(id: number): void;
|
|
376
|
-
/**
|
|
377
|
-
* 移除指定的tween
|
|
378
|
-
* @param tween
|
|
379
|
-
*/
|
|
380
|
-
remove(tween: Tween<EcsComponent>): void;
|
|
381
|
-
/**
|
|
382
|
-
* 移除指定target的所有tween
|
|
383
|
-
* @param target
|
|
384
|
-
*/
|
|
385
|
-
remove(target: EcsComponent): void;
|
|
386
|
-
remove(param: number | EcsComponent | Tween<EcsComponent>) {
|
|
387
|
-
if (typeof param === 'number') {
|
|
388
|
-
this.map.delete(param);
|
|
389
|
-
this.pausing.delete(param);
|
|
390
|
-
} else if (param instanceof Tween) {
|
|
391
|
-
this.map.delete(param.id);
|
|
392
|
-
this.pausing.delete(param.id);
|
|
393
|
-
} else {
|
|
394
|
-
this.map.forEach((tween, tid) => {
|
|
395
|
-
if (tween.target === param) {
|
|
396
|
-
this.map.delete(tid);
|
|
397
|
-
this.pausing.delete(tid);
|
|
398
|
-
}
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* 暂停指定的tween
|
|
405
|
-
* @param id
|
|
406
|
-
*/
|
|
407
|
-
pause(id: number): void;
|
|
408
|
-
/**
|
|
409
|
-
* 暂停指定的tween
|
|
410
|
-
* @param tween
|
|
411
|
-
*/
|
|
412
|
-
pause(tween: Tween<EcsComponent>): void;
|
|
413
|
-
/**
|
|
414
|
-
* 暂停指定target的所有tween
|
|
415
|
-
* @param target
|
|
416
|
-
*/
|
|
417
|
-
pause(target: EcsComponent): void;
|
|
418
|
-
pause(param: number | EcsComponent | Tween<EcsComponent>) {
|
|
419
|
-
if (typeof param === 'number') {
|
|
420
|
-
this.pausing.set(param, true);
|
|
421
|
-
} else if (param instanceof Tween) {
|
|
422
|
-
this.pausing.set(param.id, true);
|
|
423
|
-
} else {
|
|
424
|
-
this.map.forEach((tween, tid) => {
|
|
425
|
-
if (tween.target === param) {
|
|
426
|
-
this.pausing.set(tid, true);
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* 恢复指定的tween
|
|
434
|
-
* @param id
|
|
435
|
-
*/
|
|
436
|
-
resume(id: number): void;
|
|
437
|
-
/**
|
|
438
|
-
* 恢复指定的tween
|
|
439
|
-
* @param tween
|
|
440
|
-
*/
|
|
441
|
-
resume(tween: Tween<EcsComponent>): void;
|
|
442
|
-
/**
|
|
443
|
-
* 恢复指定target的所有tween
|
|
444
|
-
* @param target
|
|
445
|
-
*/
|
|
446
|
-
resume(target: EcsComponent): void;
|
|
447
|
-
resume(param: number | EcsComponent | Tween<EcsComponent>) {
|
|
448
|
-
if (typeof param === 'number') {
|
|
449
|
-
this.pausing.delete(param);
|
|
450
|
-
} else if (param instanceof Tween) {
|
|
451
|
-
this.pausing.delete(param.id);
|
|
452
|
-
} else {
|
|
453
|
-
this.map.forEach((tween, tid) => {
|
|
454
|
-
if (tween.target === param) {
|
|
455
|
-
this.pausing.delete(tid);
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* 迭代一次
|
|
463
|
-
*/
|
|
464
|
-
step(dt: number) {
|
|
465
|
-
this.map.forEach((tween, tid) => {
|
|
466
|
-
// 暂停中,则跳过
|
|
467
|
-
if (this.pausing.has(tid)) return;
|
|
468
|
-
// 执行次数达到上限,则移除
|
|
469
|
-
if (Tween.step(tween, dt) === false) {
|
|
470
|
-
this.map.delete(tid);
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
get size() {
|
|
476
|
-
return this.map.size;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* 清空
|
|
481
|
-
*/
|
|
482
|
-
clear() {
|
|
483
|
-
this.map.clear();
|
|
484
|
-
this.pausing.clear();
|
|
485
|
-
}
|
|
486
|
-
}
|