コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】エディタで Web ページを表示する方法

概要

f:id:baba_s:20171229135417p:plain

上記のようにエディタ上で Web ページを表示したい場合は
下記のようなスクリプトを記述します

using System.Reflection;
using UnityEditor;

public static class Example
{
    [MenuItem( "Tools/Example" )]
    private static void Show()
    {
        var type = typeof( Editor )
            .Assembly
            .GetType( "UnityEditor.Web.WebViewEditorWindowTabs" )
        ;

        var attr =
            BindingFlags.Public |
            BindingFlags.Static |
            BindingFlags.FlattenHierarchy
        ;

        var methodInfo = type
            .GetMethod( "Create", attr )
            .MakeGenericMethod( type )
        ;

        methodInfo.Invoke( null, new object []
        {
            "Title", // ウィンドウのタイトル
            "https://google.co.jp", // URL
            300, // 横幅(最小)
            300, // 縦幅(最小)
            300, // 横幅(最大)
            300 // 縦幅(最大)
        } );
    }
}

関連記事