2
我在Unity3D中編寫遊戲,我想知道是否有任何工具可用於檢查服務器的更新,如果是,請下載並安裝更新。 我一直在試圖寫我自己的,但是我被困在「下載和安裝」部分。Unity 3D遊戲修補工具?
這是我有:
//Unity3D Patching Tool v0.1
using UnityEngine;
using System.Collections;
public class Patcher : MonoBehaviour {
public const string VERSION = "1.0"; // The version of the program that is running
private string patchUrl = "http://yoursite.com/patchversion.html"; //a website with the current build number
//a template to find the current build for windows
private const string UPDATE_WINDOWS_URL_TEMPLATE = "http://yoursite.com/release/build[[[BUILD_NUMBER]]].exe";
//a template to find the current build for mac
private const string UPDATE_MAC_URL_TEMPLATE = "http://yoursite.com/release/build[[[BUILD_NUMBER]]].app";
IEnumerator Start() {
/*
* Check for patch
*/
WWW patchwww = new WWW(patchUrl); //create new web connection to the build number site
yield return patchwww; // wait for download to finish
if (patchwww.text == VERSION){ //check version
Debug.Log("Up To Date");
}
else {
Debug.Log("Download New Update");
WWW downloadwww = new WWW(DownloadUpdate(patchwww.text)); // generates link to current build and downloads
yield return downloadwww;
}
}
private string DownloadUpdate(string version){
string versionNumber = version.Replace(".", ""); //remove periods in version number
string buildToDownload = "";
/*
* Check Platform and Set URL
*/
switch (Application.platform){
case RuntimePlatform.WindowsEditor:
case RuntimePlatform.WindowsPlayer:
Debug.Log("Windows " + Application.platform);
buildToDownload = UPDATE_WINDOWS_URL_TEMPLATE.Replace("[[[BUILD_NUMBER]]]", versionNumber);
break;
case RuntimePlatform.OSXEditor:
case RuntimePlatform.OSXPlayer:
Debug.Log("Mac " + Application.platform);
buildToDownload = UPDATE_MAC_URL_TEMPLATE.Replace("[[[BUILD_NUMBER]]]", versionNumber);
break;
}
Debug.Log(buildToDownload);
return buildToDownload;
}
}