UE求职Demo开发日志#8 强化前置条件完善,给物品加图标

1 强化前置条件完善

StrengthManager里实现一个Check前置的函数

bool CheckPreAllIsActive(int index),所有的前置都已经激活就返回true,否则返回false

之后在强化的时候加入条件检查:

1.所有前置技能全部激活

2.本身没有强化过

最后测试的时候修改下UI样式以便查看信息

2 实现过程

2.1 bool CheckPreAllIsActive和void SetCellIsActiveByIndex

声明:

cpp 复制代码
UFUNCTION(BlueprintCallable)
bool CheckPreAllIsActive(int index);

UFUNCTION(BlueprintCallable)
void SetCellIsActiveByIndex(int index,bool isActive);

实现:

bool CheckPreAllIsActive检查所有前置是否激活

SetCellIsActiveByIndex提供一个对外接口设置IsActive

cpp 复制代码
bool UStrengthenManager::CheckPreAllIsActive(int index)
{
	TArray<int> AllPreIndex=StrengthenTree_1[index].PreIndex;
	for(int i=0;i<AllPreIndex.Num();i++)
	{
		if(AllPreIndex[i]>=0&&AllPreIndex[i]<StrengthenTree_1.Num())
		{
			if(!StrengthenTree_1[AllPreIndex[i]].bIsActive)
			{
				return false;
			}
		}
	}
	return true;
}

void UStrengthenManager::SetCellIsActiveByIndex(int index,bool isActive)
{
	if(index>=0&&index<StrengthenTree_1.Num())
	{
		StrengthenTree_1[index].bIsActive=isActive;
	}
}

2.2 TryStrengthenByCellIndex的修改

修改条件判断,加入前置检查和自身是否激活检查

cpp 复制代码
if(temp.NeededItems[i].CurrentOwnedCnt>OwnedCnt||!StrengthenManager->CheckPreAllIsActive(index)||temp.bIsActive)
{
	bCanStrengthen=false;
}

强化具体逻辑修改:

cpp 复制代码
    StrengthenManager->SetCellIsActiveByIndex(index,true);
    StrengthenManager->Save();
    StrengthenByName(FString("BaseAttack"),10);
    for(int i=0;i<temp.NeededItems.Num();i++)
    {
		WarehouseManager->RemoveItemFromWarehouse(temp.NeededItems[i].ItemId,temp.NeededItems[i].CurrentOwnedCnt);
    }
	WarehouseManager->SaveData();
	UpdatePadInfo();
	SaveToSlot();
	return true;

2.3 UI样式的修改

加了一个根据是否激活更新外观的Update:

在开始的时候统一了按钮的样式:

3 最终效果测试

除了界面丑以外还是挺完美的()

4 补充:给物品加入图标

仓库管理类中加入了一个获取图标的函数

cpp 复制代码
UTexture2D* UWarehouseManager::GetTexture2DByItemId(int32 ItemId)
{
	UTexture2D* MyTexture=NewObject<UTexture2D>();
	if(ItemId==1)
	{
		MyTexture = LoadObject<UTexture2D>(nullptr, TEXT("/Game/ItemTexture/id_1.id_1")); 
	}
	return MyTexture;
}

UI中同步更新图标:

效果:

相关推荐
爱搞虚幻的阿恺12 天前
Niagara粒子系统-超炫酷的闪电特效(加餐 纸牌螺旋上升效果)
游戏·游戏引擎
_Li.12 天前
Simulink - 6DOF (Euler Angles)
人工智能·算法·机器学习·游戏引擎·cocos2d
weixin_4242946712 天前
Unity 调用Steamworks API 的 SteamUserStats.RequestCurrentStats()报错
unity·游戏引擎·steamwork
HoFunGames12 天前
Unity小地图,Easy Minimap System MT-GPS插件
unity·游戏引擎
wy32586436412 天前
Unity 新输入系统InputSystem(基本操作)
unity·c#·游戏引擎
星和月12 天前
Untiy使用说明
c#·游戏引擎
小菱形_12 天前
【Unity】TimeLine
unity·游戏引擎
weixin_4242946713 天前
Unity 使用Steamworks.NET
unity·游戏引擎
ellis197013 天前
Unity资源管理框架Addressables总结
unity·游戏引擎
郭逍遥13 天前
[Godot] 通过AABB包围盒和射线法检测碰撞
算法·游戏引擎·godot