gpt4 book ai didi

c# - Unity 3D游戏补丁工具?

转载 作者:太空宇宙 更新时间:2023-11-03 11:33:57 25 4
gpt4 key购买 nike

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

}
}

最佳答案

我有类似的东西,我有 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();
}

关于c# - Unity 3D游戏补丁工具?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6873974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com