2011-07-29 14 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#フォーム、またはインストーラをダウンロードして完了するのを待つ)を実行することができます[おそらく一体の中でも可能ですが、これは私にとってはうまくいく」

(この方法で、ブラウザまたはデフォルトのファイルダウンローダがプログラムのダウンロードを担当し、通信エラーを処理するように、最新バージョンへのリンクを使用して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(); 
} 
関連する問題