import Sprite3D = Laya.Sprite3D;
import Scene3D = Laya.Scene3D;
import { PlayerController } from "./PlayerController";
import { ObsController } from "./ObsController";
import StandBehaviour from "../Behaviour/StandBehaviour";
import CameraBehavior from "./CameraBehavior";
export class SceneController {
    private static instance: SceneController;
    public static get Instance(): SceneController {
        return SceneController.instance || (SceneController.instance = new SceneController());
    }


    private floor: Sprite3D;
    private _camera: Laya.Camera;
    public 
    public Init(_s: Scene3D) {
        if (_s) {
            Laya.stage.addChild(_s);
        }
        else {
            console.error("场景不存在");
            return;
        }
        var road = _s.getChildByName("road");
        var obs = road.getChildByName("road")._children;
        this.floor = road.getChildByName("floor").getChildAt(0) as Sprite3D;
        var player = _s.getChildByName("player") as Sprite3D;
        this._camera = _s.getChildByName("Main Camera") as Laya.Camera;
      

        PlayerController.Instance.Init(player);
        ObsController.Instance.Init(obs);
        this.InitScene();
        this._camera.addComponent(CameraBehavior);
    }

    public InitScene() {
        if (this.floor) {
            var floor = this.floor.getComponent(StandBehaviour);
            if (!floor) floor = this.floor.addComponent(StandBehaviour);
            floor.init();
        }
    }
}