应用管理系统(NApplication)
在开发过程中,有时候我们需要获取或操作当前应用程序的信息,比如应用程序版本、运行环境、是否在前台运行等。对此提供了应用管理系统,可以帮助我们获取这些信息。
接口介绍:
| 接口名称 | 返回值 | 接口作用 |
|---|---|---|
| ToAbsoluteAssetsPath | std::string | 资源绝对路径 |
| DataPath | std::string | 项目绝对距离 |
| EngineAssetsPath | std::string | 获取引擎资源路径 |
| AssetsPath | std::string | 资源相对路径 |
| GetAssetsFilePath | std::string | 获取文件相对资源路径 |
| UserDataPath | std::string | 获取用户数据路径 |
| GetUserDataFilePath | std::string | 获取文件相对用户路径 |
| IsMobilePlatform | bool | 是否为移动平台 |
| IsXR | bool | 是否为XR平台 |
| IsWindowsPlatform | bool | 是否为Windows平台 |
| Quit | void | 退出应用 |
| RegisterApplicationResume | void | 注册应用恢复函数 |
| RegisterApplicationPause | void | 注册应用暂停函数 |
| UnRegisterApplicationResume | void | 解除应用恢复函数 |
| UnRegisterApplicationPause | void | 解除应用暂停函数 |
| GetScreenSize | Vector2f | 获取屏幕尺寸 |
| GetScreenTransitionComponent | NScreenTransitionComponentPtr | 获取转场组件 |
| GetDeviceCapabilities | GfxDeviceCapabilities | 获取当前设备功能 |
| SetDebugSettings | void | 设置调试设定 |
| GetAndroidActivity | void* | 获取安卓Activity |
| GetFPS | float | 获取应用帧数 |
| SetEnableSceneCulling | void | 设置视锥剔除 |
| GetEnableSceneCulling | bool | 获取视锥剔除开启 |
| GetProjectMultiSamples | uint32 | 设置项目剔除模式 |
| GetStartCommandList | std::vectorstd::string | 获取启动行命令 |
| GetRunningMode | ERunningMode | 获取运行模式 |
| SetStartNRR | void | 设置开启NRR |
| IsSupportNRR | bool | 设备是否支持NRR |
| SetOverlayIndependentRT | void | 设置Overlay采用独立RT渲染 |
| SetEnableEngineReuse | void | 设置引擎实例重用 |
| GetApplicationMemoryUse | float | 获取应用内存使用 |
| SetTargetFPS | void | 设置目标帧数 |
| GetAppBlendMode | EAppBlendMode | 获取混合模式 |
| SetAppBlendMode | bool | 设置混合模式 |
| SetBackgroundProcessInput | void | 设置暂停时输入时间处理 |
| SendAppMessage | void | 发送App信息 |
| RegisterAppMessageCallback | int | 注册接受信息回调 |
| UnregisterAppMessageCallback | bool | 解除接受信息回调 |
接口示例: 判断不同平台设置应用限制帧数:
cpp
void NewScript1::Start()
{
if (NApplication::IsXR()||NApplication::IsWindowsPlatform())
{
NApplication::SetTargetFPS(120);
}
else if (NApplication::IsMobilePlatform())
{
NApplication::SetTargetFPS(60);
}
// Triggered before the first execution of Update
}获取当前资源文件的绝对路径并读取数据加载为纹理:
cpp
void NewScript1::Start()
{
auto pngpath = NApplication::ToAbsoluteAssetsPath("Assets/Image.png");
NFile a;
uint8_t * pBuffer = new uint8_t[141907];
auto adfas = a.Open(pngpath, OpenMode::OM_RB);
int asv = a.ReadBuffer(pBuffer, 1, 141907);
auto imageViewPtr = NActorManager::CreateImageView("imagview");
auto ImageComp = imageViewPtr->GetImageView();
auto Texture = NResources::LoadTextureFromData("TestImage", pBuffer,0,141907, ETextureSuffix::ETextureSuffix_PNG);
ImageComp->SetTexture(Texture);
// Triggered before the first execution of Update
}根据案件控制退出程序:
cpp
void NewScript1::Update()
{
if (NInput::GetKeyDown(KeyboardKeys::Escape) || NInput::GetKeyDown(KeyboardKeys::Android_Back))
{
//按下电脑ESC或者安卓返回按钮后,应用退出
NApplication::Quit();
}
// Called every frame if actor is enabled.
}
