Skip to content

应用管理系统(NApplication)

在开发过程中,有时候我们需要获取或操作当前应用程序的信息,比如应用程序版本、运行环境、是否在前台运行等。对此提供了应用管理系统,可以帮助我们获取这些信息。

接口介绍:

接口名称返回值接口作用
ToAbsoluteAssetsPathstd::string资源绝对路径
DataPathstd::string项目绝对距离
EngineAssetsPathstd::string获取引擎资源路径
AssetsPathstd::string资源相对路径
GetAssetsFilePathstd::string获取文件相对资源路径
UserDataPathstd::string获取用户数据路径
GetUserDataFilePathstd::string获取文件相对用户路径
IsMobilePlatformbool是否为移动平台
IsXRbool是否为XR平台
IsWindowsPlatformbool是否为Windows平台
Quitvoid退出应用
RegisterApplicationResumevoid注册应用恢复函数
RegisterApplicationPausevoid注册应用暂停函数
UnRegisterApplicationResumevoid解除应用恢复函数
UnRegisterApplicationPausevoid解除应用暂停函数
GetScreenSizeVector2f获取屏幕尺寸
GetScreenTransitionComponentNScreenTransitionComponentPtr获取转场组件
GetDeviceCapabilitiesGfxDeviceCapabilities获取当前设备功能
SetDebugSettingsvoid设置调试设定
GetAndroidActivityvoid*获取安卓Activity
GetFPSfloat获取应用帧数
SetEnableSceneCullingvoid设置视锥剔除
GetEnableSceneCullingbool获取视锥剔除开启
GetProjectMultiSamplesuint32设置项目剔除模式
GetStartCommandListstd::vectorstd::string获取启动行命令
GetRunningModeERunningMode获取运行模式
SetStartNRRvoid设置开启NRR
IsSupportNRRbool设备是否支持NRR
SetOverlayIndependentRTvoid设置Overlay采用独立RT渲染
SetEnableEngineReusevoid设置引擎实例重用
GetApplicationMemoryUsefloat获取应用内存使用
SetTargetFPSvoid设置目标帧数
GetAppBlendModeEAppBlendMode获取混合模式
SetAppBlendModebool设置混合模式
SetBackgroundProcessInputvoid设置暂停时输入时间处理
SendAppMessagevoid发送App信息
RegisterAppMessageCallbackint注册接受信息回调
UnregisterAppMessageCallbackbool解除接受信息回调

接口示例: 判断不同平台设置应用限制帧数:

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.
}