qiyou_manager.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator, Component, instantiate, Node, Prefab, Vec3 } from 'cc';
  2. import { car } from './car';
  3. import { qiyou_effect_item } from './qiyou_effect_item';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('qiyou_manager')
  6. export class qiyou_manager extends Component {
  7. @property(Prefab) qiyou_pf:Prefab = null
  8. private COUNT:number = 6
  9. private mCar:car = null
  10. public init(car:car){
  11. this.mCar = car
  12. this.node.removeAllChildren()
  13. for (let index = 0; index < this.COUNT; index++) {
  14. this.addItem()
  15. }
  16. }
  17. addItem(){
  18. let node = instantiate(this.qiyou_pf)
  19. node.parent = this.node
  20. node.getComponent(qiyou_effect_item).init()
  21. return node
  22. }
  23. public getCanUseItem(){
  24. for (let index = 0; index < this.node.children.length; index++) {
  25. const node = this.node.children[index];
  26. if(node.getComponent(qiyou_effect_item).IsCanUse()){
  27. return node
  28. }
  29. }
  30. return this.addItem()
  31. }
  32. public showQiYou(qiyou_pos:Vec3){
  33. let qiyou = this.getCanUseItem()
  34. qiyou.getComponent(qiyou_effect_item).show(qiyou_pos)
  35. }
  36. protected update(dt: number): void {
  37. this.node.position = new Vec3(0,this.mCar.node.parent.position.y)
  38. }
  39. }