可以多探索探索嘛,不用等着喂饭
上面那个就是封装好的模块,你直接调就行了
试一试就出来了,按U\I\O\P给手上换不同的模型
@Core.Class
export default class NewScript extends Core.Script {
/**角色_插槽:装备静态模型 */
public charEquipMents: Map<string, Gameplay.StaticMesh> = new Map();
/**装备/去除装备
* @param Attacker 需要执行装备操作的玩家
* @param guid 装备的静态模型guid,<0则视为要清除该插槽的装备
* @param location 装备的相对位置
* @param scale 装备的相对缩放
* @param rotate 装备的相对选装
* @param SlotType 装备需要装在角色的哪个插槽,常用15左手|16右手|12背部,已有的话会清除旧的装新的,如果guid<0且SlotType<0即清除身上所有装备
*/
@Core.Function(Core.Server)
public serverEquipMe(Attacker: Gameplay.Player, guid: string, location: Vector, scale: Vector, rotate: Rotation, SlotType: number) {
location = new Vector(location.x, location.y, location.z);
scale = new Vector(scale.x, scale.y, scale.z);
rotate = new Rotation(rotate.x, rotate.y, rotate.z);
let pid = Attacker.getUserSystemId();
let equipId = "Peqp_" + pid + SlotType.toString();
if (Number(guid) <= 0) {
if (SlotType > 0) {
if (this.charEquipMents.get(equipId)) {
this.charEquipMents.get(equipId).destroy();
this.charEquipMents.delete(equipId);
}
}
else {
// this.serverDetachAllEquip(Attacker);
}
} else {
if (!AssetUtil.assetLoaded(guid)) {
AssetUtil.asyncDownloadAsset(guid).then(() => {
if (this.charEquipMents.get(equipId)) {
this.charEquipMents.get(equipId).destroy();
}
Core.GameObject.asyncSpawn({ guid: guid, transform: new Transform(new Vector(0, 0, -1000), rotate, scale) }).then((equipItem: Gameplay.GameObject) => {
if (equipItem instanceof Gameplay.StaticMesh) {
equipItem.setCollision(2);
this.charEquipMents.set(equipId, equipItem);
Attacker.character.attach(equipItem, SlotType);
equipItem.relativeLocation = location;
}
})
})
} else {
if (this.charEquipMents.get(equipId)) {
this.charEquipMents.get(equipId).destroy();
}
Core.GameObject.asyncSpawn({ guid: guid, transform: new Transform(new Vector(0, 0, -1000), rotate, scale) }).then((equipItem: Gameplay.GameObject) => {
if (equipItem instanceof Gameplay.StaticMesh) {
equipItem.setCollision(2);
this.charEquipMents.set(equipId, equipItem);
Attacker.character.attach(equipItem, SlotType);
equipItem.relativeLocation = location;
}
})
}
}
}
/** 当脚本被实例后,会在第一帧更新前调用此函数 */
protected onStart(): void {
if (SystemUtil.isClient()) {
let Attacker = Gameplay.getCurrentPlayer();
InputUtil.onKeyDown(Keys.U, () => {
this.serverEquipMe(Attacker, "7669", Vector.zero, Vector.one, Rotation.zero, 16);
})
InputUtil.onKeyDown(Keys.I, () => {
this.serverEquipMe(Attacker, "7681", Vector.zero, Vector.one, Rotation.zero, 16);
})
InputUtil.onKeyDown(Keys.O, () => {
this.serverEquipMe(Attacker, "7701", Vector.zero, Vector.one, Rotation.zero, 16);
})
InputUtil.onKeyDown(Keys.P, () => {
this.serverEquipMe(Attacker, "-1", Vector.zero, Vector.one, Rotation.zero, 16);
})
}
}
/**
* 周期函数 每帧执行
* 此函数执行需要将this.useUpdate赋值为true
* @param dt 当前帧与上一帧的延迟 / 秒
*/
protected onUpdate(dt: number): void {
}
/** 脚本被销毁时最后一帧执行完调用此函数 */
protected onDestroy(): void {
}
}
|