
import Sprite3D = Laya.Sprite3D;
import ResourceLoad from "../game_module/ResourceLoad";
import BulletController from "./BulletController";
import { RoleController } from "./RoleController";
export default class AssetController {
    private static instance: AssetController;
    public static get Instance(): AssetController {
        return this.instance || (this.instance = new AssetController());
    }

    public path = "res/LayaScene_main/Conventional/main.ls";
    public _scenes: Laya.Scene3D;
    public _bullet: Laya.Sprite3D;
    public _bulletPos: Laya.Sprite3D;
    public _role: Laya.Sprite3D;


    public CreateScene() {
        ResourceLoad.LoadResource([this.path], () => {
            var t = Laya.loader.getRes(this.path) as Laya.Scene3D;
            Laya.stage.addChild(t);
            this._scenes = t;
            this._bullet = t.getChildByName("bullet") as Laya.Sprite3D;
            BulletController.Instance.init(this._bullet);
            this._role = t.getChildByName("role") as Laya.Sprite3D;
            RoleController.Instance.init(this._role);
          //  this._bulletPos = this._role.getChildByName("bulltePos") as Laya.Sprite3D;
        });
    }

    private createRay() {
        var forw = new Laya.Vector3();
        this._role.transform.getForward(forw);
        forw = new Laya.Vector3(-forw.x, -forw.y, -forw.z);
        //   Laya.Vector3.normalize()
        var _ray = new Laya.Ray(this._bulletPos.transform.position, forw);
        var _hit = new Laya.HitResult();
        var isS = this._scenes.physicsSimulation.rayCast(_ray, _hit);
        this._bullet.transform.position = this._bulletPos.transform.position;
        this._bullet.transform.rotation = this._role.transform.rotation;
        if (isS) {
            var poi = _hit.point;
            var nor = Laya.Vector3.distance(this._bulletPos.transform.position, poi);
            this._bullet.transform.localScaleZ = nor;
        } else {
            this._bullet.transform.localScaleZ = 50;
        }
    }

}