import { NodeUtil } from "../GameUtils/NodeUtil";
import BossBehav from "./BossBehav";
import { Vector3Helper } from "../GameUtils/Vector3Helper";
import { AssetManager } from "../Resources/AssetManager";
import { MateMove } from "./MateMove";

export default class MateHpBarBehav extends Laya.Script3D{
    constructor(){
        super();
    }
    private _gameobject:Laya.Sprite3D;
    private _matebehav:MateMove;
    private _hpBar:Laya.ProgressBar;
    private _headPos:Laya.Sprite3D;
    
    public onAwake(){
        this._gameobject = this.owner as Laya.Sprite3D;
        this._headPos = NodeUtil.GetChildByName(this._gameobject,"UiPos" ) as Laya.Sprite3D;
        this._matebehav = this._gameobject.getComponent(MateMove) as MateMove;
        this._hpBar = new Laya.ProgressBar("Main/youxi-1-5.png");
        this._hpBar.anchorX = this._hpBar.anchorY = 0.5;
        Laya.stage.addChild(this._hpBar);
    }
    onUpdate() {
        let sp = new Laya.Sprite3D();
        sp.transform.position = this._headPos.transform.position.clone();
        sp.transform.rotationEuler = this._headPos.transform.rotationEuler.clone();
        sp.transform.translate(new Laya.Vector3(0, 0.4, 0), false);
        let pt = Vector3Helper.Zero;
        AssetManager.Instance.maincamera.worldToViewportPoint(sp.transform.position, pt);
        this._hpBar.pos(pt.x, pt.y);
        this._hpBar.value = this._matebehav.health / this._matebehav.maxhealth;
    }
    onDestroy() {
        this._hpBar.destroy();
        this._hpBar = null;
    }
}