BottleHitMng.js 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const NodePool = require('NodePool');
  2. const BottleType = require('Types').BottleType;
  3. /**
  4. * 对象池[Bottle]
  5. */
  6. cc.Class({
  7. extends: cc.Component,
  8. properties: {
  9. bottlePools: {
  10. default: [],
  11. type: NodePool
  12. }
  13. },
  14. init () {
  15. for (let i = 0; i < this.bottlePools.length; ++i) {
  16. this.bottlePools[i].init()
  17. }
  18. },
  19. requestBottle (bottleType) {
  20. let thePool = this.bottlePools[bottleType]
  21. if(thePool.idx >= 0) {
  22. return thePool.request()
  23. } else {
  24. return null
  25. }
  26. },
  27. returnBottle (bottleType, obj) {
  28. let thePool = this.bottlePools[bottleType]
  29. if(thePool.idx < thePool.size) {
  30. thePool.return(obj)
  31. } else {
  32. // console.log('=========== NodePool: 对象池已满 ===========')
  33. return
  34. }
  35. },
  36. start () {
  37. },
  38. // update (dt) {},
  39. });