Unity 3D游戏补丁工具?

时间:2011-07-29 13:35:04

标签: c# unity3d

我正在Unity3D中编写游戏,我想知道是否有任何工具可用于检查服务器是否有更新,如果有,请下载并安装更新。 我一直在努力编写自己的,但是我仍然坚持“下载并安装”部分。

这就是我所拥有的:

//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;

}
}

1 个答案:

答案 0 :(得分:2)

我有类似的东西,我有http下载一个文本文件,其中包含latestversion,如果他们的版本低于此,他们可以选择下载安装程序

如果你在Windows上使用它,你可以让团结运行一个外部进程(一个简单的c#表单更新你的文件,或下载安装程序等待它完成然后执行它)[可能在团结中运行好吧,但这对我很有用]

(您也可以通过浏览器或其默认文件下载器负责下载程序并处理通信错误的方式在Web浏览器上指向具有最新版本链接的进程)这样他们就会知道一旦完成,他们需要打开已安装的应用程序

import System.Diagnostics;

var path:String = "somewhere";
var foo:Process = new Process();
function Start() 
{   
    foo.StartInfo.FileName = "someprogram";
    foo.StartInfo.Arguments = path;
    foo.Start();
}