六一的部落格


关关难过关关过,前路漫漫亦灿灿。




重构


实现模板函数: 获取Pawn组件


添加头文件

预编译命令应为pragma once, 代码框中有遗漏错误

Public/STUUtil.h

 1#pragma
 2
 3#include "GameFramework/Pawn.h"
 4
 5class STUUtils
 6{
 7public:
 8    template<typename T>
 9    static T* GetSTUPlayerComponent(APawn *PlayerPawn)
10    {
11        if (!PlayerPawn) return nullptr;
12
13        const auto Component = PlayerPawn->GetComponentByClass(T::StaticClass());
14        return Cast<T>(Component);
15    }
16};

修改获取Pawn组件的地方

ShootThemUp: UI/STUPlayerHUDWidget.cpp

1#include "STUUtils.h"
2
3// GetHealthPercent, IsPlayerAlive
4const auto HealthComponent = STUUtils::GetSTUPlayerComponent<USTUHealthComponent>(GetOwningPlayerPawn());
5
6// GetCurrentWeaponUIData, GetCurrentWeaponAmmoData
7const auto WeaponComponent = STUUtils::GetSTUPlayerComponent<USTUWeaponComponent>(GetOwningPlayerPawn());

屏蔽GetWeaponComponent和GetHealthComponent

ShootThemUp: UI/STUPlayerHUDWidget.cpp

定义

ShootThemUp: UI/STUPlayerHUDWidget.h

屏蔽USTUWeaponComponent和USTUHealthComponent的前向声明

屏蔽GetWeaponComponent和GetHealthComponent


屏蔽弹药日志

ShootThemUp: Weapon/STUBaseWeapon.cpp

DecreaseAmmo


修改生命值百分比和武器信息颜色

WBP_PlayerHUD


进度条

移动到左下角; 修改颜色



文本框

修改颜色



武器图标

进入到 GetWeaponIcon

MakeSlateBrush , 展开Tint针脚; 修改颜色



修改元素名



打包


重构和打包



重构


实现模板函数: 获取Pawn组件


添加头文件

预编译命令应为pragma once, 代码框中有遗漏错误

Public/STUUtil.h

 1#pragma
 2
 3#include "GameFramework/Pawn.h"
 4
 5class STUUtils
 6{
 7public:
 8    template<typename T>
 9    static T* GetSTUPlayerComponent(APawn *PlayerPawn)
10    {
11        if (!PlayerPawn) return nullptr;
12
13        const auto Component = PlayerPawn->GetComponentByClass(T::StaticClass());
14        return Cast<T>(Component);
15    }
16};

修改获取Pawn组件的地方

ShootThemUp: UI/STUPlayerHUDWidget.cpp

1#include "STUUtils.h"
2
3// GetHealthPercent, IsPlayerAlive
4const auto HealthComponent = STUUtils::GetSTUPlayerComponent<USTUHealthComponent>(GetOwningPlayerPawn());
5
6// GetCurrentWeaponUIData, GetCurrentWeaponAmmoData
7const auto WeaponComponent = STUUtils::GetSTUPlayerComponent<USTUWeaponComponent>(GetOwningPlayerPawn());

屏蔽GetWeaponComponent和GetHealthComponent

ShootThemUp: UI/STUPlayerHUDWidget.cpp

定义

ShootThemUp: UI/STUPlayerHUDWidget.h

屏蔽USTUWeaponComponent和USTUHealthComponent的前向声明

屏蔽GetWeaponComponent和GetHealthComponent


屏蔽弹药日志

ShootThemUp: Weapon/STUBaseWeapon.cpp

DecreaseAmmo


修改生命值百分比和武器信息颜色

WBP_PlayerHUD


进度条

移动到左下角; 修改颜色



文本框

修改颜色



武器图标

进入到 GetWeaponIcon

MakeSlateBrush , 展开Tint针脚; 修改颜色



修改元素名



打包