protected virtual void OnDestroy() { //Add #if UNITY_EDITOR_WIN if (webView == null) { return; } webView = null; #elif UNITY_WEBPLAYER Application.ExternalCall("unityWebView.destroy", name); #elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX if (webView == IntPtr.Zero) { return; } _CWebViewPlugin_Destroy(webView); webView = IntPtr.Zero; #elif UNITY_IPHONE if (webView == IntPtr.Zero) { return; } _CWebViewPlugin_Destroy(webView); webView = IntPtr.Zero; #elif UNITY_ANDROID if (webView == null) { return; } webView.Call("Destroy"); webView = null; #endif }
public void Init(Callback cb = null, bool transparent = false, string ua = "", Callback err = null, Callback ld = null, bool enableWKWebView = false) { onJS = cb; onError = err; onLoaded = ld; //Add #if UNITY_EDITOR_WIN webView = GreeWebViewEditorWindow.Create <GreeWebViewEditorWindow>("GreeEditorWebView", null, 200, 530, 800, 600); webView.onCallFromJS = CallFromJS; webView.onLoaded = CallOnLoaded; webView.onError = CallOnError; #elif UNITY_WEBPLAYER Application.ExternalCall("unityWebView.init", name); #elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX { var uri = new Uri(_CWebViewPlugin_GetAppPath()); var info = File.ReadAllText(uri.LocalPath + "Contents/Info.plist"); if (Regex.IsMatch(info, @"<key>CFBundleGetInfoString</key>\s*<string>Unity version [5-9]\.[3-9]") && !Regex.IsMatch(info, @"<key>NSAppTransportSecurity</key>\s*<dict>\s*<key>NSAllowsArbitraryLoads</key>\s*<true/>\s*</dict>")) { Debug.LogWarning("<color=yellow>WebViewObject: NSAppTransportSecurity isn't configured to allow HTTP. If you need to allow any HTTP access, please shutdown Unity and invoke:</color>\n/usr/libexec/PlistBuddy -c \"Add NSAppTransportSecurity:NSAllowsArbitraryLoads bool true\" /Applications/Unity/Unity.app/Contents/Info.plist"); } } #if UNITY_EDITOR_OSX // if (string.IsNullOrEmpty(ua)) { // ua = @"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53"; // } #endif webView = _CWebViewPlugin_Init( name, transparent, Screen.width, Screen.height, ua, Application.platform == RuntimePlatform.OSXEditor); // define pseudo requestAnimationFrame. EvaluateJS(@"(function() { var vsync = 1000 / 60; var t0 = window.performance.now(); window.requestAnimationFrame = function(callback, element) { var t1 = window.performance.now(); var duration = t1 - t0; var d = vsync - ((duration > vsync) ? duration % vsync : duration); var id = window.setTimeout(function() {t0 = window.performance.now(); callback(t1 + d);}, d); return id; }; })()"); rect = new Rect(0, 0, Screen.width, Screen.height); OnApplicationFocus(true); #elif UNITY_IPHONE webView = _CWebViewPlugin_Init(name, transparent, ua, enableWKWebView); #elif UNITY_ANDROID webView = new AndroidJavaObject("net.gree.unitywebview.CWebViewPlugin"); webView.Call("Init", name, transparent, ua); #else Debug.LogError("Webview is not supported on this platform."); #endif }