Unity 3D游戏补丁工具

本文关键字:工具 游戏补丁 3D Unity | 更新日期: 2023-09-27 18:03:51

我正在用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;
}
}

Unity 3D游戏补丁工具

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

如果你在windows上使用这个,你可以让unity运行一个外部进程(一个简单的c#表单来更新你的文件,或者下载一个安装程序等待它完成然后执行它)[可能也可以在unity内,但这对我来说很有效]

(你也可以将进程指向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();
}