Hello! I'm developing casual game for Android and about to release first version.
But I stuck in terrible situation.
Google demand for 64bit apk, so I build as IL2CPP.
I get assetbundle from web server and it contains some binary data.
For binary data, I convert it as TextAsset.
Below is that code.
private IEnumerator GetAssetBundle()
{
UnityWebRequest www = UnityWebRequest.Get(hNetworkManager.serverURL);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Application.Quit();
}
else
{
string assetBundleDirectory = Application.persistentDataPath + "/AssetBundle";
string serialDataPath = Application.persistentDataPath + "/SerialData";
if (!Directory.Exists(assetBundleDirectory))
Directory.CreateDirectory(assetBundleDirectory);
if (!Directory.Exists(serialDataPath))
Directory.CreateDirectory(serialDataPath);
TextAsset[] textAssets;
AssetBundle assetBundle;
hLevel.SerialData[] serialDatas;
MemoryStream memoryStream;
BinaryFormatter formatter;
var studio = Instantiate(m_thumbnailStudio);
byte[] data = new byte[www.downloadHandler.data.Length - head];
System.Array.Copy(www.downloadHandler.data, head, data, 0, data.Length);
File.WriteAllBytes(Path.Combine(assetBundleDirectory, "levels.unity3d"), data);
assetBundle = AssetBundle.LoadFromFile(Path.Combine(assetBundleDirectory, "levels.unity3d"));
if (assetBundle == null)
{
//Debug.Log("Failed to load AssetBundle!");
yield break;
}
textAssets = assetBundle.LoadAllAssets();
serialDatas = new hLevel.SerialData[textAssets.Length];
memoryStream = new MemoryStream();
formatter = new BinaryFormatter();
for (int i = 0; i < textAssets.Length; ++i)
{
memoryStream.Write(textAssets[i].bytes, 0, textAssets[i].bytes.Length);
memoryStream.Position = 0;
serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream);
memoryStream.SetLength(0);
}
memoryStream.Close();
var lastThemeColor = hColorManager.current.curColor;
for (int i = 0; i < serialDatas.Length; ++i)
studio.SaveThumbnail(serialDatas[i]);
hColorManager.current.SetTheme(lastThemeColor, true);
hSharedData.Initialize(serialDatas);
_loading.FirstLoading();
#endregion
}
}
Up there "serialDatas[i] = (hLevel.SerialData)formatter.Deserialize(memoryStream);" line occur exception like this.
![alt text][1]
and build setting.
![alt text][2]
I also test Mono version and it worked properly.
I have no idea to solve this. PLEASE SOMEBODY HELP ME!
[1]: /storage/temp/164943-a.png
[2]: /storage/temp/164944-cv.png
↧