Unity コンテンツをロードする HTML コード
Unity Webプレイヤーのロード画面

UnityObject2の働き

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

UnityObject2 はシンプルにUnityのコンテンツをHTMLに埋め込んだりインストルのプロセスをカスタマイズすることが出来るJavascriptです。 あなたのゲームやウェブサイトに適するインストールUIを作成することは,エンドユーザーにとって魅力的であり,楽しい経験をもたらすことでしょう。このUnity Web Player プラグインはWeb Playerインストールの開始と埋め込まれたUnityコンテンツの検出を行う関数を持っています。 HTMLファイルと一緒に UnityObject2.js ファイルをWebサーバー上にアップロードすることも可能ですが,Unityが提供しているhttp://webplayer.unity3d.com/download_webplayer–3.x/3.0/uo/UnityObject2.js または https対応の場合は https://ssl-webplayer.unity3d.com/download_webplayer–3.x/3.0/uo/UnityObject2.js から読み込ませるのが最善の方法です。そうすることで常に最新のUnityObject2を使用することができます。 Unityのサーバー上にある UnityObject2.js はトラフィックを節約するためにminifyされています。 ソースコードを見たい場合はWindowsであれば Data\Resources フォルダの中に,Mac OS Xであれば Contents/Resources フォルダの中にあります。 UnityObject2はデフォルトでインストールタイプの識別やコンバーション率などのデータをGoogleAnalyticsへ送信しています。UnityObject2 はjQueryに依存しています。

コンストラクタ

Webページ上に存在する各Unityコンテンツに対してunityObject2のインスタンスを生成する必要があります。

パラメータ:

  • configuration - このインスタンスは設定が含まれているオブジェクトです。 以下は利用できるメンバー:
    • width - Default: 100%, Width of Unity content. Can be specified in pixel values (e.g. 600, “450”) or in percentage values (e.g. “50%”, “100%”). Note that percentage values are relative to the parent element.
    • height - Default: 100%, Height of Unity content. Can be specified in pixel values (e.g. 600, “450”) or in percentage values (e.g. “50%”, “100%”). Note that percentage values are relative to the parent element.
    • fullInstall - Default: false, Installs the full Web Player if not available. Normally only a small part of the Web Player is installed and the remaining files are automatically downloaded later.
    • enableJava - Default: true, Enables Java based installation. Some platforms doesn’t support this feature.
    • enableClickOnce - Default: true, Enables ClickOnce based installation. Only works on Internet Explorer browsers.
    • enableUnityAnalytics - Default: true, Notifies Unity about Web Player installation. This doesn’t do anything if the Web Player is already installed.
    • enableGoogleAnalytics -Default: true, Notifies Unity about Web Player installation using Google Analytics. This doesn’t do anything if the Web Player is already installed.
    • params - Default: {}, Extra parameters to be used when embedding the Player. Those are usefull to customize the Unity experience:
      • backgroundcolor - Default: “FFFFFF”, The background color of the web player content display region during loading, the default is white. Pro Only
      • bordercolor - Default: “FFFFFF”, The color of the one pixel border drawn around the web player content display region during loading. Pro Only
      • textcolor - Default: “000000”, The color of error message text (when data file fails to load for example). Pro Only
      • logoimage - Default: unity Logo, The path to a custom logo image, the logo image is drawn centered within the web player content display region during loading. Pro Only
      • progressbarimage - The path to a custom image used as the progress bar during loading. The progress bar image width is clipped based on the amount of file loading completed, therefore it starts with a zero pixel width and animates to its original width when the loading is complete. The progress bar is drawn beneath the logo image. Pro Only
      • progressframeimage - The path to a custom image used to frame the progress bar during loading. Pro Only
      • disableContextMenu - This parameter controls whether or not the Unity Web Player displays a context menu when the user right- or control-clicks on the content. Setting it to true prevents the context menu from appearing and allows content to utilize right-mouse behavior. To enable the context menu don’t include this parameter.
      • disableExternalCall - This parameter controls whether or not the Unity Web Player allows content to communicate with browser-based JavaScript. Setting it to true prevents browser communication and so content cannot call or execute JavaScript in the browser, the default is false.
      • disableFullscreen - This parameter controls whether or not the Unity Web Player allows content to be viewed in fullscreen mode. Setting it to true prevents fullscreen viewing and removes the “Go Fullscreen” entry from the context menu, the default is false.
    • attributes - Default: {}, Object containing list of attributes. These will be added to underlying <object> or <embed> tag depending on the browser.
    • debugLevel - Default: 0, Enables/Disables logging, useful when developing to be able to see the progress on the browser console. Set it greater to 0 to enable.

