import { AssetManager } from "../Tools/AssetManager";
import GamePool from "../Tools/GamePool";
import { EventManager, EventState } from "../Tools/EventManager";
import { PlayerControl } from "./PlayerControl";
import { ViewManager, ViewType } from "../View/ViewManager";


export class GameManager{
    private static ins:GameManager;
    
    //敌人数组
    public EnemyArray:Array<Laya.Sprite3D> = [];
    public mainscene:Laya.Scene3D;

    constructor(){
        GameManager.ins = this;
        EventManager.EventOn(EventState.SceneInit,this,this.Init)
    }
    public static get Instance():GameManager{
        if(GameManager.ins){
            return GameManager.ins
        }
        else{
            return new GameManager();
        }
    }
    Init(){
        this.CreatCharacter();
        this.mainscene = AssetManager.Instance.mainscene;
        Laya.stage.addChildAt(this.mainscene,0);
        ViewManager.Instance.ShowView(ViewType.MainView);
    }
    CreatCharacter(){
        this.CreatPlayer();
        this.CreatEnemy();
    }
    CreatPlayer(){
        var playermodel = GamePool.Instance.GetModel(AssetManager.Instance.Player.get(1),"");
        var horsemodel = GamePool.Instance.GetModel(AssetManager.Instance.Horse.get(1),"");
        playermodel.addChild(horsemodel);
        playermodel.transform.position = new Laya.Vector3(0,0,0);
        horsemodel.transform.localScale = new  Laya.Vector3(1,1,1);
        horsemodel.transform.localPosition = new Laya.Vector3(0,0,0);
        PlayerControl.Instance.Init(playermodel);
        AssetManager.Instance.mainscene.addChild(playermodel);
    }
    CreatEnemy(){
        
    }
    EventListen(){
        
    }

}