import { _decorator, Component, Node, loader, Prefab } from 'cc';
import { LoadingView } from '../../engines/loadingView/LoadingView';
import { GUIManager } from '../../engines/gui/GUIManager';
import { UIConst } from '../ui/UIConst';
import { GameModel } from '../models/GameModel';
import GameConfigManager from '../models/GameConfigManager';
const { ccclass, property } = _decorator;

@ccclass('PrepareScene')
export class PrepareScene extends Component {
    /* class member could be defined like this */
    // dummy = '';

    /* use `property` decorator if your want the member to be serializable */
    // @property
    // serializableDummy = 0;

    start () {
        console.log("进入Prepare场景");
        
        this.LoadAssets();
    }
    
    private LoadAssets():void{
        let urls:string[]=[];
        //武器
        let weaponConfig:any=GameConfigManager.GetWeaponConfig(GameModel.single.currentWeaponId);
        urls.push(weaponConfig.prefab);

        //加载
        loader.loadResArray(urls,Prefab,this.LoadAssetsProgress.bind(this),this.LoadAssetsComplete.bind(this));
    }

    private LoadAssetsProgress(index:number,total:number,item):void{
        LoadingView.single.UpdateProgress(index/total);
    }

    private LoadAssetsComplete(error:Error,assets):void{
        if(error){
            console.error(error);
        }
        GUIManager.single.Show(UIConst.PREPARE_UI);
    }

    // update (deltaTime: number) {
    //     // Your update function goes here.
    // }
}
