UnityEditor上で艦これはできる

この方のツイートを見てやってみました。

<blockquote class="twitter-tweet" lang="en"><p>UnityのEditor拡張で艦これタブとか誰か作ってそう</p>&mdash; 月琴かりん＠開発修羅場 (@karinharp) <a href="https://twitter.com/karinharp/status/520250463485038592">October 9, 2014</a></blockquote>


## Unity4.5

表示される。けど操作できない。

> あ...これ満員だからクリックしても反応ないだけ？艦これやったこと無いのでわかりません＼(^o^)／

![ss 2014-10-10 2.45.30.png](https://qiita-image-store.s3.amazonaws.com/0/5549/7cebf107-61c8-7e37-bcf9-fe349891bda2.png)


```csharp
using UnityEngine;
using UnityEditor;

public class Kancolle : EditorWindow
{
	WebView webview;

	[MenuItem("Window/Kancolle")]
	static void Open ()
	{
		var window = GetWindow<Kancolle> ();
		window.wantsMouseMove = true;
	}

	void OnGUI ()
	{
		if (webview == null) {
			webview = CreateInstance<WebView> ();
			webview.InitWebView ((int)position.width, (int)position.height - 23, true);
			webview.LoadURL ("http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/");
		} else {
			webview.DoGUI (new Rect (0, 0, position.width, position.height));
		}
	}
}
```


## Unity5.0

FlashPlayerに対応していません！

![ss 2014-10-10 2.10.13.png](https://qiita-image-store.s3.amazonaws.com/0/5549/4d131cfb-843e-4608-936c-f12083936a10.png)


```csharp
using UnityEngine;
using UnityEditor;
using System.Reflection;

public class Kancolle : EditorWindow
{
	static BindingFlags fullBinding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
	ScriptableObject webview;
	static MethodInfo setSizeAndPosition;

	[MenuItem("Window/Kancolle")]
	static void Open ()
	{
		var window = GetWindow<Kancolle> ();
		window.wantsMouseMove = true;
		if (window.webview == null) {

			var dockArea = typeof(EditorWindow).GetField ("m_Parent", fullBinding).GetValue (window);

			var webViewType = Types.GetType ("UnityEditor.WebView", "UnityEditor.dll");
			var initWebView = webViewType.GetMethod ("InitWebView", fullBinding);
			var loadURL = webViewType.GetMethod ("LoadURL", fullBinding);
			setSizeAndPosition = webViewType.GetMethod ("SetSizeAndPosition", fullBinding);


			window.webview = CreateInstance (webViewType);


			initWebView.Invoke (window.webview, new object[] {
				dockArea,
				0,
				23,
				(int)window.position.width,
				(int)window.position.height - 23,
				true
			});

			loadURL.Invoke (window.webview, new object[]{"http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/"});

		}


	}

	void OnGUI ()
	{
		if(setSizeAndPosition !=null)
			setSizeAndPosition.Invoke(webview,new object[]{0,
			23,
			(int)position.width,
			(int)position.height}
		);
	}
}
```

## Unity5.1.0f2


![ss 2015-05-25 12.25.24.png](https://qiita-image-store.s3.amazonaws.com/0/5549/bff726b1-8cee-bc38-e8da-e8c7f9caee60.png)

Flash動いた！

```csharp
using UnityEngine;
using UnityEditor;
using System.Reflection;

public class KancolleWindow : ScriptableObject
{
	static BindingFlags Flags = BindingFlags.Public | BindingFlags.Static;

	[MenuItem("Window/Kancolle")]
	static void Open ()
	{
		var type = Types.GetType ("UnityEditor.Web.WebViewEditorWindow", "UnityEditor.dll");
		var methodInfo = type.GetMethod ("Create", Flags);
		methodInfo = methodInfo.MakeGenericMethod (typeof(KancolleWindow));
		methodInfo.Invoke (null, new object[]{
            "Kancolle",
            "http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/",
            200, 530, 800, 600
        });
	}
}
```

## Unity5.4.0

`WebViewEditorWindow` が abstract になるので修正が必要です。

![](https://t.gyazo.com/teams/unity/16d4502a4708a3a7777d745ccbe337eb.png)

`WebViewEditorWindowTabs` を呼び出すようにします。

```csharp
using UnityEngine;
using UnityEditor;
using System.Reflection;

public class KancolleWindow : ScriptableObject
{
	static BindingFlags Flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;

	[MenuItem ("Window/Kancolle")]
	static void Open ()
	{
		var type = Types.GetType ("UnityEditor.Web.WebViewEditorWindowTabs", "UnityEditor.dll");

		var methodInfo = type.GetMethod ("Create", Flags);
		methodInfo = methodInfo.MakeGenericMethod (type);
		methodInfo.Invoke (null, new object[] {
			"Kancolle",
			"http://www.dmm.com/netgame/social/-/gadgets/=/app_id=854854/",
			200, 530, 800, 600
		});
	}
}
```