/// <summary> /// Real-time rendering of webview content to the specified texture. /// </summary> /// <param name="texture"> /// Texture in which the content of the webview will be rendered /// </param> public void SetTexture(Texture2D texture) { Setup(); #if UNIWEBVIEW3_SUPPORTED UniWebViewInterface.SetTexture(listener.Name, texture); StartCoroutine("OnRenderTexture", UniWebViewInterface.GetRenderEventFunc()); #elif UNIWEBVIEW2_SUPPORTED UniWebViewPlugin.SetTexture(listener.Name, texture); StartCoroutine("OnRenderTexture", UniWebViewPlugin.GetRenderEventFunc()); #else WWebViewPlugin.SetTexture(listener.Name, texture); StartCoroutine("OnRenderTexture", WWebViewPlugin.GetRenderEventFunc()); #endif }
private void OnGUI() { if (Application.platform == RuntimePlatform.OSXEditor) { if (_webViewId != 0 && !_hidden) { Vector3 pos = Input.mousePosition; bool down = Input.GetMouseButton(0); bool press = Input.GetMouseButtonDown(0); bool release = Input.GetMouseButtonUp(0); float deltaY = Input.GetAxis("Mouse ScrollWheel"); bool keyPress = false; string keyChars = ""; short keyCode = 0; if (!string.IsNullOrEmpty(_inputString)) { keyPress = true; keyChars = _inputString.Substring(0, 1); keyCode = (short)_inputString[0]; _inputString = _inputString.Substring(1); } var id = _texture.GetNativeTexturePtr().ToInt32(); #if !UNITY_ANDROID UniWebViewPlugin.InputEvent(gameObject.name, (int)(pos.x - _webViewRect.x), (int)(pos.y - _webViewRect.y), deltaY, down, press, release, keyPress, keyCode, keyChars, id); #endif #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2_0 || UNITY_EDITOR GL.IssuePluginEvent(_webViewId); #else GL.IssuePluginEvent(UniWebViewPlugin.GetRenderEventFunc(), _webViewId); #endif Matrix4x4 m = GUI.matrix; GUI.matrix = Matrix4x4.TRS(new Vector3(0, Screen.height, 0), Quaternion.identity, new Vector3(1, -1, 1)); GUI.DrawTexture(_webViewRect, _texture); GUI.matrix = m; } } }