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中同步更新图标:

效果:

相关推荐
小李也疯狂1 天前
Unity 中的立方体贴图(Cubemaps)
unity·游戏引擎·贴图·cubemap
呆呆敲代码的小Y1 天前
【Unity工具篇】| 超实用工具LuBan,快速上手使用
游戏·unity·游戏引擎·unity插件·luban·免费游戏·游戏配置表
EQ-雪梨蛋花汤1 天前
【Unity优化】Unity多场景加载优化与资源释放完整指南:解决Additive加载卡顿、预热、卸载与内存释放问题
unity·游戏引擎
我的offer在哪里1 天前
用 Unity 从 0 做一个「可以玩的」游戏,需要哪些步骤和流程
游戏·unity·游戏引擎
泡泡茶壶ᐇ1 天前
Unity游戏开发入门指南:从零开始理解游戏引擎核心概念
unity·游戏引擎
Var_al1 天前
抖小Unity WebGL分包命令行工具实践指南
unity·游戏引擎·webgl
天人合一peng1 天前
unity 通过代码修改button及其名字字体的属性
unity·游戏引擎
GLDbalala2 天前
Unity基于自定义管线实现经典经验光照模型
unity·游戏引擎
心疼你的一切2 天前
Unity异步编程神器:Unitask库深度解析(功能+实战案例+API全指南)
深度学习·unity·c#·游戏引擎·unitask
呆呆敲代码的小Y2 天前
【Unity 实用工具篇】 | Book Page Curl 快速实现翻书效果
游戏·unity·游戏引擎·u3d·免费游戏·翻书插件