完善 colliderTriggerHelper 用于更新碰撞信息
This commit is contained in:
25
source/bin/framework.d.ts
vendored
25
source/bin/framework.d.ts
vendored
@@ -194,7 +194,7 @@ declare class Entity {
|
||||
hasComponent<T extends Component>(type: any): boolean;
|
||||
getOrCreateComponent<T extends Component>(type: T): T;
|
||||
getComponent<T extends Component>(type: any): T;
|
||||
getComponents<T extends Component>(type: any): T[];
|
||||
getComponents(typeName: string, componentList?: any): any;
|
||||
removeComponentForType<T extends Component>(type: any): boolean;
|
||||
removeComponent(component: Component): void;
|
||||
removeAllComponents(): void;
|
||||
@@ -471,7 +471,7 @@ declare class ComponentList {
|
||||
updateLists(): void;
|
||||
private handleRemove;
|
||||
getComponent<T extends Component>(type: any, onlyReturnInitializedComponents: boolean): T;
|
||||
getComponents<T extends Component>(type: any): T[];
|
||||
getComponents(typeName: string, components?: any): any;
|
||||
update(): void;
|
||||
onEntityTransformChanged(comp: any): void;
|
||||
}
|
||||
@@ -627,7 +627,13 @@ declare class Vector2 {
|
||||
}
|
||||
declare class ColliderTriggerHelper {
|
||||
private _entity;
|
||||
private _activeTriggerIntersections;
|
||||
private _previousTriggerIntersections;
|
||||
private _tempTriggerList;
|
||||
constructor(entity: Entity);
|
||||
update(): void;
|
||||
private checkForExitedColliders;
|
||||
private notifyTriggerListeners;
|
||||
}
|
||||
declare enum PointSectors {
|
||||
center = 0,
|
||||
@@ -764,6 +770,21 @@ declare class Emitter<T> {
|
||||
removeObserver(eventType: T, handler: Function): void;
|
||||
emit(eventType: T, data: any): void;
|
||||
}
|
||||
declare class ListPool {
|
||||
private static readonly _objectQueue;
|
||||
static warmCache(cacheCount: number): void;
|
||||
static trimCache(cacheCount: any): void;
|
||||
static clearCache(): void;
|
||||
static obtain<T>(): Array<T>;
|
||||
static free<T>(obj: Array<T>): void;
|
||||
}
|
||||
declare class Pair<T> {
|
||||
first: T;
|
||||
second: T;
|
||||
constructor(first: T, second: T);
|
||||
clear(): void;
|
||||
equals(other: Pair<T>): boolean;
|
||||
}
|
||||
declare class Triangulator {
|
||||
triangleIndices: number[];
|
||||
private _triPrev;
|
||||
|
||||
@@ -1013,8 +1013,8 @@ var Entity = (function () {
|
||||
Entity.prototype.getComponent = function (type) {
|
||||
return this.components.getComponent(type, false);
|
||||
};
|
||||
Entity.prototype.getComponents = function (type) {
|
||||
return this.components.getComponents(type);
|
||||
Entity.prototype.getComponents = function (typeName, componentList) {
|
||||
return this.components.getComponents(typeName, componentList);
|
||||
};
|
||||
Entity.prototype.removeComponentForType = function (type) {
|
||||
var comp = this.getComponent(type);
|
||||
@@ -2208,17 +2208,18 @@ var ComponentList = (function () {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
ComponentList.prototype.getComponents = function (type) {
|
||||
var components = [];
|
||||
ComponentList.prototype.getComponents = function (typeName, components) {
|
||||
if (!components)
|
||||
components = [];
|
||||
for (var i = 0; i < this._components.length; i++) {
|
||||
var component = this._components[i];
|
||||
if (component instanceof type)
|
||||
components.push(components);
|
||||
if (egret.is(component, typeName))
|
||||
components.push(component);
|
||||
}
|
||||
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
||||
var component = this._componentsToAdd[i];
|
||||
if (component instanceof type)
|
||||
components.push(components);
|
||||
if (egret.is(component, typeName))
|
||||
components.push(component);
|
||||
}
|
||||
return components;
|
||||
};
|
||||
@@ -2928,10 +2929,14 @@ var Vector2 = (function () {
|
||||
return Vector2;
|
||||
}());
|
||||
var ColliderTriggerHelper = (function () {
|
||||
function ColliderTriggerHelper() {
|
||||
function ColliderTriggerHelper(entity) {
|
||||
this._activeTriggerIntersections = [];
|
||||
this._previousTriggerIntersections = [];
|
||||
this._tempTriggerList = [];
|
||||
this._entity = entity;
|
||||
}
|
||||
ColliderTriggerHelper.prototype.update = function () {
|
||||
var colliders = this._entity.getComponents(Collider);
|
||||
var colliders = this._entity.getComponents("Collider");
|
||||
for (var i = 0; i < colliders.length; i++) {
|
||||
var collider = colliders[i];
|
||||
var neighbors = Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers);
|
||||
@@ -2940,9 +2945,58 @@ var ColliderTriggerHelper = (function () {
|
||||
if (!collider.isTrigger && !neighbor.isTrigger)
|
||||
continue;
|
||||
if (collider.overlaps(neighbor)) {
|
||||
var pair = new Pair(collider, neighbor);
|
||||
var shouldReportTriggerEvent = !this._activeTriggerIntersections.contains(pair) &&
|
||||
!this._previousTriggerIntersections.contains(pair);
|
||||
if (shouldReportTriggerEvent)
|
||||
this.notifyTriggerListeners(pair, true);
|
||||
this._activeTriggerIntersections.push(pair);
|
||||
}
|
||||
}
|
||||
}
|
||||
ListPool.free(colliders);
|
||||
this.checkForExitedColliders();
|
||||
};
|
||||
ColliderTriggerHelper.prototype.checkForExitedColliders = function () {
|
||||
var _this = this;
|
||||
var tempIntersections = [];
|
||||
this._previousTriggerIntersections = this._previousTriggerIntersections.filter(function (value) {
|
||||
for (var i = 0; i < _this._activeTriggerIntersections.length; i++) {
|
||||
if (value == _this._activeTriggerIntersections[i]) {
|
||||
tempIntersections.push(value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
this._previousTriggerIntersections.forEach(function (pair) { return _this.notifyTriggerListeners(pair, false); });
|
||||
this._previousTriggerIntersections.length = 0;
|
||||
tempIntersections.forEach(function (value) { return _this._previousTriggerIntersections.push(value); });
|
||||
this._activeTriggerIntersections.length = 0;
|
||||
};
|
||||
ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) {
|
||||
collisionPair.first.entity.getComponents("ITriggerListener", this._tempTriggerList);
|
||||
for (var i = 0; i < this._tempTriggerList.length; i++) {
|
||||
if (isEntering) {
|
||||
this._tempTriggerList[i].onTriggerEnter(collisionPair.second, collisionPair.first);
|
||||
}
|
||||
else {
|
||||
this._tempTriggerList[i].onTriggerExit(collisionPair.second, collisionPair.first);
|
||||
}
|
||||
this._tempTriggerList.length = 0;
|
||||
if (collisionPair.second.entity) {
|
||||
collisionPair.second.entity.getComponents("ITriggerListener", this._tempTriggerList);
|
||||
for (var i_3 = 0; i_3 < this._tempTriggerList.length; i_3++) {
|
||||
if (isEntering) {
|
||||
this._tempTriggerList[i_3].onTriggerEnter(collisionPair.first, collisionPair.second);
|
||||
}
|
||||
else {
|
||||
this._tempTriggerList[i_3].onTriggerExit(collisionPair.first, collisionPair.second);
|
||||
}
|
||||
}
|
||||
this._tempTriggerList.length = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
return ColliderTriggerHelper;
|
||||
}());
|
||||
@@ -3612,6 +3666,49 @@ var Emitter = (function () {
|
||||
};
|
||||
return Emitter;
|
||||
}());
|
||||
var ListPool = (function () {
|
||||
function ListPool() {
|
||||
}
|
||||
ListPool.warmCache = function (cacheCount) {
|
||||
cacheCount -= this._objectQueue.length;
|
||||
if (cacheCount > 0) {
|
||||
for (var i = 0; i < cacheCount; i++) {
|
||||
this._objectQueue.unshift([]);
|
||||
}
|
||||
}
|
||||
};
|
||||
ListPool.trimCache = function (cacheCount) {
|
||||
while (cacheCount > this._objectQueue.length)
|
||||
this._objectQueue.shift();
|
||||
};
|
||||
ListPool.clearCache = function () {
|
||||
this._objectQueue.length = 0;
|
||||
};
|
||||
ListPool.obtain = function () {
|
||||
if (this._objectQueue.length > 0)
|
||||
return this._objectQueue.shift();
|
||||
return [];
|
||||
};
|
||||
ListPool.free = function (obj) {
|
||||
this._objectQueue.unshift(obj);
|
||||
obj.length = 0;
|
||||
};
|
||||
ListPool._objectQueue = [];
|
||||
return ListPool;
|
||||
}());
|
||||
var Pair = (function () {
|
||||
function Pair(first, second) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
}
|
||||
Pair.prototype.clear = function () {
|
||||
this.first = this.second = null;
|
||||
};
|
||||
Pair.prototype.equals = function (other) {
|
||||
return this.first == other.first && this.second == other.second;
|
||||
};
|
||||
return Pair;
|
||||
}());
|
||||
var Triangulator = (function () {
|
||||
function Triangulator() {
|
||||
this.triangleIndices = [];
|
||||
|
||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user