新增allTweensWithTargetEntity与clearAllCoroutines方法

This commit is contained in:
YHH
2022-07-09 11:24:32 +08:00
parent dde04d514e
commit 34f0c4ac2d
9 changed files with 115 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ module es {
* 它可以做任何需要每帧执行的事情。
*/
export abstract class AbstractTweenable implements ITweenable {
readonly discriminator = "ITweenable";
protected _isPaused: boolean;
/**

View File

@@ -3,6 +3,7 @@ module es {
* 更多具体的Tween播放控制在这里
*/
export interface ITweenControl extends ITweenable {
readonly discriminator: "ITweenControl";
/**
* 当使用匿名方法时,您可以在任何回调(如完成处理程序)中使用该属性来避免分配
*/

View File

@@ -1,5 +1,6 @@
module es {
export interface ITweenable {
readonly discriminator: string;
/**
* 就像内部的Update一样每一帧都被TweenManager调用
*/

View File

@@ -12,6 +12,7 @@ module es {
}
export abstract class Tween<T> implements ITweenable, ITween<T> {
readonly discriminator: "ITweenControl";
protected _target: ITweenTarget<T>;
protected _isFromValueOverridden: boolean;
protected _fromValue: T;

View File

@@ -23,6 +23,10 @@ module es {
* 当前所有活跃用户的内部列表
*/
private _activeTweens: ITweenable[] = [];
public static get activeTweens(): ITweenable[] {
return this._instance._activeTweens;
}
private _tempTweens: ITweenable[] = [];
/**
* 标志表示tween更新循环正在运行
@@ -134,6 +138,29 @@ module es {
return foundTweens;
}
/**
* 返回以特定实体为目标的所有tween
* Tween返回为ITweenControl
* @param target
*/
public static allTweensWithTargetEntity(target: Entity) {
let foundTweens = [];
for (let i = 0; i < this._instance._activeTweens.length; i ++) {
if (this._instance._activeTweens[i].discriminator == "ITweenControl") {
let tweenControl = this._instance._activeTweens[i] as ITweenControl;
let obj = tweenControl.getTargetObject();
if (obj instanceof Entity && obj == target ||
obj instanceof Component && obj.entity == target ||
obj instanceof Transform && obj.entity == target) {
foundTweens.push(this._instance._activeTweens[i]);
}
}
}
return foundTweens;
}
/**
* 停止所有具有TweenManager知道的特定目标的tweens
* @param target

View File

@@ -3,7 +3,7 @@ module es {
* CoroutineManager用于隐藏Coroutine所需数据的内部类
*/
export class CoroutineImpl implements ICoroutine, IPoolable {
public enumerator: any;
public enumerator: Generator;
/**
* 每当产生一个延迟它就会被添加到跟踪延迟的waitTimer中
@@ -46,6 +46,22 @@ module es {
public _unblockedCoroutines: CoroutineImpl[] = [];
public _shouldRunNextFrame: CoroutineImpl[] = [];
/**
* 立即停止并清除所有协程
*/
public clearAllCoroutines() {
for (let i = 0; i < this._unblockedCoroutines.length; i ++) {
Pool.free(CoroutineImpl, this._unblockedCoroutines[i]);
}
for (let i = 0; i < this._shouldRunNextFrame.length; i ++) {
Pool.free(CoroutineImpl, this._shouldRunNextFrame[i]);
}
this._unblockedCoroutines.length = 0;
this._shouldRunNextFrame.length = 0;
}
/**
* 将IEnumerator添加到CoroutineManager中
* Coroutine在每一帧调用Update之前被执行
@@ -144,6 +160,11 @@ module es {
return true;
}
if (typeof chain.value == 'function') {
coroutine.waitForCoroutine = this.startCoroutine(chain.value);
return true;
}
if (chain.value instanceof CoroutineImpl) {
coroutine.waitForCoroutine = chain.value;
return true;