注意: 全ての色は16進数の色で指定しなければいけません。 (eg. FFFFFF, 020F16, etc.)。 画像のパスは相対パスまたは絶対パスを指定することができます。また画像のファイルはRGB(透過なし)またはRGBA(透過)の8bit/channelのPNGファイルでなければいけません。最後に,progressframeimageとprogressbarimageの高さが同じでなければいけません。

関数

進捗の観察

プラグインのインストール,かつ/または初期化の際に通知を受け取るコールバックを登録することができます。

パラメータ:

  • callback - プラグインのインストール/初期化に関する情報を得るためのコールバック関数です。このコールバックはprogressを受け取るオブジェクトです。
    • progress - It contains information about the current step of the plugin installation/initialization.
      • pluginStatus - Will contain a string identifying the plugin status, can be one of those:
        • unsupported` - The current Browser/OS is not supported
        • missing - Supported platform, but the plugin haven’t be installed yet.
        • installed - The plugin have finished installing, or was already installed.
        • first - called after the plugin have been installed at the first frame of the game is played (This will not be called if the plugin was already installed previously)
  • targetEl - Web Playerのコンテナとして機能するDOM要素です。(これは,UnityObject2.initPluginに渡すものと同じ要素です) * bestMethod - If the plugin is missing will contain the best installation path for the current platform, can be one of the following strings: * JavaInstall - It will use our “One Click” Java Applet to install the plugin * ClickOnceIE - It will use Internet Explorer’s Click Once install * Manual - It will ask the user to download a file and install it manually. * unityObj- A reference to the previously created unityObject2 instance responsible for this callback * ua - Contains some User Agent information used to decide the pluginStatus and bestMethod.

initPlugin

実際にゲームを起動しようとします。そして,事前に登録したコールバックを呼び出します。注意して下さい。

パラメータ:

  • containerElement - Web Playerのコンテナとして機能するDOM要素です。
  • gameURL - Web Playerのデータファイル(.unity3d)のURL。相対パスと絶対パスを利用することができます。

注意: この関数はcontainerElementがDOMに存在した後に呼び出す必要があります。安全のために,DOMが完全にロードするまで待つことができます。

installPlugin

指定された方法 method でプラグインをインストールします。もし方法が指定されなかった時,this.getBestInstallMethod()を呼び出して使用します。

パラメータ:

  • method - デフォルトは getBestInstallMethod(). インストール方法を文字列で指定します。 文字列は以下の値をサポートしています。: JavaInstall, ClickOnceIE, Manual.

注意: Not all methods are available in every platform/browser. Manual will download an exe/dmg installer and the user will need to perform a manual installation.

getUnity

これはPlayerの参照を返します。ですのでSendMessageを呼び出すことができます。

注意: WebPlayerがまだ初期化されていない場合はnullを返します。

例: この例は非常に簡単なUnityObject2の使い方です。もし既にユーザーがプラグインをインストールしていたらWebPlayerが正常にロードされ,それ以外の場合は隠されていた div.missing が表示され,インストールボタンが表示されます。 インストールが成功した後,WebPlayerは正常にロードされます。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Unity Web Player | "Sample"</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
        <!--
        var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
        if (document.location.protocol == 'https:')
            unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
        document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
        -->
    </script>
        <script type="text/javascript">
        var u = new UnityObject2();
        u.observeProgress(function (progress) {
            var $missingScreen = jQuery(progress.targetEl).find(".missing");
            switch(progress.pluginStatus) {
                case "unsupported":
                    showUnsupported();
                break;
                case "broken":
                    alert("You will need to restart your browser after installation.");
                break;
                case "missing":
                    $missingScreen.find("a").click(function (e) {
                        e.stopPropagation();
                        e.preventDefault();
                        u.installPlugin();
                        return false;
                    });
                    $missingScreen.show();
                break;
                case "installed":
                    $missingScreen.remove();
                break;
                case "first":
                break;
            }
        });
        jQuery(function(){
            u.initPlugin(jQuery("#unityPlayer")[0], "Example.unity3d");
        });
        </script>
    </head>
    <body>
        <p class="header">
            <span>Unity Web Player | </span>WebPlayer
        </p>
        <div class="content">
            <div id="unityPlayer">
                <div class="missing">
                    <a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
                        <img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
                    </a>
                </div>
            </div>
        </div>
        <p class="footer">&laquo; created with <a href="http://unity3d.com/unity/" title="Go to unity3d.com">Unity</a> &raquo;</p>
    </body>
</html>


Unity コンテンツをロードする HTML コード
Unity Webプレイヤーのロード画面