UE GameplayTags

UnrealGAS——GameplayTag(玩法标签)

Gameplay标记

UE5 GameplayTag流量优化机制分析

c++

xxx.Build.cs

 "GameplayTags"
.h


protected:

	/// <summary>
	/// 所有用户权限
	/// </summary>
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Vince|Permission")
	TMap <FString, FGameplayTagContainer>UserPrivileges;

private:

	/// <summary>
	///  当前用户
	/// </summary>
	FString CurrentUser = TEXT("");



public:


	UFUNCTION(BlueprintCallable, Category = "Vince|Permission")
	/// <summary>
	///  设置当前用户
	/// </summary>
	/// <param name="UserName">用户名</param>
	void SetCurrentUser(FString UserName);

	UFUNCTION(BlueprintPure, Category = "Vince|Permission")
	/// <summary>
	///  获取当前用户
	/// </summary>
	FString GetUserName();

	UFUNCTION(BlueprintPure, Category = "Vince|Permission")
	/// <summary>
	///  获取所有用户
	/// </summary>
	TArray<FString> GetAllUserName();

	UFUNCTION(BlueprintCallable, Category = "Vince|Permission")
	/// <summary>
	/// 获取用户权限
	/// </summary>
	/// <param name="UserPrivilege">权限标签</param>
	/// <param name="UserName">用户名</param>
	/// <param name="bCurrentUser">是否查询的是当前用户</param>
	void GetUserPrivilege(FGameplayTagContainer& UserPrivilege, FString UserName, bool bCurrentUser = true);

	UFUNCTION(BlueprintCallable, Category = "Vince|Permission")
	/// <summary>
	/// 检查用户权限
	/// </summary>
	/// <param name="UserPrivilege">权限标签</param>
	/// <param name="UserName">用户名</param>
	/// <param name="bCurrentUser">是否查询的是当前用户</param>
	/// <returns></returns>
	bool CheckUserPrivilege(FGameplayTag UserPrivilege, FString UserName, bool bCurrentUser = true);

	UFUNCTION(BlueprintCallable, Category = "Vince|Permission")
	/// <summary>
	/// 添加用户权限单一标签
	/// </summary>
	/// <param name="UserPrivilege">权限标签</param>
	/// <param name="UserName">用户名</param>
	/// <param name="bCurrentUser">是否查询的是当前用户</param>
	/// <returns></returns>
	bool AddOnlyUserPrivilege(FGameplayTag UserPrivilege, FString UserName, bool bCurrentUser = true);


	UFUNCTION(BlueprintCallable, Category = "Vince|Permission")
	/// <summary>
	/// 移除用户权限单一标签
	/// </summary>
	/// <param name="UserPrivilege">权限标签</param>
	/// <param name="UserName">用户名</param>
	/// <param name="bCurrentUser">是否查询的是当前用户</param>
	/// <returns></returns>
	bool RemoveOnlyUserPrivilege(FGameplayTag UserPrivilege, FString UserName, bool bCurrentUser = true);





.cpp


void UPieceTogetherTools_GameInstance::SetCurrentUser(FString UserName)
{
	if (!UserName.IsEmpty())
	{
		CurrentUser = UserName;
	}
}

FString UPieceTogetherTools_GameInstance::GetUserName()
{
	return CurrentUser;
}



TArray<FString> UPieceTogetherTools_GameInstance::GetAllUserName()
{
	TArray<FString>  nowTArrayKeys;
	UserPrivileges.GenerateKeyArray(nowTArrayKeys);
	return	nowTArrayKeys;
}


void UPieceTogetherTools_GameInstance::GetUserPrivilege(FGameplayTagContainer& UserPrivilege, FString UserName, bool bCurrentUser /*= true*/)
{

	if (bCurrentUser)
	{
		if (!CurrentUser.IsEmpty())
		{
			UserPrivilege = *(UserPrivileges.Find(CurrentUser));
		}
	}

	else
	{

		if (!UserName.IsEmpty())
		{
			UserPrivilege = *(UserPrivileges.Find(UserName));
		}
	}

}

bool UPieceTogetherTools_GameInstance::CheckUserPrivilege(FGameplayTag UserPrivilege, FString UserName, bool bCurrentUser /*= true*/)
{

	if (bCurrentUser)
	{
		if (!CurrentUser.IsEmpty())
		{
			FGameplayTagContainer& nowTagContainer = *(UserPrivileges.Find(CurrentUser));
			return nowTagContainer.HasTag(UserPrivilege);


		}
	}

	else
	{

		if (!UserName.IsEmpty())
		{
			FGameplayTagContainer& nowTagContainer = *(UserPrivileges.Find(UserName));

			return nowTagContainer.HasTag(UserPrivilege);
		}
	}


	return false;
}

bool UPieceTogetherTools_GameInstance::AddOnlyUserPrivilege(FGameplayTag UserPrivilege, FString UserName, bool bCurrentUser)
{

	if (bCurrentUser)
	{
		if (!CurrentUser.IsEmpty())
		{
			FGameplayTagContainer& nowTagContainer = UserPrivileges.FindOrAdd(CurrentUser);

			nowTagContainer.AddTag(UserPrivilege);

			return true;

		}
	}

	else
	{

		if (!UserName.IsEmpty())
		{
			FGameplayTagContainer& nowTagContainer = UserPrivileges.FindOrAdd(UserName);

			nowTagContainer.AddTag(UserPrivilege);

			return true;

		}
	}


	return false;
}



bool UPieceTogetherTools_GameInstance::RemoveOnlyUserPrivilege(FGameplayTag UserPrivilege, FString UserName, bool bCurrentUser /*= true*/)
{
	if (bCurrentUser)
	{
		if (!CurrentUser.IsEmpty())
		{
			FGameplayTagContainer& nowTagContainer = UserPrivileges.FindOrAdd(CurrentUser);

			nowTagContainer.RemoveTag(UserPrivilege);

			return true;

		}
	}

	else
	{

		if (!UserName.IsEmpty())
		{
			FGameplayTagContainer& nowTagContainer = UserPrivileges.FindOrAdd(UserName);

			nowTagContainer.RemoveTag(UserPrivilege);

			return true;

		}
	}


	return false;
}

INI

[/Script/GameplayTags.RestrictedGameplayTagsList]
RestrictedGameplayTagList=(bAllowNonRestrictedChildren=False,Tag="Feature.A",DevComment="功能A")
RestrictedGameplayTagList=(bAllowNonRestrictedChildren=False,Tag="Feature.B",DevComment="功能B")
RestrictedGameplayTagList=(bAllowNonRestrictedChildren=False,Tag="Login",DevComment="")
RestrictedGameplayTagList=(bAllowNonRestrictedChildren=False,Tag="Feature.C",DevComment="功能C")

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值