|
@@ -3,7 +3,7 @@ import { resMgr } from '../../../Frames/ResourcesMgr';
|
|
const { ccclass, property } = _decorator;
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
@ccclass('BulletPool')
|
|
@ccclass('BulletPool')
|
|
-export class BulletPool extends Component{
|
|
|
|
|
|
+export class BulletPool extends Component {
|
|
private _bulletPrefab: Prefab = null;
|
|
private _bulletPrefab: Prefab = null;
|
|
private _enemyBulletPrefab: Prefab = null;
|
|
private _enemyBulletPrefab: Prefab = null;
|
|
|
|
|
|
@@ -25,18 +25,18 @@ export class BulletPool extends Component{
|
|
}
|
|
}
|
|
getBullet(isEnemy: boolean): Node {
|
|
getBullet(isEnemy: boolean): Node {
|
|
const pool = isEnemy ? this._enemyBulletPool : this._bulletPool;
|
|
const pool = isEnemy ? this._enemyBulletPool : this._bulletPool;
|
|
- if(pool.size()>0){
|
|
|
|
|
|
+ if (pool.size() > 0) {
|
|
return pool.get()!;
|
|
return pool.get()!;
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
//动态扩容
|
|
//动态扩容
|
|
- const prefab = isEnemy ? this._enemyBulletPrefab: this._bulletPrefab;
|
|
|
|
|
|
+ const prefab = isEnemy ? this._enemyBulletPrefab : this._bulletPrefab;
|
|
return instantiate(prefab);
|
|
return instantiate(prefab);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
recycle(bullet: Node, isEnemy: boolean) {
|
|
recycle(bullet: Node, isEnemy: boolean) {
|
|
const pool = isEnemy ? this._enemyBulletPool : this._bulletPool;
|
|
const pool = isEnemy ? this._enemyBulletPool : this._bulletPool;
|
|
- if(!pool) return;
|
|
|
|
|
|
+ if (!pool) return;
|
|
pool.put(bullet);
|
|
pool.put(bullet);
|
|
}
|
|
}
|
|
}
|
|
}
|