2011-07-29 57 views
2

我在Unity3D中編寫遊戲,我想知道是否有任何工具可用於檢查服務器的更新,如果是,請下載並安裝更新。 我一直在試圖寫我自己的,但是我被困在「下載和安裝」部分。Unity 3D遊戲修補工具?

這是我有:

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

} 
} 

回答

2

我有類似的東西,我有HTTP下載了其中的latestversion一個文本文件,如果他們的版本過低那麼這一點,他們可以選擇下載一個安裝程序

如果你在windows上使用它,你可以運行一個外部進程(一個簡單的c#表單來更新你的文件,或者下載一個安裝程序等待它完成然後執行它)可能在統一之內,但這對我很好]

(你也可以通過瀏覽器或默認文件下載器負責下載程序並處理通信錯誤),這樣,他們就會知道他們需要在完成後打開已安裝的應用程序

import System.Diagnostics; 

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