Unity 3D game patching tool?
I am writing a game in Unity3D and I was wondering if there are any tools available to check a server for an update, if so, download and install the update. I have been trying to write my own, however I am stuck on the "Download and Install" part.
This is what I have:
//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;
}
}
I have something similar, I have the http download a text file that has the latestversion within it, if their version is lower then this, they have the option to download an installer
if you are using this on windows, you could then have unity run a external process ( a simple c# form that updates your files, or that downloads a installer waits for it to complete then executes it) [probably possible within unity as well, but this works well for me]
(you could also just point the process at the web browser with the link to the latest version this way the browser or their default file downloader will be responsible for downloading the program and will handle communication errors) this way they would know that they need to open the installed app once it is complete
import System.Diagnostics;
var path:String = "somewhere";
var foo:Process = new Process();
function Start()
{
foo.StartInfo.FileName = "someprogram";
foo.StartInfo.Arguments = path;
foo.Start();
}
精彩评论