当前位置: 首页 > news >正文

凡客诚品官网商城首页seo网页的基础知识

凡客诚品官网商城首页,seo网页的基础知识,新民网站建设价格咨询,网站推广的定义及方法TP_WeaponComponent.h 看看头文件 暴露了attach weapon和fire给蓝图 这两个函数意义一看名字吧,就是捡起来枪的时候执行,一个就是发射子弹的时候执行 #pragma once#include "CoreMinimal.h" #include "Components/SkeletalMeshComponen…

TP_WeaponComponent.h

看看头文件
暴露了attach weapon和fire给蓝图
这两个函数意义一看名字吧,就是捡起来枪的时候执行,一个就是发射子弹的时候执行

#pragma once#include "CoreMinimal.h"
#include "Components/SkeletalMeshComponent.h"
#include "TP_WeaponComponent.generated.h"class AFirstPersonCharacter;UCLASS(Blueprintable, BlueprintType, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class FIRSTPERSON_API UTP_WeaponComponent : public USkeletalMeshComponent
{GENERATED_BODY()public:/** Projectile class to spawn */UPROPERTY(EditDefaultsOnly, Category=Projectile)TSubclassOf<class AFirstPersonProjectile> ProjectileClass;/** Sound to play each time we fire */UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay)USoundBase* FireSound;/** AnimMontage to play each time we fire */UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)UAnimMontage* FireAnimation;/** Gun muzzle's offset from the characters location */UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay)FVector MuzzleOffset;/** MappingContext */UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))class UInputMappingContext* FireMappingContext;/** Fire Input Action */UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))class UInputAction* FireAction;/** Sets default values for this component's properties */UTP_WeaponComponent();/** Attaches the actor to a FirstPersonCharacter */UFUNCTION(BlueprintCallable, Category="Weapon")bool AttachWeapon(AFirstPersonCharacter* TargetCharacter);/** Make the weapon Fire a Projectile */UFUNCTION(BlueprintCallable, Category="Weapon")void Fire();protected:/** Ends gameplay for this component. */UFUNCTION()virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;private:/** The Character holding this weapon*/AFirstPersonCharacter* Character;
};

看看具体实现
这个是attach
传入character,然后获取到USkeletalMeshComponent,就是mesh1p这个
然后就attach上去,这个rule后面再细了解吧
然后character还要AddInstanceComponent(this)
这里注意attach和add是分开的
完事就可以注册mapping和bindaction了,最后endplay的时候remove掉

bool UTP_WeaponComponent::AttachWeapon(AFirstPersonCharacter* TargetCharacter)
{Character = TargetCharacter;// Check that the character is valid, and has no weapon component yetif (Character == nullptr || Character->GetInstanceComponents().FindItemByClass<UTP_WeaponComponent>()){return false;}// Attach the weapon to the First Person CharacterFAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true);AttachToComponent(Character->GetMesh1P(), AttachmentRules, FName(TEXT("GripPoint")));// add the weapon as an instance component to the characterCharacter->AddInstanceComponent(this);// Set up action bindingsif (APlayerController* PlayerController = Cast<APlayerController>(Character->GetController())){if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer())){// Set the priority of the mapping to 1, so that it overrides the Jump action with the Fire action when using touch inputSubsystem->AddMappingContext(FireMappingContext, 1);}if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerController->InputComponent)){// FireEnhancedInputComponent->BindAction(FireAction, ETriggerEvent::Triggered, this, &UTP_WeaponComponent::Fire);}}return true;
}

再看另外一个fire函数

void UTP_WeaponComponent::Fire()
{if (Character == nullptr || Character->GetController() == nullptr){return;}// Try and fire a projectileif (ProjectileClass != nullptr){UWorld* const World = GetWorld();if (World != nullptr){APlayerController* PlayerController = Cast<APlayerController>(Character->GetController());const FRotator SpawnRotation = PlayerController->PlayerCameraManager->GetCameraRotation();// MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle positionconst FVector SpawnLocation = GetOwner()->GetActorLocation() + SpawnRotation.RotateVector(MuzzleOffset);//Set Spawn Collision Handling OverrideFActorSpawnParameters ActorSpawnParams;ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;// Spawn the projectile at the muzzleWorld->SpawnActor<AFirstPersonProjectile>(ProjectileClass, SpawnLocation, SpawnRotation, ActorSpawnParams);}}// Try and play the sound if specifiedif (FireSound != nullptr){UGameplayStatics::PlaySoundAtLocation(this, FireSound, Character->GetActorLocation());}// Try and play a firing animation if specifiedif (FireAnimation != nullptr){// Get the animation object for the arms meshUAnimInstance* AnimInstance = Character->GetMesh1P()->GetAnimInstance();if (AnimInstance != nullptr){AnimInstance->Montage_Play(FireAnimation, 1.f);}}
}

如果有character,也有子弹类projectileclass
拿到world然后spawnActor了一个AFirstPersonProjectile,就是那个子弹,上一章说过这个对象,他创建完毕是具备一个初速度的,所以就实现发射了,然后执行音频播放和动画播放,动画应该是后坐力

这个attach的具体地方如下所示,所以顺道看看pickup
在这里插入图片描述
在这里插入图片描述
这个是property,且参数用的是这样的,所以逻辑在蓝图里实现,具体就是上面的图
看看cpp文件实现
在这里插入图片描述
就是给overlap也就是相交事件绑定一个broadcast(Character)可以触发onPickUp
然后就走蓝图里的流程了

总结

weapon实现attach,然后是pickup component的mesh使用gun,等character碰到gun了就触发onpick 调用attach
attach后,character就有一个枪拿在手里了
鼠标点击就能出发fire函数了就生成sphere飞出去

http://www.dt0577.cn/news/3337.html

相关文章:

  • 儿童网站欣赏百度快照的作用是什么
  • 北京网站建设石榴汇企业培训系统
  • 网站搭建备案吗营业推广是什么意思
  • 基本信息型营销网站有哪些公司seo是什么意思
  • 怎样找到正规代加工网站百度seo技术
  • 网盘 商业网站建设案例课程 下载品牌宣传推广策划方案
  • 桂林做手机网站seo简介
  • 域名和空间都有了怎么做网站商城推广软文范文
  • 柳江网站开发整站优化外包服务
  • 商城类app开发价格百度关键词优化工具
  • 江西建设信息网站外贸接单平台哪个最好
  • 成交型网站建设价格淘宝推广软件哪个好
  • 网站建设吸引客户的网站外链出售
  • 什么公司做网站百度热搜排名
  • h5网站的优势百度关键词排名软件
  • 可以做哪些网站有哪些深圳海外推广
  • 湖北建设注册中心网站首页seo推广排名重要吗
  • 服务器放n个网站电商网
  • 网站建设手机网站百度查询网
  • 怎样安装网站模板百度指数查询工具
  • 自己做的网站图片加载过慢91
  • designer怎么做网站免费推广引流平台
  • 如何建设一个小型网站网站安全检测工具
  • 沈阳网站网页网络优化大师手机版
  • 深圳做网站的爱情独白百度软件应用中心下载
  • 返利的网站怎么做长沙关键词自然排名
  • 安装网站到服务器东莞疫情最新消息通知
  • 网站引流怎么做全网搜索引擎优化
  • 网销都是在那些网站做推广抖音seo什么意思
  • 做班级玩网站做哪些方面海南百度推广公司