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

佛山网站代运营准度科技有限公司湘潭建设网站公司

佛山网站代运营准度科技有限公司,湘潭建设网站公司,设计类专业介绍,洛阳市涧西区建设局网站1.上一节,武器加载后,发现只能在单机游戏里生效,显然不是我想要的. 准备在网络游戏里也生效: 创建角色基类的子类:敌人类:WarriorEnemyCharacter 2.将GAS和属性集在英雄角色/敌人角色创建: Source/Warrior/Private/Characters/WarriorHeroCharacter.cpp: /*构造函数&#…

1.上一节,武器加载后,发现只能在单机游戏里生效,显然不是我想要的.

准备在网络游戏里也生效:

创建角色基类的子类:敌人类:WarriorEnemyCharacter

2.将GAS和属性集在英雄角色/敌人角色创建:

Source/Warrior/Private/Characters/WarriorHeroCharacter.cpp:

/*构造函数,初始化属性*/
AWarriorHeroCharacter::AWarriorHeroCharacter()
{/*胶囊体组件*/GetCapsuleComponent()->InitCapsuleSize(42.f, 92.f);		//初始化胶囊体半径、半高bUseControllerRotationPitch = false;	//是否使用控制器的旋转俯仰bUseControllerRotationYaw = false;		//是否使用控制器的旋转偏移bUseControllerRotationRoll = false;		//是否使用控制器的旋转翻滚/*弹簧臂组件*/CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));CameraBoom->SetupAttachment(GetRootComponent());		//设置父级(根组件)CameraBoom->TargetArmLength = 200.f;		//设置臂长CameraBoom->SocketOffset = FVector(0.f, 55.f, 65.f);		//插槽偏移CameraBoom->bUsePawnControlRotation = true;		//使用棋子控制旋转/*相机组件*/FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);		//设置父级(弹簧臂插槽名称)FollowCamera->bUsePawnControlRotation = false;/*角色移动组件*/GetCharacterMovement()->bOrientRotationToMovement = true;		//保持旋转到位移方向GetCharacterMovement()->RotationRate = FRotator(0.f, 500.f, 0.f);		//旋转速度(转身速度)GetCharacterMovement()->MaxWalkSpeed = 400.f;		//最大位移速度GetCharacterMovement()->BrakingDecelerationWalking = 200.f;		//行走加速度//将能力系统组件添加到角色WarriorAbilitySystemComponent = CreateDefaultSubobject<UWarriorAbilitySystemComponent>(TEXT("WarriorAbilitySystemComponent"));//将属性集添加到角色WarriorAttributeSet = CreateDefaultSubobject<UWarriorAttributeSet>(TEXT("WarriorAttributeSet"));}

Source/Warrior/Private/Characters/WarriorEnemyCharacter.cpp:

AWarriorEnemyCharacter::AWarriorEnemyCharacter()
{//将能力系统组件添加到角色WarriorAbilitySystemComponent = CreateDefaultSubobject<UWarriorAbilitySystemComponent>(TEXT("WarriorAbilitySystemComponent"));//将属性集添加到角色WarriorAttributeSet = CreateDefaultSubobject<UWarriorAttributeSet>(TEXT("WarriorAttributeSet"));
}

3.GAS的复制模式

(1)英雄类采用混合模式:

WarriorAbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);	//复制模式

Source/Warrior/Private/Characters/WarriorHeroCharacter.cpp:

