ue4闊虫晥銆佸姩鐢荤粨鍚堝疄渚-- 鎴戣嚜宸卞晩

鍦ㄦ父鎴忎腑锛岃澶氶煶鏁堥渶瑕佸湪鍔ㄧ敾鎭板綋鐨勬椂鏈哄嚭鐜帮紝渚嬪琛岃蛋銆佸璺戯紝灏遍渶瑕佹伆濂藉湪瓒抽儴钀藉湴鐬棿鎾斁銆?/p>

鑰孉nimNotify灏辫兘闈炲父鏂逛究鍦板鐞嗘绫婚棶棰樸€?/p>

AnimNotify锛岄【鍚嶆€濅箟灏辨槸鍔ㄧ敾閫氱煡锛岃兘鍦ㄧ壒瀹氱殑鍔ㄧ敾鐗囨鎾斁鍒扮壒瀹氳繘搴︽椂鈥滃彂鍑烘秷鎭€濄€?/p>

鐩墠鎴戜滑鐨勫伐绋嬫湁鍓嶃€佸悗銆佸乏銆佸彸銆佸乏鍓嶃€佸彸鍓嶃€佸乏鍚庛€佸彸鍚庡叓鍚戠殑璺戝姩鍔ㄧ敾銆?/p>

鍏堜互鍚戝墠璺戜负渚?鐢ㄥ彸閿坊鍔犻€氱煡鐨勬柟寮忥紝鍒嗗埆鍦ㄥ彸鑴氥€佸乏鑴氳惤鍦版椂娣诲姞浜唋foot_touchground涓巖foot_touchground鐨勪袱涓嚜瀹氫箟閫氱煡

褰撶劧鐩存帴娣诲姞playsound閫氱煡涔熸槸鍙互鐨勶紝鑳藉緢鏂逛究鍦扮洿鎺ヨ缃0闊筹紝浣嗕负浜嗗姛鑳界殑鍙墿灞曟€ф垜浠繕鏄娇鐢ㄨ嚜瀹氫箟閫氱煡銆?/p>

鐒惰€屾垜浠浣曟墠鑳借幏鍙栬繖浜涢€氱煡鍛紵

if (mesh) {
        UAnimInstance* anim=mesh->GetAnimInstance();
        if (anim) {
            TArray<const struct FAnimNotifyEvent*> AnimNotifies=anim->NotifyQueue.AnimNotifies;
            range(i,0,AnimNotifies.Num()) {
                FString NotifyName=AnimNotifies[i]->NotifyName.ToString();
                /*GEngine->A/ddOnScreenDebugMessage
                (-1, 5.f, FColor::Red, FString::FromInt(i)+" "+ NotifyName);*/
                if (NotifyName=="lfoot_touchground") {
                    audio_lfoot->SetSound(sb_walks[0]);
                    audio_lfoot->Play();
                }
                else if (NotifyName == "rfoot_touchground") {
                    audio_rfoot->SetSound(sb_walks[1]);
                    audio_rfoot->Play();
                }
                else {

                }
            }
        }
    }

 

娌¢敊锛屽氨鏄繖涔堢畝鍗昦nim->NotifyQueue鍗充负鍔ㄧ敾閫氱煡闃熷垪,AnimNotifies灏辫兘鑾峰彇褰撳墠鎵€鏈夐€氱煡浜嬩欢锛屼笂杩颁唬鐮佸幓鎺夋敞閲婂嵆鍙墦鍗板綋鍓嶅抚鎵€鏈夊姩鐢婚€氱煡鍚嶇О銆?/p>

涓轰簡瀹炵幇鎾斁闊虫晥锛屾垜浠繕闇€瑕佺粦瀹氬湪宸﹀彸鑴氱殑AudioComponent锛屽鏋滃綋鍓嶉€氱煡闃熷垪涓湁瀵瑰簲鐨勯€氱煡锛屽氨鍏圫etSound璁剧疆灏嗚鎾斁鐨勫0闊宠祫婧愬悗鍐峆lay銆?/p>

鎴戞妸鎵€鏈夐渶瑕佺粦瀹氬湪Chracter鐨凪esh涓婄殑AudioComponent鈥滄墦鍖呰鍏モ€滀簡涓€涓彨AudioController鐨勭被锛屽湪Character鐨勬瀯閫犲嚱鏁颁腑杩涜浜咥udioController鐨勬瀯閫狅紝骞跺皢AudioController涓殑鍚勯煶鏁堢粍浠剁粦瀹氬埌瀵瑰簲鐨剆ocket涓娿€?/p>

 

