玩法 / HotWeapon
HotWeapon Class
热武器
热武器功能是指游戏中武器的使用和管理机制,它使得玩家可以在战斗中使用各种类型的武器。
射击 - 玩家按下开火键,武器会射出子弹或光线。
上膛 - 每次射击后,都需要加载下一发弹药进入膛室。
换弹 - 当弹夹为空时,需要更换新的弹夹。
后坐力 - 射击时会产生后坐力,让准星会稍稍偏移。
Precautions
当装备上玩家时,此对象的功能才能生效。
ts
@Component
export default class HotWeaponSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.fireComponent.isFireOnScreenCenter = false
hotWeapon.fireComponent.clipSize = 50
hotWeapon.fireComponent.fireInterval = 0
hotWeapon.fireComponent.multipleShot = 3
hotWeapon.fireComponent.isFireOnScreenCenter = false
hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
// 设置参数
hotWeapon.fireComponent.animationAssetId = "80484";
hotWeapon.fireComponent.fireMode = HotWeaponFireMode.SingleFire;
hotWeapon.aimEnabled = true;
// 切换瞄准时的 第一/第三 人称
hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
// 设置模拟瞄准时的倍镜放大倍数(仅第一人称瞄准时生效,范围1~18)
hotWeapon.aimComponent.aimingZoom = 16;
hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
hotWeapon.loadEnabled = true;
hotWeapon.loadComponent.loadDuration = 1
hotWeapon.loadComponent.loadAfterFireEnabled = true;
hotWeapon.loadComponent.animationAssetId = "4172";
hotWeapon.reloadEnabled = true;
hotWeapon.reloadComponent.reloadDuration = 2;
hotWeapon.reloadComponent.animationAssetId = "4171";
hotWeapon.recoilForceEnabled = true;
hotWeapon.recoilForceComponent.minHorizontalOffset = 1;
hotWeapon.recoilForceComponent.maxHorizontalOffset = 1;
hotWeapon.recoilForceComponent.minVerticalOffset = 1;
hotWeapon.recoilForceComponent.maxVerticalOffset = 1;
hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
hotWeapon.recoilForceComponent.minVerticalJitter = 1;
hotWeapon.recoilForceComponent.maxVerticalJitter = 1;
hotWeapon.accuracyOfFireEnabled = true;
// 影响射击精度的子弹偏移半角的最大值(范围Min~88)
hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
// 影响射击精度的子弹偏移半角的最小值(范围0~Max)
hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
// 默认影响射击精度的子弹偏移半角(范围Min~Max)
hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
// 影响射击精度的子弹偏移半角的每秒扩张速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
// 影响射击精度的子弹偏移半角的每秒收缩速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
// 影响射击精度的子弹偏移半角的每次开火扩张值(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
hotWeapon.onEquip.add((owner) => { console.log("热武器装备好了后会在服务器端触发回调") });
hotWeapon.onUnequip.add(() => { console.log("onUnequippedServer") });
hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });
hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
mw.Event.addClientListener("weaponEquipment", (player) => {
// 目前装备方法只能在服务端调用
hotWeapon.equip(player.character, HumanoidSlotType.RightHand);
});
} else if (SystemUtil.isClient()) {
hotWeapon.onEquip.add(() => { console.log("onEquippedClient") });
hotWeapon.onUnequip.add(() => { console.log("onUnequippedClient") });
hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });
hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });
hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
// 装备
InputUtil.onKeyDown(Keys.One, () => {
mw.Event.dispatchToServer("weaponEquipment");
});
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
hotWeapon.stopFire();
} else {
hotWeapon.startFire();
}
});
InputUtil.onKeyDown(Keys.Three, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
hotWeapon.breakReload();
} else {
hotWeapon.reload(30);
}
});
InputUtil.onKeyDown(Keys.Four, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
hotWeapon.breakLoad();
} else {
hotWeapon.load();
}
});
}
}
}
@Component
export default class HotWeaponSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.fireComponent.isFireOnScreenCenter = false
hotWeapon.fireComponent.clipSize = 50
hotWeapon.fireComponent.fireInterval = 0
hotWeapon.fireComponent.multipleShot = 3
hotWeapon.fireComponent.isFireOnScreenCenter = false
hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
// 设置参数
hotWeapon.fireComponent.animationAssetId = "80484";
hotWeapon.fireComponent.fireMode = HotWeaponFireMode.SingleFire;
hotWeapon.aimEnabled = true;
// 切换瞄准时的 第一/第三 人称
hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
// 设置模拟瞄准时的倍镜放大倍数(仅第一人称瞄准时生效,范围1~18)
hotWeapon.aimComponent.aimingZoom = 16;
hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
hotWeapon.loadEnabled = true;
hotWeapon.loadComponent.loadDuration = 1
hotWeapon.loadComponent.loadAfterFireEnabled = true;
hotWeapon.loadComponent.animationAssetId = "4172";
hotWeapon.reloadEnabled = true;
hotWeapon.reloadComponent.reloadDuration = 2;
hotWeapon.reloadComponent.animationAssetId = "4171";
hotWeapon.recoilForceEnabled = true;
hotWeapon.recoilForceComponent.minHorizontalOffset = 1;
hotWeapon.recoilForceComponent.maxHorizontalOffset = 1;
hotWeapon.recoilForceComponent.minVerticalOffset = 1;
hotWeapon.recoilForceComponent.maxVerticalOffset = 1;
hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
hotWeapon.recoilForceComponent.minVerticalJitter = 1;
hotWeapon.recoilForceComponent.maxVerticalJitter = 1;
hotWeapon.accuracyOfFireEnabled = true;
// 影响射击精度的子弹偏移半角的最大值(范围Min~88)
hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
// 影响射击精度的子弹偏移半角的最小值(范围0~Max)
hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
// 默认影响射击精度的子弹偏移半角(范围Min~Max)
hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
// 影响射击精度的子弹偏移半角的每秒扩张速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
// 影响射击精度的子弹偏移半角的每秒收缩速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
// 影响射击精度的子弹偏移半角的每次开火扩张值(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
hotWeapon.onEquip.add((owner) => { console.log("热武器装备好了后会在服务器端触发回调") });
hotWeapon.onUnequip.add(() => { console.log("onUnequippedServer") });
hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });
hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
mw.Event.addClientListener("weaponEquipment", (player) => {
// 目前装备方法只能在服务端调用
hotWeapon.equip(player.character, HumanoidSlotType.RightHand);
});
} else if (SystemUtil.isClient()) {
hotWeapon.onEquip.add(() => { console.log("onEquippedClient") });
hotWeapon.onUnequip.add(() => { console.log("onUnequippedClient") });
hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoadClient") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoadClient") });
hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForceClient") });
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReloadClient") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReloadClient") });
hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
// 装备
InputUtil.onKeyDown(Keys.One, () => {
mw.Event.dispatchToServer("weaponEquipment");
});
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
hotWeapon.stopFire();
} else {
hotWeapon.startFire();
}
});
InputUtil.onKeyDown(Keys.Three, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
hotWeapon.breakReload();
} else {
hotWeapon.reload(30);
}
});
InputUtil.onKeyDown(Keys.Four, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
hotWeapon.breakLoad();
} else {
hotWeapon.load();
}
});
}
}
}
Hierarchy
↳
HotWeapon
Table of contents
Properties
accuracyOfFireComponent: HotWeaponAccuracyOfFireComponent |
---|
射击精度功能。 |
aimComponent: HotWeaponAimComponent |
瞄准功能。 |
fireComponent: HotWeaponFireComponent |
射击功能。 |
loadComponent: HotWeaponLoadComponent |
上膛功能。 |
onEquip: MulticastDelegateInterface <(EquipOwner : $Nullable <Actor >) => void > |
装备热武器时执行绑定函数 |
onUnequip: MulticastDelegateInterface <() => void > |
服务器卸载时执行绑定函数。使用示例见属性 onEquipped |
recoilForceComponent: HotWeaponRecoilForceComponent |
后坐力功能。 |
reloadComponent: HotWeaponReloadComponent |
换弹功能。 |
click
Properties
onBeforeDestroyDelegate: MulticastDelegate <() => void > |
---|
物体销毁前事件回调 |
onCustomPropertyChange: Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
监听自定义属性同步事件 |
onDestroyDelegate: MulticastDelegate <() => void > |
物体销毁后事件回调 |
Accessors
accuracyOfFireEnabled(): boolean |
---|
是否开启了射击精度组件。 |
aimEnabled(): boolean |
是否开启了瞄准组件。 |
loadEnabled(): boolean |
是否开启了上膛组件。 |
recoilForceEnabled(): boolean |
获取是否开启了后坐力组件。 |
reloadEnabled(): boolean |
是否开启了换弹组件。 |
click
Accessors
actorFlagValue(): number other |
---|
获取对象标记 |
actorLevel(): number other |
获取Actor等级 |
assetId(): string |
获取当前物体使用资源的GUID |
gameObjectId(): string |
获取物体的唯一标识(唯一标识一个对象的字符串)。 |
isDestroyed(): boolean |
当前物体是否被销毁 |
isReady(): boolean |
当前物体状态 |
localTransform(): Transform |
当前物体本地变换 |
name(): string |
返回当前物体名称 |
netStatus(): NetStatus |
获取当前物体同步状态 |
parent(): GameObject |
获取当前父物体 |
tag(): string |
获取当前物体的标签 |
worldTransform(): Transform |
当前物体世界变换 |
Methods
breakLoad(): void other |
---|
打断上膛。 |
breakReload(): void other |
打断换弹 |
cloneComponentsData(otherHotWeapon : HotWeapon ): void server |
从传入的热武器逻辑对象中拷贝所有组件数据到当前的热武器中。 |
equip(character : Character , slotName : HumanoidSlotType ): void other |
装备热武器到角色的指定插槽位置 |
getBulletLocWhileSpawnOnScreenCenter(): Vector client |
使用屏幕中心生成子弹投掷物模式时,获取子弹投掷物生成的location |
getCurrentOwner(): Character |
获取当前热武器的所有者 |
getCurrentState(): HotWeaponState |
获取当前热武器状态 |
getDefaultCrossHairSize(maxShootRange : number ): number client |
传入最大射程,获取默认准星大小 |
getShootDirWithDispersion(StartLoc : Vector , ShootRange : number ): Vector client |
非屏幕中心生成子弹模式下,获取子弹飞行方向 |
load(): void other |
上膛 |
reload(bulletSize : number ): void other |
换弹 |
startFire(): void other |
开火 |
stopFire(): void other |
停止开火 |
unequip(): void other |
卸载热武器。 |
click
Methods
addComponent<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >, bInReplicates? : boolean ): T : extends Script <T > |
---|
添加一个脚本组件 |
asyncGetChildByName(name : string ): Promise <GameObject > |
异步根据名称查找子物体 |
asyncReady(): Promise <GameObject > |
物体准备好后返回 |
clone(gameObjectInfo? : GameObjectInfo ): GameObject |
复制对象 |
destroy(): void |
删除对象 |
getBoundingBox(nonColliding? : boolean , includeFromChild? : boolean , outer? : Vector ): Vector |
获取物体包围盒大小 |
getBounds(onlyCollidingComponents : boolean , originOuter : Vector , boxExtentOuter : Vector , includeFromChild? : boolean ): void |
获取物体边界 |
getChildByGameObjectId(gameObjectId : string ): GameObject |
根据 gameObjectId 查找子物体 |
getChildByName(name : string ): GameObject |
根据名称查找子物体 |
getChildByPath(path : string ): GameObject |
根据路径查找子物体 |
getChildren(): GameObject [] |
获取子物体 |
getChildrenBoundingBoxCenter(outer? : Vector ): Vector |
获取所有子对象包围盒中心点(不包含父对象,父对象不可用返回[0,0,0]) |
getChildrenByName(name : string ): GameObject [] |
通过名字查找所有的子物体 |
getComponent<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T > |
获取指定类型的组件 |
getComponentPropertys<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >): Map <string , IPropertyOptions > |
获取脚本组件属性 |
getComponents<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T >[] |
获取指定类型的所有组件 |
getCustomProperties(): string [] |
获取所有自定义属性 |
getCustomProperty<T : extends CustomPropertyType >(propertyName : string ): T : extends CustomPropertyType |
获取自定义属性 |
getCustomPropertyChangeDelegate(property ): Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
给定对象属性修改时触发的事件代理 |
getVisibility(): boolean |
获取物体是否被显示 |
isPrefabActor(): boolean |
返回当前物体是否为预制体 |
moveBy(velocity : Vector , isLocal? : boolean ): void other |
按给定的速度矢量随时间平滑地移动对象 |
moveTo(targetPosition : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
在指定时间内从当前位置平滑移动至目标位置 |
rotateBy(rotation : Quaternion Rotation , multiplier : number , isLocal? : boolean ): void other |
按给定的旋转量随时间平滑地旋转对象 |
rotateTo(targetRotation : Quaternion Rotation , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
在指定时间内从当前旋转平滑变化至目标旋转 |
scaleBy(scale : Vector , isLocal? : boolean ): void other |
按每秒给定的缩放矢量随时间平滑缩放对象 |
scaleTo(targetScale : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
在指定时间内从当前缩放平滑变化至目标缩放 |
setAbsolute(absolutePosition? : boolean , absoluteRotation? : boolean , absoluteScale? : boolean ): void |
设置物体localTransform是相对于父物体或者世界 |
setCustomProperty(propertyName : string , value : undefined CustomPropertyType ): void |
设置自定义属性 |
setVisibility(status : boolean PropertyStatus , propagateToChildren? : boolean ): void |
设置物体是否被显示 |
stopMove(): void other |
中断moveTo()、moveBy()的进一步移动 |
stopRotate(): void other |
中断从rotateTo()或rotateBy()的进一步旋转 |
stopScale(): void other |
中断从ScaleTo()或ScaleBy()的进一步缩放 |
asyncFindGameObjectById(gameObjectId : string ): Promise <GameObject > |
通过 gameObjectId 异步查找 GameObject |
asyncGetGameObjectByPath(path : string ): Promise <GameObject > |
通过路径异步查找物体 |
asyncSpawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): Promise <T : extends GameObject <T >> |
异步构造一个物体 |
bulkPivotTo(gameObjects : GameObject [], transforms : Transform []): void |
批量设置位置 |
findGameObjectById(gameObjectId : string ): GameObject |
通过 gameObjectId 查找物体 |
findGameObjectByName(name : string ): GameObject |
通过名字查找物体 |
findGameObjectsByName(name : string ): GameObject [] |
通过名字查找物体 |
findGameObjectsByTag(tag : string ): GameObject [] |
通过自定义标签获取物体 |
getGameObjectByPath(path : string ): GameObject |
通过路径查找物体 |
spawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): T : extends GameObject <T > |
构造一个物体 |
Properties
accuracyOfFireComponent
• accuracyOfFireComponent: HotWeaponAccuracyOfFireComponent
射击精度功能。
此功能可以看做 hotweapon 的功能组件,只限于热武器使用。
使用示例: 创建一个名为"HotWeaponAofSample"的脚本,放置在对象管理器中,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponAofSample extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.accuracyOfFireEnabled = true;
// 影响射击精度的子弹偏移半角的最大值(范围Min~88)
hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
// 影响射击精度的子弹偏移半角的最小值(范围0~Max)
hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
// 默认影响射击精度的子弹偏移半角(范围Min~Max)
hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
// 影响射击精度的子弹偏移半角的每秒扩张速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
// 影响射击精度的子弹偏移半角的每秒收缩速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
// 影响射击精度的子弹偏移半角的每次开火扩张值(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
} else if (SystemUtil.isClient()) {
hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
}
}
}
@Component
export default class HotWeaponAofSample extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.accuracyOfFireEnabled = true;
// 影响射击精度的子弹偏移半角的最大值(范围Min~88)
hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
// 影响射击精度的子弹偏移半角的最小值(范围0~Max)
hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
// 默认影响射击精度的子弹偏移半角(范围Min~Max)
hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
// 影响射击精度的子弹偏移半角的每秒扩张速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
// 影响射击精度的子弹偏移半角的每秒收缩速度(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
// 影响射击精度的子弹偏移半角的每次开火扩张值(范围0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
} else if (SystemUtil.isClient()) {
hotWeapon.accuracyOfFireComponent.onCurrentDispersionChange.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
}
}
}
aimComponent
• aimComponent: HotWeaponAimComponent
瞄准功能。
使用示例: 创建一个名为"HotWeaponAimSample1"的脚本,放置在对象管理器中,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponAimSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.aimEnabled = true;
hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
hotWeapon.aimComponent.aimingZoom = 16;
hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
} else if (SystemUtil.isClient()) {
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
}
}
}
@Component
export default class HotWeaponAimSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.aimEnabled = true;
hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
hotWeapon.aimComponent.aimingZoom = 16;
hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
} else if (SystemUtil.isClient()) {
hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
}
}
}
fireComponent
• fireComponent: HotWeaponFireComponent
射击功能。
使用示例: 创建一个名为"HotWeaponFireSample1"的脚本,放置在对象管理器热武器的子节点中,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponFireSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.fireComponent.isFireOnScreenCenter = false;
hotWeapon.fireComponent.clipSize = 50;
hotWeapon.fireComponent.fireInterval = 0;
hotWeapon.fireComponent.multipleShot = 3;
hotWeapon.fireComponent.isFireOnScreenCenter = false;
hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
// 设置参数
hotWeapon.fireComponent.animationAssetId = "80484";
hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });
}
}
}
@Component
export default class HotWeaponFireSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.fireComponent.isFireOnScreenCenter = false;
hotWeapon.fireComponent.clipSize = 50;
hotWeapon.fireComponent.fireInterval = 0;
hotWeapon.fireComponent.multipleShot = 3;
hotWeapon.fireComponent.isFireOnScreenCenter = false;
hotWeapon.fireComponent.offsetOfFireOnScreenCenter = new Vector(100, 30, 0);
// 设置参数
hotWeapon.fireComponent.animationAssetId = "80484";
hotWeapon.fireComponent.onStartFire.add(() => { console.log("fireComponent.onStartFireClient") });
hotWeapon.fireComponent.onEndFire.add(() => { console.log("fireComponent.onEndFireClient") });
hotWeapon.fireComponent.onEndContinuousFire.add(() => { console.log("fireComponent.onEndFireClient") });
}
}
}
loadComponent
• loadComponent: HotWeaponLoadComponent
上膛功能。
使用示例: 创建一个名为"HotWeaponLoadSample1"的脚本,放置在对象管理器中,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponLoadSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.loadEnabled = true;
hotWeapon.loadComponent.loadDuration = 1
hotWeapon.loadComponent.loadAfterFireEnabled = true;
hotWeapon.loadComponent.animationAssetId = "4172";
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Server") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Server") });
} else if (SystemUtil.isClient()) {
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Client") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Client") });
}
}
}
@Component
export default class HotWeaponLoadSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.loadEnabled = true;
hotWeapon.loadComponent.loadDuration = 1
hotWeapon.loadComponent.loadAfterFireEnabled = true;
hotWeapon.loadComponent.animationAssetId = "4172";
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Server") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Server") });
} else if (SystemUtil.isClient()) {
hotWeapon.loadComponent.onStartLoad.add(() => { console.log("loadComponent.onStartLoad Client") });
hotWeapon.loadComponent.onEndLoad.add(() => { console.log("loadComponent.onEndLoad Client") });
}
}
}
onEquip
• onEquip: MulticastDelegateInterface
<(EquipOwner
: $Nullable
<Actor
>) => void
>
装备热武器时执行绑定函数
此委托可双端执行。当你在服务端调用时,角色装备上热武器时会在服务端执行自定义绑定函数;在客户端调用时,角色装备上热武器时会在客户端执行自定义绑定函数。
使用示例: 创建一个名为"HotWeaponSample2"的脚本,放置在对象管理器中热武器对象子级,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponSample2 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.onEquip.add((owner) => { console.log("热武器装备好了后会在服务器端触发回调") });
hotWeapon.onUnequip.add(() => { console.log("onUnequipServer") });
} else if (SystemUtil.isClient()) {
hotWeapon.onEquip.add(() => { console.log("onEquip Client") });
hotWeapon.onUnequip.add(() => { console.log("onUnequip Client") });
}
}
}
@Component
export default class HotWeaponSample2 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.onEquip.add((owner) => { console.log("热武器装备好了后会在服务器端触发回调") });
hotWeapon.onUnequip.add(() => { console.log("onUnequipServer") });
} else if (SystemUtil.isClient()) {
hotWeapon.onEquip.add(() => { console.log("onEquip Client") });
hotWeapon.onUnequip.add(() => { console.log("onUnequip Client") });
}
}
}
onUnequip
• onUnequip: MulticastDelegateInterface
<() => void
>
服务器卸载时执行绑定函数。使用示例见属性 onEquipped
recoilForceComponent
• recoilForceComponent: HotWeaponRecoilForceComponent
后坐力功能。
使用示例: 创建一个名为"HotWeaponRecoilForceSample"的脚本,放置在对象管理器中,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponRecoilForceSample extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.recoilForceEnabled = true;
hotWeapon.recoilForceComponent.minHorizontalOffset = 1
hotWeapon.recoilForceComponent.maxHorizontalOffset = 1
hotWeapon.recoilForceComponent.minVerticalOffset = 1
hotWeapon.recoilForceComponent.maxVerticalOffset = 1
hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
hotWeapon.recoilForceComponent.minVerticalJitter = 1;
hotWeapon.recoilForceComponent.maxVerticalJitter = 1;
}
hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForce") });
}
}
@Component
export default class HotWeaponRecoilForceSample extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.recoilForceEnabled = true;
hotWeapon.recoilForceComponent.minHorizontalOffset = 1
hotWeapon.recoilForceComponent.maxHorizontalOffset = 1
hotWeapon.recoilForceComponent.minVerticalOffset = 1
hotWeapon.recoilForceComponent.maxVerticalOffset = 1
hotWeapon.recoilForceComponent.minHorizontalJitter = 1;
hotWeapon.recoilForceComponent.maxHorizontalJitter = 1;
hotWeapon.recoilForceComponent.minVerticalJitter = 1;
hotWeapon.recoilForceComponent.maxVerticalJitter = 1;
}
hotWeapon.recoilForceComponent.onStartRecoil.add(() => { console.log("recoilForceComponent.onStartRecoilForce") });
}
}
reloadComponent
• reloadComponent: HotWeaponReloadComponent
换弹功能。
使用示例: 创建一个名为"HotWeaponReloadSample1"的脚本,放置在对象管理器中,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponReloadSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.reloadEnabled = true;
hotWeapon.reloadComponent.reloadDuration = 2;
hotWeapon.reloadComponent.animationAssetId = "4171";
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Server") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Server") });
} else if (SystemUtil.isClient()) {
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Client") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Client") });
}
}
}
@Component
export default class HotWeaponReloadSample1 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.reloadEnabled = true;
hotWeapon.reloadComponent.reloadDuration = 2;
hotWeapon.reloadComponent.animationAssetId = "4171";
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Server") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Server") });
} else if (SystemUtil.isClient()) {
hotWeapon.reloadComponent.onStartReload.add(() => { console.log("reloadComponent.onStartReload Client") });
hotWeapon.reloadComponent.onEndReload.add(() => { console.log("reloadComponent.onEndReload Client") });
}
}
}
Accessors
accuracyOfFireEnabled
• | • | ||||
---|---|---|---|---|---|
是否开启了射击精度组件。 Returns
| 设置是否开启射击精度组件。 默认开启 Parameters
|
aimEnabled
• | • | ||||
---|---|---|---|---|---|
是否开启了瞄准组件。 Returns
| 设置是否开启瞄准组件。 默认开启 Parameters
|
loadEnabled
• | • | ||||
---|---|---|---|---|---|
是否开启了上膛组件。 Returns
| 设置是否开启上膛组件。 默认开启 Parameters
|
recoilForceEnabled
• | • | ||||
---|---|---|---|---|---|
获取是否开启了后坐力组件。 Returns
| 设置是否开启后座力组件。 默认开启 Parameters
|
reloadEnabled
• | • | ||||
---|---|---|---|---|---|
是否开启了换弹组件。 Returns
| 设置是否开启换弹组件。 默认开启 Parameters
|
Methods
breakLoad
• breakLoad(): void
other
打断上膛。
使用示例: 创建一个名为"HotWeaponSample10"的脚本,放置在对象管理器中热武器对象子级,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponSample10 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
hotWeapon.breakLoad();
} else {
hotWeapon.load();
}
});
}
}
}
@Component
export default class HotWeaponSample10 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
hotWeapon.breakLoad();
} else {
hotWeapon.load();
}
});
}
}
}
breakReload
• breakReload(): void
other
打断换弹
使用示例: 创建一个名为"HotWeaponSample9"的脚本,放置在对象管理器中热武器对象子级,打开脚本,输入以下代码保存,运行游戏,按下"2"键,热武器换弹,中止换弹,代码如下:ts
@Component
export default class HotWeaponSample9 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
hotWeapon.breakReload();
} else {
hotWeapon.reload(30);
}
});
}
}
}
@Component
export default class HotWeaponSample9 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
hotWeapon.breakReload();
} else {
hotWeapon.reload(30);
}
});
}
}
}
cloneComponentsData
• cloneComponentsData(otherHotWeapon
): void
server
从传入的热武器逻辑对象中拷贝所有组件数据到当前的热武器中。
Parameters
otherHotWeapon HotWeapon | 数据源。 |
---|
Precautions
无法拷贝代理委托绑定事件,完成拷贝后,数据同步到客户端有较短延迟。
equip
• equip(character
, slotName
): void
other
装备热武器到角色的指定插槽位置
Parameters
character Character | 该武器的装备对象 |
---|---|
slotName HumanoidSlotType | 要装备到角色上的插槽名称 |
如果想将武器装备在角色身上,需要在服务端调用此函数。客户端调用不会报错,但不生效。
使用示例: 创建一个名为"HotWeaponSample"的脚本,打开脚本,输入以下代码保存,此示例为动态加载热武器与武器模型资源,不需要在右侧栏配置,运行游戏,一个热武器装备到角色右手上,代码如下:ts
@Component
export default class weapon extends Script {
private hotweapon:HotWeapon;
private gun:Model;
protected async onStart(): Promise<void> {
if(SystemUtil.isServer()) {
this.hotweapon = await GameObject.asyncSpawn<HotWeapon>("HotWeapon",{
replicates:true,
transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
});
this.gun = await GameObject.asyncSpawn<Model>("44980",{
replicates:true,
transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
});
this.gun.parent = this.hotweapon;
this.gun.setCollision(PropertyStatus.Off);
Player.onPlayerJoin.add(()=>{
Player.getAllPlayers().forEach(element => {
this.player = element.character;
});
this.hotweapon.equip(this.player,HumanoidSlotType.RightHand);
})
}
}
}
@Component
export default class weapon extends Script {
private hotweapon:HotWeapon;
private gun:Model;
protected async onStart(): Promise<void> {
if(SystemUtil.isServer()) {
this.hotweapon = await GameObject.asyncSpawn<HotWeapon>("HotWeapon",{
replicates:true,
transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
});
this.gun = await GameObject.asyncSpawn<Model>("44980",{
replicates:true,
transform: new Transform(new Vector(500,0,0), new Rotation(0, 0, 0), new Vector(1)),
});
this.gun.parent = this.hotweapon;
this.gun.setCollision(PropertyStatus.Off);
Player.onPlayerJoin.add(()=>{
Player.getAllPlayers().forEach(element => {
this.player = element.character;
});
this.hotweapon.equip(this.player,HumanoidSlotType.RightHand);
})
}
}
}
getBulletLocWhileSpawnOnScreenCenter
• getBulletLocWhileSpawnOnScreenCenter(): Vector
client
使用屏幕中心生成子弹投掷物模式时,获取子弹投掷物生成的location
Returns
Vector | 子弹投掷物生成的location |
---|
Precautions
服务器没有角色相机组件
ts
@Component
export default class HotWeaponSample5 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
const bulletLoc = hotWeapon.getBulletLocWhileSpawnOnScreenCenter()
// 省略:生成投掷物
}
}
}
@Component
export default class HotWeaponSample5 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
const bulletLoc = hotWeapon.getBulletLocWhileSpawnOnScreenCenter()
// 省略:生成投掷物
}
}
}
getCurrentOwner
• getCurrentOwner(): Character
获取当前热武器的所有者
Returns
Character | 当前热武器的所有者 |
---|
ts
@Component
export default class HotWeaponSample6 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
const hotWeaponOwner = hotWeapon.getCurrentOwner()
}
}
@Component
export default class HotWeaponSample6 extends Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as HotWeapon;
const hotWeaponOwner = hotWeapon.getCurrentOwner()
}
}
getCurrentState
• getCurrentState(): HotWeaponState
获取当前热武器状态
Returns
HotWeaponState | 当前热武器状态 |
---|
ts
@Component
export default class HotWeaponSample11 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
// 热武器需要先装备上,见方法 equipment
const status = hotWeapon.getCurrentState();
}
}
@Component
export default class HotWeaponSample11 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
// 热武器需要先装备上,见方法 equipment
const status = hotWeapon.getCurrentState();
}
}
getDefaultCrossHairSize
• getDefaultCrossHairSize(maxShootRange
): number
client
传入最大射程,获取默认准星大小
Parameters
maxShootRange number | 最大射程 default:100 range:[0,100000] type:浮点数 |
---|
Returns
number | 默认准星大小(射击精度半角值) |
---|
ts
@Component
export default class HotWeaponSample3 extends mw.Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as mw.HotWeapon;
if (SystemUtil.isClient()) {
// 传入射程,得到准心扩散大小
const crossHairSize = hotWeapon.getDefaultCrossHairSize(1000)
// 省略:更新 UI 准心位置
}
}
}
@Component
export default class HotWeaponSample3 extends mw.Script {
protected onStart(): void {
// 构造
const hotWeapon = this.gameObject as mw.HotWeapon;
if (SystemUtil.isClient()) {
// 传入射程,得到准心扩散大小
const crossHairSize = hotWeapon.getDefaultCrossHairSize(1000)
// 省略:更新 UI 准心位置
}
}
}
getShootDirWithDispersion
• getShootDirWithDispersion(StartLoc
, ShootRange
): Vector
client
非屏幕中心生成子弹模式下,获取子弹飞行方向
Parameters
StartLoc Vector | 子弹生成位置 |
---|---|
ShootRange number | 最大射程 default:100 range:[0, 100000] type:浮点数 |
Returns
Vector | 子弹的实际飞行方向 |
---|
Precautions
该函数可传入经偏移了的屏幕中心发出的射线方向
Precautions
服务器没有角色相机组件
load
• load(): void
other
上膛
使用示例: 创建一个名为"HotWeaponSample10"的脚本,放置在对象管理器中热武器对象子级,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponSample10 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
hotWeapon.breakLoad();
} else {
hotWeapon.load();
}
});
}
}
}
@Component
export default class HotWeaponSample10 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Loading) {
hotWeapon.breakLoad();
} else {
hotWeapon.load();
}
});
}
}
}
reload
• reload(bulletSize
): void
other
换弹
Parameters
bulletSize number | 子弹数 range:[1, ClipSize] type: 整数 |
---|
ts
@Component
export default class HotWeaponSample9 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
hotWeapon.breakReload();
} else {
hotWeapon.reload(30);
}
});
}
}
}
@Component
export default class HotWeaponSample9 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Reloading) {
hotWeapon.breakReload();
} else {
hotWeapon.reload(30);
}
});
}
}
}
startFire
• startFire(): void
other
开火
使用示例: 创建一个名为"HotWeaponSample8"的脚本,放置在对象管理器中热武器对象子级,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponSample8 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
hotWeapon.stopFire();
} else {
hotWeapon.startFire();
}
});
}
}
}
@Component
export default class HotWeaponSample8 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
hotWeapon.stopFire();
} else {
hotWeapon.startFire();
}
});
}
}
}
stopFire
• stopFire(): void
other
停止开火
使用示例: 创建一个名为"HotWeaponSample8"的脚本,放置在对象管理器中热武器对象子级,打开脚本,输入以下代码保存,运行游戏,代码如下:ts
@Component
export default class HotWeaponSample8 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
hotWeapon.stopFire();
} else {
hotWeapon.startFire();
}
});
}
}
}
@Component
export default class HotWeaponSample8 extends Script {
protected onStart(): void {
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isClient()) {
// 热武器需要先装备上,见方法 equipment
InputUtil.onKeyDown(Keys.Two, () => {
// 开始执行操作
if (hotWeapon.getCurrentState() == HotWeaponState.Firing) {
hotWeapon.stopFire();
} else {
hotWeapon.startFire();
}
});
}
}
}
unequip
• unequip(): void
other
卸载热武器。