unity游戏上架GooglePlay问题
·
游戏需要上架googlePlay,但是apk大于100M,需要使用扩展文件。
http://blog.csdn.net/pdw_jsp/article/details/45150061
参考这篇贴。
只要导入插件 https://pan.baidu.com/s/1jILhKfO
修改其中example的代码:
using UnityEngine;
using System.Collections;
public class DownloadObbExample : MonoBehaviour
{
private string expPath;
private string logtxt;
private bool alreadyLogged = false;
private string nextScene = "Main1";
private bool downloadStarted;
//public Texture2D background;
//public GUISkin mySkin;
void log( string t )
{
logtxt += t + "\n";
print("MYLOG " + t);
}
void OnGUI()
{
//GUI.skin = mySkin;
//GUI.DrawTexture(new Rect(0,0,background.width,background.height),background);
if (!GooglePlayDownloader.RunningOnAndroid())
{
GUI.Label(new Rect(10, 10, Screen.width-10, 20), "Use GooglePlayDownloader only on Android device!");
return;
}
expPath = GooglePlayDownloader.GetExpansionFilePath();
if (expPath == null)
{
GUI.Label(new Rect(10, 10, Screen.width-10, 20), "External storage is not available!");
}
else
{
string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
string patchPath = GooglePlayDownloader.GetPatchOBBPath(expPath);
if( alreadyLogged == false )
{
alreadyLogged = true;
log( "expPath = " + expPath );
log( "Main = " + mainPath );
log( "Main = " + mainPath.Substring(expPath.Length));
if (mainPath != null)
StartCoroutine(loadLevel());
}
//GUI.Label(new Rect(10, 10, Screen.width-10, Screen.height-10), logtxt );
if (mainPath == null)
{
GUI.Label(new Rect(Screen.width-600, Screen.height-230, 430, 60), "The game needs to download 200MB of game content. It's recommanded to use WIFI connexion.");
if (GUI.Button(new Rect(Screen.width-500, Screen.height-170, 250, 60), "Start Download !"))
{
GooglePlayDownloader.FetchOBB();
StartCoroutine(loadLevel());
}
}
}
}
protected IEnumerator loadLevel()
{
string mainPath;
do
{
yield return new WaitForSeconds(0.5f);
mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
log("waiting mainPath "+mainPath);
}
while( mainPath == null);
if( downloadStarted == false )
{
downloadStarted = true;
string uri = "file://" + mainPath;
log("downloading " + uri);
WWW www = WWW.LoadFromCacheOrDownload(uri , 0);
// Wait for download to complete
yield return www;
if (www.error != null)
{
log ("wwww error " + www.error);
}
else
{
Application.LoadLevel(nextScene);
}
}
}
}
覆盖package中的代码就可以了。
导出的apk,obb在真机上使用的时候,需要先安装apk,然后再将对应obb文件改名为:
main.bundle version code.<包名>.obb
例:main.1.com.company.TestPack.obb
拷贝到Android设备的“/android/obb/com. Demo.ABC/”路径下
Mark:没考虑到sdk相互接入问题
更多推荐


所有评论(0)