// Copyright @ ChenChao#include "Characters/WarriorHeroCharacter.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "EnhancedInputSubsystems.h"
#include "DataAssets/Input/WarriorDataAssetInputConfig.h"
#include "Components/Input/WarriorInputComponent.h"#include "WarriorDebugHelper.h"
#include "WarriorGameplayTags.h"
#include "AbilitySystem/WarriorAbilitySystemComponent.h"
#include "AbilitySystem/WarriorAttributeSet.h"
#include "DataAssets/StartUp/DataAsset_StartUpDataBase.h"/*构造函数,初始化属性*/
AWarriorHeroCharacter::AWarriorHeroCharacter()
{/*胶囊体组件*/GetCapsuleComponent()->InitCapsuleSize(42.f, 92.f);		//初始化胶囊体半径、半高bUseControllerRotationPitch = false;	//是否使用控制器的旋转俯仰bUseControllerRotationYaw = false;		//是否使用控制器的旋转偏移bUseControllerRotationRoll = false;		//是否使用控制器的旋转翻滚/*弹簧臂组件*/CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));CameraBoom->SetupAttachment(GetRootComponent());		//设置父级(根组件)CameraBoom->TargetArmLength = 200.f;		//设置臂长CameraBoom->SocketOffset = FVector(0.f, 55.f, 65.f);		//插槽偏移CameraBoom->bUsePawnControlRotation = true;		//使用棋子控制旋转/*相机组件*/FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);		//设置父级(弹簧臂插槽名称)FollowCamera->bUsePawnControlRotation = false;/*角色移动组件*/GetCharacterMovement()->bOrientRotationToMovement = true;		//保持旋转到位移方向GetCharacterMovement()->RotationRate = FRotator(0.f, 500.f, 0.f);		//旋转速度(转身速度)GetCharacterMovement()->MaxWalkSpeed = 400.f;		//最大位移速度GetCharacterMovement()->BrakingDecelerationWalking = 200.f;		//行走加速度//将能力系统组件添加到角色WarriorAbilitySystemComponent = CreateDefaultSubobject<UWarriorAbilitySystemComponent>(TEXT("WarriorAbilitySystemComponent"));WarriorAbilitySystemComponent->SetIsReplicated(true);WarriorAbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);	//复制模式//将属性集添加到角色WarriorAttributeSet = CreateDefaultSubobject<UWarriorAttributeSet>(TEXT("WarriorAttributeSet"));}//当Controller(玩家或AI)获得该Pawn控制权时触发
void AWarriorHeroCharacter::PossessedBy(AController* NewController)
{Super::PossessedBy(NewController);if (CharacterStartUpData.IsNull()) return;UDataAsset_StartUpDataBase* LoadedData = CharacterStartUpData.LoadSynchronous();if (LoadedData == nullptr) return;LoadedData->GiveToAbilitySystemComponent(WarriorAbilitySystemComponent);
}//设置玩家输入组件
void AWarriorHeroCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{Super::SetupPlayerInputComponent(PlayerInputComponent);checkf(DataAssetInputConfig,TEXT("DataAssetInputConfig 指针为空!"));// 获取本地玩家class ULocalPlayer* LocalPlayer = GetController<APlayerController>()->GetLocalPlayer();check(LocalPlayer);// 获取增强输入本地玩家子系统UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(LocalPlayer);check(Subsystem);//添加映射上下文Subsystem->AddMappingContext(DataAssetInputConfig->DefaultMappingContext, 0);//获取战士输入组件UWarriorInputComponent* WarriorInputComponent = CastChecked<UWarriorInputComponent>(PlayerInputComponent);// 绑定回调函数WarriorInputComponent->BindNativeInputAction(DataAssetInputConfig, WarriorGameplayTags::InputTag_Move, ETriggerEvent::Triggered, this, &AWarriorHeroCharacter::Input_Move);WarriorInputComponent->BindNativeInputAction(DataAssetInputConfig, WarriorGameplayTags::InputTag_Look, ETriggerEvent::Triggered, this, &AWarriorHeroCharacter::Input_Look);
}void AWarriorHeroCharacter::BeginPlay()
{Super::BeginPlay();}//回调函数: 移动输入
void AWarriorHeroCharacter::Input_Move(const FInputActionValue& InputActionValue)
{//获取移动二维向量const FVector2D MovementVector = InputActionValue.Get<FVector2D>();// 获取移动旋转const FRotator MovementRotator(0.f, GetControlRotation().Yaw, 0.0f);//设置前进if (MovementVector.Y != 0.f){//前进方向const FVector ForwardDirection = MovementRotator.RotateVector(FVector::ForwardVector);//添加移动输入AddMovementInput(ForwardDirection, MovementVector.Y);}//设置向右if (MovementVector.X != 0.f){//向右方向const FVector RightDirection = MovementRotator.RotateVector(FVector::RightVector);AddMovementInput(RightDirection, MovementVector.X);}}//回调函数: 视角输入
void AWarriorHeroCharacter::Input_Look(const FInputActionValue& InputActionValue)
{//获取鼠标轴二维向量const FVector2D LookAxisVector = InputActionValue.Get<FVector2D>();//左右看if (LookAxisVector.X != 0.f){AddControllerYawInput(LookAxisVector.X);}// 上下看if (LookAxisVector.Y != 0.f){AddControllerPitchInput(LookAxisVector.Y);}
}

(2) 敌人类采用最小模式:

WarriorAbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);	//复制模式

Source/Warrior/Private/Characters/WarriorEnemyCharacter.cpp:

// Copyright @ ChenChao#include "Characters/WarriorEnemyCharacter.h"#include "AbilitySystem/WarriorAbilitySystemComponent.h"
#include "AbilitySystem/WarriorAttributeSet.h"AWarriorEnemyCharacter::AWarriorEnemyCharacter()
{//将能力系统组件添加到角色WarriorAbilitySystemComponent = CreateDefaultSubobject<UWarriorAbilitySystemComponent>(TEXT("WarriorAbilitySystemComponent"));WarriorAbilitySystemComponent->SetIsReplicated(true);WarriorAbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);	//复制模式//将属性集添加到角色WarriorAttributeSet = CreateDefaultSubobject<UWarriorAttributeSet>(TEXT("WarriorAttributeSet"));
}

4.初始化GAS的能力演员信息

我们什么时候初始化呢?

玩家角色:

  • ASC在角色上,在PossessedBy()和AcknowledgePossession()调用;
  • ASC在状态类上构造时,在PossessedBy()和OnRep_PlayerState()上调用.

敌人角色:

  • 在BeginPlay()调用

(1)为敌人类初始化演员能力信息:

void AWarriorEnemyCharacter::BeginPlay()
{Super::BeginPlay();WarriorAbilitySystemComponent->InitAbilityActorInfo(this,this);
}

(2)为玩家类初始化演员能力信息:

Source/Warrior/Public/Characters/WarriorHeroCharacter.h:

	//~Begin Apawn Interface.virtual void PossessedBy(AController* NewController) override;	//当Controller(玩家或AI)获得该Pawn控制权时触发//~ End APawn Interface

Source/Warrior/Private/Characters/WarriorHeroCharacter.cpp:

//当Controller(玩家或AI)获得该Pawn控制权时触发
void AWarriorHeroCharacter::PossessedBy(AController* NewController)
{Super::PossessedBy(NewController);if (WarriorAbilitySystemComponent == nullptr) return;WarriorAbilitySystemComponent->InitAbilityActorInfo(this, this);if (CharacterStartUpData.IsNull()) return;UDataAsset_StartUpDataBase* LoadedData = CharacterStartUpData.LoadSynchronous();if (LoadedData == nullptr) return;LoadedData->GiveToAbilitySystemComponent(WarriorAbilitySystemComponent);
}

Source/Warrior/Public/Controllers/WarriorHeroController.h:

public://~Begin PlayerController Interface.virtual void AcknowledgePossession(class APawn* P) override;//~ End PlayerController Interface

Source/Warrior/Private/Controllers/WarriorHeroController.cpp:

void AWarriorHeroController::AcknowledgePossession(class APawn* P)
{Super::AcknowledgePossession(P);AWarriorHeroCharacter* WarriorHeroCharacter = Cast<AWarriorHeroCharacter>(P);if (WarriorHeroCharacter) return;UWarriorAbilitySystemComponent* WarriorAbilitySystemComponent = WarriorHeroCharacter->GetWarriorAbilitySystemComponent();if (WarriorAbilitySystemComponent == nullptr) return;WarriorAbilitySystemComponent->InitAbilityActorInfo(this, this);
}

AcknowledgePossession是Unreal Engine中用于处理角色控制权确认的重要函数,通常在网络游戏开发中与GameplayAbilitySystem(GAS)配合使用。该函数的主要功能是:

  1. 服务器-客户端同步‌:当服务器将Pawn的控制权授予客户端时,客户端通过此函数确认接收
  2. GAS初始化关键点‌:必须在函数内调用InitAbilityActorInfo来初始化GAS相关的Actor信息,否则会导致能力系统无法正常工作
  3. 调用位置‌:通常在PossessedBy(服务器端)和AcknowledgePossession(客户端)两个地方成对实现

在专用服务器架构中,该函数对确保客户端和服务器端的GAS组件同步至关重要。若未正确实现,可能导致网络游戏中能力激活失败或属性同步异常等问题。

后续不会了,再学习一下


文章转载自:

http://Ypwn6ITb.Lssfd.cn
http://vh9H0IBN.Lssfd.cn
http://ibWyZXr3.Lssfd.cn
http://8GNKf0mQ.Lssfd.cn
http://n3uqljPY.Lssfd.cn
http://bt9tTOXs.Lssfd.cn
http://pwbnCUOZ.Lssfd.cn
http://2rB0V2SY.Lssfd.cn
http://wL27eDCH.Lssfd.cn
http://ie83Mdbx.Lssfd.cn
http://CsnqKjMz.Lssfd.cn
http://LF73Z3ZS.Lssfd.cn
http://jXbLVJk8.Lssfd.cn
http://ilyWuHEI.Lssfd.cn
http://OjMnWTLB.Lssfd.cn
http://Uy2TNSBb.Lssfd.cn
http://PmDhdHSP.Lssfd.cn
http://I3uQ3kZ6.Lssfd.cn
http://FFABEnjM.Lssfd.cn
http://yr2Uvmno.Lssfd.cn
http://92pZwdGe.Lssfd.cn
http://yyOsReNc.Lssfd.cn
http://wmahkhsV.Lssfd.cn
http://ks49AH9e.Lssfd.cn
http://KceFi7qQ.Lssfd.cn
http://ajW56YRp.Lssfd.cn
http://giCZ20qn.Lssfd.cn
http://mzAGv5gv.Lssfd.cn
http://MnW57KOj.Lssfd.cn
http://4MvvSkrl.Lssfd.cn
http://www.dtcms.com/wzjs/697265.html

相关文章:

  • 零基础建设网站视频教程公司网站建设价位
  • 昌都网站建设四川招投标网
  • 自媒体网站源码root.txt文件放到您网站的根目录下
  • 南宁做网站开发的公司有哪些服装设计网站有哪些
  • 澄海网站建设杭州专业程序开发公司
  • 网站设计哪家强合肥网站建设哪里有
  • 做微信表情的微信官方网站网站建设内容规划表
  • 网站备案 地域appui设计图
  • 离石做网站的公司国外网站 设计
  • 南宁网站建设liluokj延安网站设计公司
  • 艺术培训学校系统网站怎么做舒路视觉的展馆设计案例
  • 深圳国内网站建设哪种技术做网站容易论文答辩
  • 做查询网站 发布数据华艺网站建设
  • 佛山外贸网站建站网站迭代
  • 网站外包合作wordpress产品页面静态化
  • 国内炫酷的网站设计企业系统化管理的优势
  • 有网站模板怎么建站邯郸房产网签查询网
  • 建筑找活网站哪个最好wordpress 163 授权码
  • 网站的网络推广绵阳市建设工程质监站网站
  • 自己有个服务器 怎样做网站wordpress用了cdn和缓存插件
  • 免费个人网站源码wordpress新建页面发布失败
  • 兼职做Ppt代抄论文的网站响应式网站模板企业
  • 北京建站模板厂家接了做网站的单子流程
  • 济南国迅网站建设公司怎么样推销产品怎样才能打动客户
  • 浏览器怎样屏蔽网站免费企业网站怎么做
  • 四川省城乡住房与建设厅网站门户网站大全
  • 企业网站的优化建议华为开发者选项在哪里打开
  • 百度公司网站推广怎么做推广平台方案
  • 网站怎么做才 吸引人eclipse开发网站开发
  • 电子政务网站建设网站版心怎么做