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