AudioController.h鏂囦欢

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Components/ActorComponent.h"
#include "Components/AudioComponent.h"
#include "Components/SkeletalMeshComponent.h"
#include "AudioController.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYSOUNDANDEFFECTS_API UAudioController : public UActorComponent
{
    GENERATED_BODY()

public:    
    // Sets default values for this component's properties
    UAudioController();
    //UAudioController(USkeletalMeshComponent* mesh_);

protected:
    // Called when the game starts
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

    UPROPERTY(Category = Audio, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
        UAudioComponent* audio_lfoot = NULL;
    UPROPERTY(Category = Audio, EditDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
        FString bonename_lfoot = "Bip01-L-Foot";

    UPROPERTY(Category = Audio, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
        UAudioComponent* audio_rfoot = NULL;
    UPROPERTY(Category = Audio, EditDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
        FString bonename_rfoot = "Bip01-R-Foot";

    USkeletalMeshComponent* mesh = NULL;

    void my_init(USkeletalMeshComponent* mesh_);

    UPROPERTY(Category = Audio, EditDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
        TArray<class USoundBase*> sb_walks;
    
    
};

AudioController.cpp鏂囦欢

// Fill out your copyright notice in the Description page of Project Settings.

#include "MySoundAndEffects.h"
#include "Animation/AnimInstance.h"
#include "AudioController.h"


// Sets default values for this component's properties
UAudioController::UAudioController()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
    // off to improve performance if you don't need them.
    PrimaryComponentTick.bCanEverTick = true;
    // ...
    audio_lfoot = CreateDefaultSubobject<UAudioComponent>("audio_lfoot");
    audio_rfoot = CreateDefaultSubobject<UAudioComponent>("audio_rfoot");

}

//UAudioController::UAudioController(USkeletalMeshComponent* mesh_)
//{
//    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
//    // off to improve performance if you don't need them.
//    PrimaryComponentTick.bCanEverTick = true;
//
//    // ...
//    
//
//    
//}


void UAudioController::my_init(USkeletalMeshComponent* mesh_) {
    this->mesh = mesh_;
    //UAudioController();
    audio_lfoot->SetupAttachment(mesh_, FName(*bonename_lfoot));
    audio_rfoot->SetupAttachment(mesh_, FName(*bonename_rfoot));
}


// Called when the game starts
void UAudioController::BeginPlay()
{
    Super::BeginPlay();

    // ...
    
}


// Called every frame
void UAudioController::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

    // ...
    if (mesh) {
        UAnimInstance* anim=mesh->GetAnimInstance();
        if (anim) {
            TArray<const struct FAnimNotifyEvent*> AnimNotifies=anim->NotifyQueue.AnimNotifies;
            range(i,0,AnimNotifies.Num()) {
                FString NotifyName=AnimNotifies[i]->NotifyName.ToString();
                /*GEngine->A/ddOnScreenDebugMessage
                (-1, 5.f, FColor::Red, FString::FromInt(i)+" "+ NotifyName);*/
                if (NotifyName=="lfoot_touchground") {
                    audio_lfoot->SetSound(sb_walks[0]);
                    audio_lfoot->Play();
                }
                else if (NotifyName == "rfoot_touchground") {
                    audio_rfoot->SetSound(sb_walks[1]);
                    audio_rfoot->Play();
                }
                else {

                }
            }
        }
    }
    else {
        throw std::exception("mesh not exist!!");
    }

}

 

杩樻湁character绫讳腑audiocontroller鐨勫畾涔夊拰鍒涘缓锛?/p>

AAimPraticeHuman::AAimPraticeHuman()
{
#ifdef AudioController_h
	audiocontroller = CreateDefaultSubobject<UAudioController>("audiocontroller");
	audiocontroller->my_init(GetMesh());
#endif
}

銆€

UPROPERTY(Category = Audio, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
  class UAudioController* audiocontroller = NULL;

 

鏈€鍚庡氨鏄煶鏁堝鍏ワ紝鐪嬩技绠€鍗曞叾瀹炴湁寰堝缁嗚妭銆?/p>

寤鸿鐩存帴鎷栧叆wav鏍煎紡鏂囦欢锛屽鏋滃鍏ュけ璐ュ簲璇ユ槸wav鏂囦欢鍏蜂綋鍙傛暟鐨勯棶棰樸€?/p>

(鎴戠敤Audition鎶婁竴闀夸覆鐨勮窇姝ラ煶鏁堝垎鍓插嚭浜嗕袱澹拌剼纰板湴鐨勫0闊筹紝鐩存帴瀵煎叆ue4鎶ラ敊锛岀劧鑰屽厛鐢ㄦ牸寮忓伐鍘傝浆涓€涓嬪氨ok浜?

 

褰撶劧鐜板湪鐨勯煶鏁堣繕涓嶈兘鐩存帴鐢ㄤ簬娓告垙鑴氭锛岃繕闇€瑕佸厛璁剧疆骞跺彂鍜岀珛浣撴晥鏋溿€?/p>

Concurrency椤瑰嬀閫塷verride鍗冲彲锛屼娇鐢ㄢ€濆厛杩滃悗鏃р€滅殑骞跺彂鍋滄绛栫暐闂涔熶笉澶с€?/p>

Attenuation椤规垜鏂板缓浜嗕竴涓彨SceneSoundAttenuation钃濆浘锛岃缃涓嬶細

杩欎簺閫夐」鐪嬪瓧闈㈤兘姣旇緝濂界悊瑙o紝3D Stereo Spread鐨勬剰鎬濆叾瀹炲氨鏄乏鍙宠€抽棿璺濄€?/p>

 

鏈€鍚庡埆蹇樹簡璁剧疆character钃濆浘鐨剆b_walks鏁扮粍鐨勫€硷紝浠ュ強宸﹀彸鑴氱殑socketname

 

 

澶у姛鍛婃垚鍟︼紒

鍏蜂綋鏁堟灉銆傘€傘€傚弽姝d綘浠篃鍚笉鍒般€傘€傘€?/p>

 

------------------------------------------------

涓嬫湡棰勫憡锛氱編濡欑殑IK锛堝弽鍚戝姩鍔涘锛?/p>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值