
    export class GamePool{
    private static ins:GamePool;
    constructor(){
        GamePool.ins = this;
    }
    
    //最大存储数量
    private maxAcount:number = 30;

    public static get Instance():GamePool{
        if(GamePool.ins){
            return GamePool.ins
        }
        else{
            return new GamePool();
        }
    }
    //模型库
    private modelpool : {[Key:string]:Array<Laya.Image> } = {};
    //获取模型
    public GetModel(title:string):Laya.Image{
        let poolname = title ;
        if(this.modelpool[poolname]!=null && this.modelpool[poolname]!=undefined){
            if(this.modelpool[poolname].length >0){
                let model1 = this.modelpool[poolname].shift();
                if(!model1.active){
                    model1.active = true;  
                }
                return model1;
            }
            else{
                let model = new Laya.Image();
                model.name=title;
                return model;
            }
        }
        else{
            let model = new Laya.Image();
            model.name=title;
            return model;
        }
    }
    //回收模型
    public RecoverModel(_image:Laya.Image,title = "",modelstate = false){
        if(_image.destroyed){
            return;
        }
        if(!modelstate && _image.active == false){
            return;
        }
       let poolname = title ; 
        if(this.modelpool[poolname] != null && this.modelpool[poolname] != undefined){
           let modelnum = this.modelpool[poolname];
           this.modelpool[poolname].push(_image);
        }
        else{
            let modelnum = [];
            modelnum.push(_image);
            this.modelpool[poolname] = modelnum;
        }
        _image.removeSelf();
        _image.active = false;
    }



    /**取出模型*/
// GetModel(_model:Laya.Sprite3D,title:string):Laya.Image{
   
//     var poolname =title+ _model.name ;
//     if(this.modelpool[poolname]!=null && this.modelpool[poolname] !=undefined){
//         if(this.modelpool[poolname].length >0 ){
//             var model1 = this.modelpool[poolname][0];
//             this.modelpool[poolname].splice(0,1);
//             if(model1.modelcur.destroyed){
//                 model1.modelcur = Sprite3D.instantiate(_model);
//                 if(!model1.modelcur.active){
//                     model1.modelcur.active = true;
//                 }
//             }
//             model1.modelcur.active = true;
//             model1.modelcur.transform.position = _model.transform.position.clone();
//             model1.modelcur.transform.rotation = _model.transform.rotation.clone();
//             model1.modelcur.transform.scale = _model.transform.scale.clone();
//             return model1.modelcur;
//         }
//         else{
//             var model = Sprite3D.instantiate(_model);
//             model.active = true;
//             return model;
//         }
//     }
//     else{
//         var model = Sprite3D.instantiate(_model);
//         model.active = true;
//         return model;
//     }
// }
// /**回收模型*/
// RecoveryModel(model:Sprite3D,title = "",modelstate = false){
//     if(model.destroyed){
//         return;
//     }
//     if(!modelstate && model.active == false){
//         return;
//     }
//     var poolname =title+ model.name ; 
//     if(this.modelpool[poolname] != null && this.modelpool[poolname] != undefined){
//         var modelnum = this.modelpool[poolname];
//         if( modelnum.length>this.maxAcount){
//             model.destroy();
//             return;
//         }
//         else{
//             modelnum.push(new modelConfig(model));
//         }
//     }
//     else{
//         modelnum = [];
//         modelnum.push(new modelConfig(model));
//         this.modelpool[poolname] = modelnum;
//     }
//     model.transform.position = new Vector3(0,0,-10000);
//     model.removeSelf();
//     model.active = false;
// }

}