解析SampleBrowser項目的SampleBrowser.h文件,我們可以發現其中有這麼一個函數:
/*-----------------------------------------------------------------------------
| Initialises only the browser's resources and those most commonly used
| by samples. This way, additional special content can be initialised by
| the samples that use them, so startup time is unaffected.
-----------------------------------------------------------------------------*/
virtual void loadResources()
{
#if OGRE_PLATFORM != OGRE_PLATFORM_NACL
mTrayMgr->showLoadingBar(1, 0);
#endif
Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Popular");
#if OGRE_PLATFORM != OGRE_PLATFORM_NACL
mTrayMgr->hideLoadingBar();
#endif
}
其主要是基於封裝了Overlay和Material的SdkTrayManager類對象mTrayMgr的調用,主要負責界面的顯示和更新。在這裏首先顯示了進度條界面,然後加載"Popular"資源組,最後再隱藏進度條界面。
那麼是如何做到資源讀取的同步更新的呢?
我們查看showLoadingBar()函數,可以看到這樣一句核心代碼:
Ogre::ResourceGroupManager::getSingleton().addResourceGroupListener(this);
很容易可以看出,它是通過ResourceGroupManager來監聽,從而實現同步更新的功能。
看到這裏,我們也可以利用Ogre自帶的mTrayMgr來自己動手實現一個資源讀取的界面了,
需要注意的是,要實現資源加載的界面,我們需要預先初始化SdkTrays.zip資源文件(默認
位於resources.cfg中Essential資源組),然後便可以成功調用showLodingBar()函數了。
下面附一張進度條界面實現的效果圖: