Skip to content

Instantly share code, notes, and snippets.

@kimsama
Created February 16, 2017 05:28
Show Gist options
  • Save kimsama/f539cc838738d8d33dd856447f020239 to your computer and use it in GitHub Desktop.
Save kimsama/f539cc838738d8d33dd856447f020239 to your computer and use it in GitHub Desktop.
Open WebView window within Unity editor. It runs fine with Unity 5.5.x and no crash when closing Unity editor.
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
/// <summary>
/// Open a webview within Unity editor. (similar as AssetStore window)
/// </summary>
public class WebViewEditorWindow : EditorWindow
{
static string Url = "http://google.com";
[MenuItem("Window/WebViewWindow")]
static void Open()
{
// "UnityEditor.Web.WebViewEditorWindow" does not work with Unity 5.5.x. Obsolete?
string typeName = "UnityEditor.Web.WebViewEditorWindowTabs";
// With Unity 5.5.x, calling UnityEngine.Types.GetType cause the following error:
// error CS0619 : 'UnityEngine.Types.GetType (string, string)'is obsolete :
// `This was an internal method which is no longer used'
Type type = Assembly.Load("UnityEditor.dll").GetType(typeName);
BindingFlags Flags = BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy;
var methodInfo = type.GetMethod("Create", Flags);
methodInfo = methodInfo.MakeGenericMethod(type);
methodInfo.Invoke(null, new object[] { "WebView", Url, 200, 530, 800, 600 });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment