Unity 3D游戏补丁工具?
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的东西,我有http下载一个文本文件,其中有最新版本,如果他们的版本低于这个,他们可以选择下载安装程序,
如果你在Windows上使用它,然后你可以运行unity一个外部进程(一个简单的 C# 表单,用于更新文件,或者下载安装程序等待其完成然后执行它)[也可能在 Unity 中实现,但这对我来说效果很好]
(您也可以只指出该进程在网络浏览器中,链接到最新版本,这样浏览器或他们的默认文件下载器将负责下载程序并处理通信错误)这样他们就会知道他们需要在完成后打开已安装的应用程序
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