System.register(["cc"], function (_export, _context) {
  "use strict";

  var _cclegacy, Component, _decorator, v3, _dec, _class, _temp, _crd, ccclass, property, PositionMapToUIComponent;

  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

  return {
    setters: [function (_cc) {
      _cclegacy = _cc.cclegacy;
      Component = _cc.Component;
      _decorator = _cc._decorator;
      v3 = _cc.v3;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "03052IJ4x9EXqyWJITjaSGn", "PositionMapToUIComponent", undefined);

      ({
        ccclass,
        property
      } = _decorator);
      /**位置映射到UI节点,并自动更新该UI节点的位置*/

      _export("PositionMapToUIComponent", PositionMapToUIComponent = (_dec = ccclass('PositionMapToUIComponent'), _dec(_class = (_temp = class PositionMapToUIComponent extends Component {
        constructor() {
          super(...arguments);

          _defineProperty(this, "_canMove", true);

          _defineProperty(this, "_lastCameraPos", v3());

          _defineProperty(this, "_lastWPos", v3());

          _defineProperty(this, "_transformUIPos", v3());

          _defineProperty(this, "_testPos", v3());
        }

        start() {}

        onEnable() {
          this._checkCanMove();
        }

        _checkCanMove() {
          this._canMove = !!(this.camera && this.targetUI);
        }

        update() {
          var wPos = this.node.worldPosition;
          var camera = this.camera;

          if (!this._canMove || !camera || !camera.camera || this._lastWPos.equals(wPos) && this._lastCameraPos.equals(camera.node.worldPosition)) {
            return;
          }

          this._lastWPos.set(wPos);

          this._lastCameraPos.set(camera.node.worldPosition); // [HACK]


          camera.camera.update();
          camera.convertToUINode(wPos, this.targetUI, this._transformUIPos); //this._transformUIPos这值一下异常一下正常

          camera.worldToScreen(wPos, this._testPos);
          /*
          if (this._useScale) {
              Vec3.transformMat4(this._viewPos, this.node.worldPosition, camera.camera.matView);
          }*/

          /*
          if (this.syncEvents.length > 0) {
              const data = this._distance / Math.abs(this._viewPos.z);
              EventHandler.emitEvents(this.syncEvents, this._transformUIPos, data);
          }*/
          //先简单的直接更新UI节点位置

          this._transformUIPos.z = 0;
          this.targetUI.setPosition(this._transformUIPos); //this._testPos.z = 0;
          //this.targetUI.setPosition(this._testPos);
        }

      }, _temp)) || _class));

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=PositionMapToUIComponent.js.map