Пример #1
0
    static void Open()
    {
        var editor = typeof(Editor).Assembly;

        webWindow = webView = null;

        if (unityListWindow == null)
        {
            unityListWindow           = new UnityListWindow();
            unityListWindow.hideFlags = HideFlags.HideAndDontSave;
        }

        webViewType   = editor.GetType("UnityEditor.WebView");
        webScriptType = editor.GetType("UnityEditor.Web.WebScriptObject");

        var cbMethod = editor.GetType("UnityEditor.WebViewV8CallbackCSharp").GetMethod("Callback");

        callback = (inst, message) => cbMethod.Invoke(inst, new object[] { message });

#if (UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0)
        webViewEditorWindowType = editor.GetType("UnityEditor.Web.WebViewEditorWindow");
        var methodInfo = webViewEditorWindowType.GetMethod("Create", Flags).MakeGenericMethod(webViewEditorWindowType);
#elif UNITY_5_4
        webViewEditorWindowType = editor.GetType("UnityEditor.Web.WebViewEditorWindowTabs");
        var methodInfo = webViewEditorWindowType.GetMethod("Create", Flags).MakeGenericMethod(webViewEditorWindowType);
#endif
        webWindow = methodInfo.Invoke(null, new object[] {
            "UnityList",
            url,
            200, 530, 800, 600
        });
        webViewEditorWindowType.GetProperty("hideFlags").SetValue(webWindow, HideFlags.HideAndDontSave, null);

        FreeEditorCoroutines.EditorCoroutine.StartCoroutine(connect(unityListWindow));
    }
Пример #2
0
    static IEnumerator connect(UnityListWindow win)
    {
        //Debug.Log("Step 1");
        //Debug.Log("test.." + (webView != null ? "exists" : "not found"));
        while (webView == null)
        {
            webView = webViewEditorWindowType.GetProperty("webView", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(webWindow, null);
            yield return(new WaitForSeconds(0.5f));
        }

        webViewEditorWindowType.GetProperty("titleContent").SetValue(webWindow, new GUIContent("UnityListX", EditorGUIUtility.FindTexture("UnityEditor.InspectorWindow")), null);

        //Debug.Log("Step 2");
        //Debug.Log("test.." + (webView != null ? "exists" : "not found"));
        webViewType.GetMethod("DefineScriptObject").Invoke(webView, new object[] { "window.unityScriptObject", win });
    }
Пример #3
0
 public void Send(string message)
 {
     UnityListWindow.callback(this.callback, message);
 }