Unity 3D游戏补丁工具?

发布于 2024-11-26 21:10:25 字数 2096 浏览 0 评论 0原文

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

}
}

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;

}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半岛未凉 2024-12-03 21:10:25

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

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

(您也可以只指出该进程在网络浏览器中,链接到最新版本,这样浏览器或他们的默认文件下载器将负责下载程序并处理通信错误)这样他们就会知道他们需要在完成后打开已安装的应用程序

import System.Diagnostics;

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

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文