Skip to content

Commit

Permalink
Equip Sound
Browse files Browse the repository at this point in the history
  • Loading branch information
“包饭厅” committed Nov 14, 2023
1 parent 69a807b commit c629270
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
17 changes: 16 additions & 1 deletion Source/ARPG/Item/Weapon/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@

#include "Weapon.h"
#include "ARPG/Character/Character01.h"
#include "Kismet/GameplayStatics.h"
#include "Components/SphereComponent.h"

void AWeapon::Equip(USceneComponent* InParent, FName InSocketName)
{ //附加组件到socket
{
// 调用 AttachMeshToSocket 函数将武器的 Mesh 附加到指定的骨骼插槽上
AttachMeshToSocket(InParent, InSocketName);

// 设置武器的状态为在手上
ItemState = EItemState::EIS_OnHand;

// 如果设置了装备音效,就在武器的位置播放音效
if (EquipSound)
{
UGameplayStatics::PlaySoundAtLocation(this, EquipSound, GetActorLocation());
}
if (Sphere)
{
Sphere->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}
}

void AWeapon::AttachMeshToSocket(USceneComponent* InParent, const FName& InSocketName)
Expand Down
14 changes: 11 additions & 3 deletions Source/ARPG/Item/Weapon/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@
/**
*
*/
class USoundBase;

UCLASS()
class ARPG_API AWeapon : public Aitem
{
GENERATED_BODY()

public:
// 装备武器的函数,将武器附加到指定的骨骼插槽上
void Equip(USceneComponent* InParent, FName InSocketName);

void Equip(USceneComponent* InParent,FName InSocketName);
// 将武器的Mesh附加到指定的骨骼插槽上
void AttachMeshToSocket(USceneComponent* InParent, const FName& InSocketName);

// 重写基类的碰撞开始函数,用于处理武器的特定碰撞逻辑
virtual void OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) override;


// 重写基类的碰撞结束函数,用于处理武器的特定碰撞结束逻辑
virtual void EndSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) override;


// 武器装备时播放的音效
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
USoundBase* EquipSound;
};

6 changes: 4 additions & 2 deletions Source/ARPG/Item/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class ARPG_API Aitem : public AActor
UPROPERTY(BlueprintReadWrite)
EItemState ItemState = EItemState::EIS_UnOnHand;

UPROPERTY(VisibleAnywhere)
USphereComponent* Sphere;

protected:
virtual void BeginPlay() override;

Expand All @@ -51,8 +54,7 @@ class ARPG_API Aitem : public AActor
UPROPERTY(VisibleAnywhere,BlueprintReadonly,meta = (AllowPrivateAccess = "true"))
float RunningTime = 0.f;

UPROPERTY(VisibleAnywhere)
USphereComponent* Sphere;



};
Expand Down

0 comments on commit c629270

Please sign in to comment.