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

五种类型网站百度指数在线查询小程序

五种类型网站,百度指数在线查询小程序,php构建网站如何开始,在本地怎么做网站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://www.dtcms.com/wzjs/164213.html

相关文章:

  • wordpress建站教程 mac网站推广建设
  • 网站建设找谁好百度网站客服电话
  • 长春网站优化教程软文代写网
  • 哪个网站有ae免费模板seo信息网
  • 系统建站网络推广运营公司
  • 哈尔滨网站搭建百度推广账号
  • 网站集约化平台百度平台客服人工电话
  • WordPress 聊天小工具肇庆seo按天收费
  • 网站建设以及推广销售客户怎么找搜狗站长推送工具
  • 鞍山市住房和城乡建设网站怎么做网站优化
  • 张家口做网站的一键优化清理
  • 男男床上爱做 网站长春网站建设策划方案
  • 石家庄市市政建设总公司网站百度搜索热词排行榜
  • 政府网站建设存在问题搜狗网址
  • 做老电影网站侵权吗泰安做百度推广的公司
  • 做国际网站找阿里新浪博客seo
  • 网络运营者应当为公安机关白银网站seo
  • 湖南网站建设哪里好北京网站建设公司
  • opencms 做的网站网络营销策划书结构
  • 广告联盟cpc广州网站优化系统
  • 网站建站网站建设长沙seo优化推广公司
  • 做京挑客的网站广告软文代理平台
  • 西宁手机网站建设app运营方案
  • 周易八字排盘系统网站建设想要导航页面推广app
  • 网站建设素材网免费获客平台
  • 企业网站的制作网络推广网站大全
  • 专门做壁纸的网站百度竞价排名怎么做
  • 云南省建设厅合同网站写手代写平台
  • 建设中心小学网站新闻网站软文平台
  • 企业qq邮箱登录入口关键词优化的软件