チラ裏Unity

主にUnityについての備忘録ですが誰か様の為になれば

UnityでWebページを表示する

WebViewプラグインのインストール

  1. https://github.com/gree/unity-webviewでDownload ZIP
  2. ダウンロードしたzipファイルを展開
  3. Assets > Import Package > Custom Package...
  4. 2.で展開したディレクトリのdist/unity-webview.unitypackageを指定

 

Webページを表示するスクリプト

  1. 以下のスクリプトを適当なGameObjectにアタッチ
    #ifディレクティブはUnity FreeでPlayした際の「License error. This plugin is only supported in Unity Pro!」を回避するため
    using UnityEngine;

    public class SampleWebView : MonoBehaviour {

        void Start () {
            #if !UNITY_EDITOR
            WebViewObject webViewObject = this.transform.gameObject.AddComponent<WebViewObject>();
            webViewObject.Init();
            webViewObject.LoadURL("http://example.com/");
            webViewObject.SetVisibility(true);
            #endif
        }
    }

 

ビルド

以下の「UnityをAndroid実機で動かす」も参考

http://hwks.hatenadiary.jp/entry/2014/09/03/023017

  1. File > Build Settings...でAndroidにSwitch Platform
  2. Player Settings... > Other Settings > Configuration > Internet AccessをRequire
    (AndroidManifest.xmlに以下の定義を追加するため)
    <uses-permission android:name="android.permission.INTERNET" />
  3. File > Build & Run

 

補足