342 lines
15 KiB
JavaScript
342 lines
15 KiB
JavaScript
System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2", "__unresolved_3", "__unresolved_4"], function (_export, _context) {
|
|
"use strict";
|
|
|
|
var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Node, Vec3, Quat, v3, tween, Camera, geometry, screen, PhysicsSystem, Prefab, instantiate, ParticleSystem, RagdollBone, SingletonBase, GameController, UIManager, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _crd, ccclass, property, FPSCameraController;
|
|
|
|
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
|
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
|
|
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
|
|
function _reportPossibleCrUseOfRagdollBone(extras) {
|
|
_reporterNs.report("RagdollBone", "../Ragdoll/RagdollBone", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfSingletonBase(extras) {
|
|
_reporterNs.report("SingletonBase", "./framework/SingletonBase", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfGameController(extras) {
|
|
_reporterNs.report("GameController", "./GameController", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfRagdoll(extras) {
|
|
_reporterNs.report("Ragdoll", "../Ragdoll/Ragdoll", _context.meta, extras);
|
|
}
|
|
|
|
function _reportPossibleCrUseOfUIManager(extras) {
|
|
_reporterNs.report("UIManager", "./framework/ui/UIManager", _context.meta, extras);
|
|
}
|
|
|
|
return {
|
|
setters: [function (_unresolved_) {
|
|
_reporterNs = _unresolved_;
|
|
}, function (_cc) {
|
|
_cclegacy = _cc.cclegacy;
|
|
__checkObsolete__ = _cc.__checkObsolete__;
|
|
__checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
|
|
_decorator = _cc._decorator;
|
|
Node = _cc.Node;
|
|
Vec3 = _cc.Vec3;
|
|
Quat = _cc.Quat;
|
|
v3 = _cc.v3;
|
|
tween = _cc.tween;
|
|
Camera = _cc.Camera;
|
|
geometry = _cc.geometry;
|
|
screen = _cc.screen;
|
|
PhysicsSystem = _cc.PhysicsSystem;
|
|
Prefab = _cc.Prefab;
|
|
instantiate = _cc.instantiate;
|
|
ParticleSystem = _cc.ParticleSystem;
|
|
}, function (_unresolved_2) {
|
|
RagdollBone = _unresolved_2.RagdollBone;
|
|
}, function (_unresolved_3) {
|
|
SingletonBase = _unresolved_3.SingletonBase;
|
|
}, function (_unresolved_4) {
|
|
GameController = _unresolved_4.GameController;
|
|
}, function (_unresolved_5) {
|
|
UIManager = _unresolved_5.UIManager;
|
|
}],
|
|
execute: function () {
|
|
_crd = true;
|
|
|
|
_cclegacy._RF.push({}, "c9316GAFZBHB7Hr7DxrRdFJ", "FPSCameraController", undefined);
|
|
|
|
__checkObsolete__(['_decorator', 'Component', 'Node', 'input', 'Input', 'EventTouch', 'Vec3', 'Quat', 'v3', 'Button', 'tween', 'v2', 'Camera', 'director', 'geometry', 'screen', 'PhysicsSystem', 'Prefab', 'instantiate', 'ParticleSystem']);
|
|
|
|
({
|
|
ccclass,
|
|
property
|
|
} = _decorator);
|
|
|
|
_export("FPSCameraController", FPSCameraController = (_dec = ccclass('FPSCameraController'), _dec2 = property(Node), _dec3 = property(Camera), _dec4 = property(Camera), _dec5 = property(ParticleSystem), _dec6 = property(Prefab), _dec(_class = (_class2 = class FPSCameraController extends (_crd && SingletonBase === void 0 ? (_reportPossibleCrUseOfSingletonBase({
|
|
error: Error()
|
|
}), SingletonBase) : SingletonBase) {
|
|
constructor() {
|
|
super(...arguments);
|
|
|
|
// export class FPSCameraController extends Component {
|
|
_initializerDefineProperty(this, "cameraNode", _descriptor, this);
|
|
|
|
// 相机节点
|
|
_initializerDefineProperty(this, "camera", _descriptor2, this);
|
|
|
|
// 相机节点
|
|
_initializerDefineProperty(this, "qingBao", _descriptor3, this);
|
|
|
|
// 相机节点
|
|
_initializerDefineProperty(this, "particle", _descriptor4, this);
|
|
|
|
// 粒子系统
|
|
_initializerDefineProperty(this, "lastBulletPrefab", _descriptor5, this);
|
|
|
|
this.lastBullet = null;
|
|
this._touchStartPos = new Vec3();
|
|
this._rotationSpeed = 0.04;
|
|
// 旋转速度
|
|
this._currentRotationX = 0;
|
|
// 当前相机的垂直旋转角度
|
|
this._currentRotationY = 0;
|
|
// 当前相机的水平旋转角度
|
|
this._defaultRotationY = 0;
|
|
// 当前相机的水平旋转角度
|
|
this._maxVerticalAngle = 70;
|
|
// 最大垂直旋转角度
|
|
this._maxHorizontalAngle = 45;
|
|
// 最大垂直旋转角度
|
|
this._defaultFOV = 45;
|
|
// 默认 FOV
|
|
this._aimFOV = 25;
|
|
// 瞄准时的 FOV
|
|
this._isAiming = false;
|
|
}
|
|
|
|
// 是否正在瞄准
|
|
onLoad() {
|
|
super.onLoad();
|
|
}
|
|
|
|
init(curCamera, aimFov) {
|
|
this.camera = curCamera;
|
|
this.cameraNode = curCamera.node;
|
|
var initialRotation = this.cameraNode.getWorldRotation();
|
|
var eulerAngles = initialRotation.getEulerAngles(v3());
|
|
this._currentRotationX = eulerAngles.x;
|
|
this._currentRotationY = eulerAngles.y;
|
|
this._defaultRotationY = eulerAngles.y;
|
|
this._aimFOV = aimFov; // 获取摄像机的默认 FOV
|
|
|
|
var camera = this.cameraNode.getComponent(Camera);
|
|
camera.fov = this._defaultFOV;
|
|
}
|
|
|
|
onTouchStart(event) {
|
|
// console.log("onTouchStart", event)
|
|
var touch = event.touch;
|
|
|
|
this._touchStartPos.set(touch.getLocation().x, touch.getLocation().y, 0);
|
|
}
|
|
|
|
onTouchMove(event) {
|
|
// console.log("onTouchMove", event)
|
|
var touch = event.touch;
|
|
|
|
var deltaX = touch.getLocation().x - this._touchStartPos.x;
|
|
|
|
var deltaY = touch.getLocation().y - this._touchStartPos.y; // 横向旋转(左右滑动):作用于摄像机的 Y 轴
|
|
|
|
|
|
var rotationY = -deltaX * this._rotationSpeed * this.camera.fov / 45; // console.log("this.camera.fov", this.camera.fov)
|
|
|
|
this._currentRotationY += rotationY; // 纵向旋转(上下滑动):作用于摄像机的 X 轴
|
|
|
|
var rotationX = deltaY * this._rotationSpeed * this.camera.fov / 45; // 修正:去掉负号
|
|
|
|
this._currentRotationX += rotationX; // 限制垂直旋转角度
|
|
|
|
this._currentRotationX = Math.min(Math.max(this._currentRotationX, -this._maxVerticalAngle), 60);
|
|
this._currentRotationY = Math.min(Math.max(this._currentRotationY, this._defaultRotationY - this._maxHorizontalAngle), this._defaultRotationY + this._maxHorizontalAngle); // 应用旋转到相机节点
|
|
|
|
var newRotation = Quat.fromEuler(new Quat(), this._currentRotationX, this._currentRotationY, 0);
|
|
this.cameraNode.setWorldRotation(newRotation); // console.log("newRotation", this._currentRotationX, this._currentRotationY)
|
|
// 更新起始位置
|
|
|
|
this._touchStartPos.set(touch.getLocation().x, touch.getLocation().y, 0);
|
|
}
|
|
|
|
setTutorialRotate() {
|
|
this._currentRotationX = -3.99;
|
|
this._currentRotationY = -32.27;
|
|
var newRotation = Quat.fromEuler(new Quat(), this._currentRotationX, this._currentRotationY, 0);
|
|
this.cameraNode.setWorldRotation(newRotation);
|
|
}
|
|
|
|
shoot() {
|
|
var ray = new geometry.Ray();
|
|
this.camera.screenPointToRay(screen.windowSize.width / 2, screen.windowSize.height / 2, ray); // 以下参数可选
|
|
|
|
var mask = 0xffffffff;
|
|
var maxDistance = 10000000;
|
|
var queryTrigger = true;
|
|
var result = false;
|
|
|
|
if (PhysicsSystem.instance.raycastClosest(ray, mask, maxDistance, queryTrigger)) {
|
|
var raycastClosestResult = PhysicsSystem.instance.raycastClosestResult;
|
|
var hitPoint = raycastClosestResult.hitPoint;
|
|
var hitNormal = raycastClosestResult.hitNormal;
|
|
var collider = raycastClosestResult.collider;
|
|
var distance = raycastClosestResult.distance;
|
|
console.log("碰撞检测", raycastClosestResult.collider.node.name);
|
|
var bone = raycastClosestResult.collider.node.getComponent(_crd && RagdollBone === void 0 ? (_reportPossibleCrUseOfRagdollBone({
|
|
error: Error()
|
|
}), RagdollBone) : RagdollBone);
|
|
|
|
if (bone != null) {
|
|
if (!bone.ragdoll.isDie) {
|
|
if ((_crd && GameController === void 0 ? (_reportPossibleCrUseOfGameController({
|
|
error: Error()
|
|
}), GameController) : GameController).getInstance().curLevel.judgeLastBullet()) {
|
|
this.fireLastBullet(bone.ragdoll, hitPoint);
|
|
} else {
|
|
this.scheduleOnce(() => {
|
|
bone.ragdoll.node.active = false;
|
|
}, 2);
|
|
bone.ragdoll.setEnabled(true);
|
|
result = true;
|
|
this.particle.node.setWorldPosition(hitPoint.clone());
|
|
this.particle.play();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
tween(this.camera.node).by(0.05, {
|
|
position: new Vec3(0, 2, 0)
|
|
}, {
|
|
easing: 'sineOutIn'
|
|
}).by(0.05, {
|
|
position: new Vec3(0, -2, 0)
|
|
}, {
|
|
easing: 'sineOutIn'
|
|
}).start();
|
|
return result;
|
|
}
|
|
|
|
closeQingBao() {
|
|
this.qingBao.node.active = false;
|
|
}
|
|
|
|
showQingBao() {
|
|
this.qingBao.node.active = true;
|
|
var enemy = (_crd && GameController === void 0 ? (_reportPossibleCrUseOfGameController({
|
|
error: Error()
|
|
}), GameController) : GameController).getInstance().curLevel.getQingBaoEnemey().centerNode;
|
|
var pos = enemy.getWorldPosition().add(enemy.getWorldPosition().subtract(this.cameraNode.getWorldPosition()).normalize().multiplyScalar(-5));
|
|
var enemyPos = enemy.getWorldPosition();
|
|
var cameraPos = this.cameraNode.getWorldPosition();
|
|
var dirNor = enemy.getWorldPosition().subtract(this.cameraNode.getWorldPosition()).normalize();
|
|
var newPos = enemy.getWorldPosition().add(dirNor.multiplyScalar(-15));
|
|
var dir = this.cameraNode.getWorldPosition().subtract(enemy.getWorldPosition());
|
|
console.log("enemy", enemy.getWorldPosition());
|
|
console.log("camera", this.cameraNode.getWorldPosition());
|
|
console.log("newPos", newPos);
|
|
console.log("dirNor", enemy.getWorldPosition().subtract(this.cameraNode.getWorldPosition()).normalize());
|
|
this.qingBao.node.setWorldPosition(newPos);
|
|
this.qingBao.node.forward = enemy.getWorldPosition().subtract(this.cameraNode.getWorldPosition()).normalize();
|
|
}
|
|
|
|
fireLastBullet(ragdoll, hitPoint) {
|
|
var last = instantiate(this.lastBulletPrefab);
|
|
last.setParent(this.node);
|
|
last.setWorldPosition(this.cameraNode.worldPosition);
|
|
last.forward = this.cameraNode.worldPosition.subtract(hitPoint).normalize();
|
|
this.lastBullet = last;
|
|
this.camera.enabled = false;
|
|
(_crd && UIManager === void 0 ? (_reportPossibleCrUseOfUIManager({
|
|
error: Error()
|
|
}), UIManager) : UIManager).instance.closeAllPanels();
|
|
tween(last).to(1.67, {
|
|
worldPosition: hitPoint
|
|
}, {
|
|
easing: 'cubicIn'
|
|
}).call(() => {
|
|
ragdoll.setEnabled(true);
|
|
last.getChildByName("bullet").active = false;
|
|
(_crd && GameController === void 0 ? (_reportPossibleCrUseOfGameController({
|
|
error: Error()
|
|
}), GameController) : GameController).getInstance().curLevel.win();
|
|
}).start();
|
|
}
|
|
|
|
clear() {
|
|
if (this.lastBullet != null) {
|
|
this.lastBullet.destroy();
|
|
this.lastBullet = null;
|
|
}
|
|
}
|
|
|
|
onAimButtonClick(isAnim) {
|
|
var camera = this.cameraNode.getComponent(Camera);
|
|
if (!camera) return;
|
|
this._isAiming = isAnim; // 切换瞄准状态
|
|
|
|
if (this._isAiming) {
|
|
// 瞄准状态:缩小 FOV
|
|
tween(camera).to(0.1, {
|
|
fov: this._aimFOV
|
|
}) // 平滑过渡到瞄准 FOV
|
|
.start();
|
|
} else {
|
|
// 非瞄准状态:恢复默认 FOV
|
|
tween(camera).to(0.1, {
|
|
fov: this._defaultFOV
|
|
}) // 平滑过渡到默认 FOV
|
|
.start();
|
|
}
|
|
}
|
|
|
|
}, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "cameraNode", [_dec2], {
|
|
configurable: true,
|
|
enumerable: true,
|
|
writable: true,
|
|
initializer: function initializer() {
|
|
return null;
|
|
}
|
|
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "camera", [_dec3], {
|
|
configurable: true,
|
|
enumerable: true,
|
|
writable: true,
|
|
initializer: function initializer() {
|
|
return null;
|
|
}
|
|
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "qingBao", [_dec4], {
|
|
configurable: true,
|
|
enumerable: true,
|
|
writable: true,
|
|
initializer: function initializer() {
|
|
return null;
|
|
}
|
|
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "particle", [_dec5], {
|
|
configurable: true,
|
|
enumerable: true,
|
|
writable: true,
|
|
initializer: function initializer() {
|
|
return null;
|
|
}
|
|
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "lastBulletPrefab", [_dec6], {
|
|
configurable: true,
|
|
enumerable: true,
|
|
writable: true,
|
|
initializer: function initializer() {
|
|
return null;
|
|
}
|
|
})), _class2)) || _class));
|
|
|
|
_cclegacy._RF.pop();
|
|
|
|
_crd = false;
|
|
}
|
|
};
|
|
});
|
|
//# sourceMappingURL=067be96b86fad6e644289c720d9d23738f4ed87c.js.map
|