import { _decorator, Component, instantiate, Node, Prefab, Vec3 } from 'cc';
import { car } from './car';
import { qiyou_effect_item } from './qiyou_effect_item';
const { ccclass, property } = _decorator;

@ccclass('qiyou_manager')
export class qiyou_manager extends Component {
    @property(Prefab) qiyou_pf:Prefab = null
    private COUNT:number = 6
    private mCar:car = null
    public init(car:car){
        this.mCar = car
        this.node.removeAllChildren()
        for (let index = 0; index < this.COUNT; index++) {
            this.addItem()
        }
    }
    addItem(){
        let node = instantiate(this.qiyou_pf)
        node.parent = this.node
        node.getComponent(qiyou_effect_item).init()
        return node
    }
    public getCanUseItem(){
        for (let index = 0; index < this.node.children.length; index++) {
            const node = this.node.children[index];
            if(node.getComponent(qiyou_effect_item).IsCanUse()){
                return node
            }
        }
        return this.addItem()
    }
    public showQiYou(qiyou_pos:Vec3){
        let qiyou = this.getCanUseItem()
        qiyou.getComponent(qiyou_effect_item).show(qiyou_pos)
    }
    protected update(dt: number): void {
        this.node.position = new Vec3(0,this.mCar.node.parent.position.y)
    }
}


