Hi all.
Currently, for a small game with very special font, I choose to show them as Textures.
So to manage multi language, I create one asset bundle for each language.
To load an Asset bundle, I do this :
private IEnumerator SetLanguage(string currentLanguage)
{
if (currentDownload == null)
{
PlayerPrefs.SetString("Language", currentLanguage);
string downloadDataPath;
if (Application.isEditor)
{
downloadDataPath = Application.dataPath + "/StreamingAssets/";
}
else
{
downloadDataPath = Application.dataPath + "/Raw/";
}
if (Screen.width < 500)
{
currentDownload = new WWW ("file://" + downloadDataPath + currentLanguage + "Language.unity3d");
}
else
{
currentDownload = new WWW ("file://" + downloadDataPath + currentLanguage + "HDLanguage.unity3d");
}
isDownloading = true;
return;
}
else
{
if (oldAssetBundle != null)
{
oldAssetBundle.Unload(true);
}
AssetBundle currentAssetBundle = currentDownload.assetBundle;
buttons = currentAssetBundle.Load("buttons") as Texture2D;
menus = currentAssetBundle.Load("mainmenu") as Texture2D;
messages = currentAssetBundle.Load("hudmsg") as Texture2D;
help = currentAssetBundle.Load("help") as Texture2D;
touchScreenRenderer.material.SetTexture("_MainTex", buttons);
buttonPlayRenderer.material.SetTexture("_MainTex", menus);
buttonHelpRenderer.material.SetTexture("_MainTex", menus);
buttonOptionsRenderer.material.SetTexture("_MainTex", menus);
buttonCreditsRenderer.material.SetTexture("_MainTex", menus);
buttonMusicRenderer.material.SetTexture("_MainTex", menus);
buttonFXRenderer.material.SetTexture("_MainTex", menus);
buttonLanguagesRenderer.material.SetTexture("_MainTex", menus);
selectLanguageRenderer.material.SetTexture("_MainTex", messages);
Vector2 temp = selectLanguageRenderer.material.mainTextureOffset;
temp.y = 0.5f;
selectLanguageRenderer.material.mainTextureOffset = temp;
Renderer titleRenderer = title.GetComponentInChildren<Renderer>() as Renderer;
titleRenderer.material.SetTexture("_MainTex", menus);
helpText01.renderer.material.SetTexture("_MainTex", help);
helpText02.renderer.material.SetTexture("_MainTex", help);
oldAssetBundle = currentAssetBundle;
currentDownload.Dispose();
currentDownload = null;
isDownloading = false;
if (oldAssetBundle != null)
{
oldAssetBundle.Unload(false);
}
}
}
As you can see I think I correctly free all memory but if I change language many times, It always finish by a crash.
More the iphone is recent, most I need to change language, so it’s really a memory problem.
But I can’t see what i’ve done wrong.
Could you help me please?
PS/ when I do this on the editor, my computer lag a lot, all memory must be used but if I show memory usage in the editor, nothing wrong and there is no sign of a memory leak.