转自:http://aigo.iteye.com/blog/2275110
参考自Epic官方项目StrategyGame
血条效果:
StrategyHUD.h
StrategyHUD.cpp
分类:
Unreal Engine 4
随笔 - 991, 文章 - 0, 评论 - 27, 阅读 -
341万
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
导航
搜索随笔分类
随笔档案
最新评论
|
转自:http://aigo.iteye.com/blog/2275110 参考自Epic官方项目StrategyGame 血条效果: StrategyHUD.h /** * Draws health bar for specific actor. * * @param ForActor Actor for which the health bar is for. * @param HealthPct Current Health percentage. * @param BarHeight Height of the health bar * @param OffsetY Y Offset of the health bar. */ void DrawHealthBar(AActor* ForActor, float HealthPct, int32 BarHeight, int OffsetY = 0) const;
StrategyHUD.cpp void AStrategyHUD::DrawHealthBar(AActor* ForActor, float HealthPercentage, int32 BarHeight, int32 OffsetY) const { FBox BB = ForActor->GetComponentsBoundingBox(); FVector Center = BB.GetCenter(); FVector Extent = BB.GetExtent(); FVector2D Center2D = FVector2D(Canvas->Project(FVector(Center.X,Center.Y,Center.Z + Extent.Z))); float ActorExtent = 40; if (Cast<APawn>(ForActor) != NULL) { AStrategyChar* StrategyChar = Cast<AStrategyChar>(ForActor); if( ( StrategyChar != NULL ) && ( StrategyChar->GetCapsuleComponent() != NULL ) ) { ActorExtent = StrategyChar->GetCapsuleComponent()->GetScaledCapsuleRadius(); } } else if (Cast<AStrategyBuilding>(ForActor) != NULL) { Center2D = FVector2D(Canvas->Project(ForActor->GetActorLocation())); ActorExtent = 60; } FVector Pos1 = Canvas->Project(FVector(Center.X,Center.Y - ActorExtent*2, Center.Z + Extent.Z)); FVector Pos2 = Canvas->Project(FVector(Center.X,Center.Y + ActorExtent*2, Center.Z + Extent.Z)); float HealthBarLength = (Pos2-Pos1).Size2D(); AStrategyPlayerController* MyPC = GetPlayerController(); IStrategyTeamInterface* ActorTeam = Cast<IStrategyTeamInterface>(ForActor); UTexture2D* HealthBarTexture = EnemyTeamHPTexture; if (ActorTeam != NULL && MyPC != NULL && ActorTeam->GetTeamNum() == MyPC->GetTeamNum()) { HealthBarTexture = PlayerTeamHPTexture; } float X = Center2D.X - HealthBarLength/2; float Y = Center2D.Y + OffsetY; FCanvasTileItem TileItem( FVector2D( X, Y ), HealthBarTexture->Resource, FVector2D( HealthBarLength * HealthPercentage, BarHeight ), FLinearColor::White ); TileItem.BlendMode = SE_BLEND_Translucent; TileItem.UV1 = FVector2D(HealthPercentage, 1.0f); Canvas->DrawItem( TileItem ); //Fill the rest of health with gray gradient texture X = Center2D.X-HealthBarLength/2 + HealthBarLength * HealthPercentage; Y = Center2D.Y + OffsetY; TileItem.Position = FVector2D( X, Y ); TileItem.Texture = BarFillTexture->Resource; TileItem.UV1 = FVector2D(1.0f, 1.0f); TileItem.Size = FVector2D( HealthBarLength * (1.0f - HealthPercentage), BarHeight ); TileItem.SetColor(FLinearColor(0.5f, 0.5f, 0.5f, 0.5f)); Canvas->DrawItem( TileItem ); }
分类:
Unreal Engine 4
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Powered by:
|
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· [AI/GPT/综述] AI Agent的设计模式综述
2010-10-25 Web服务