Ejemplo n.º 1
0
        public override void HandleDestroy()
        {
            //Debug.Log("BridgeTransportWebView: HandleDestroy");

            base.HandleDestroy();

            if (unityJSPlugin != null)
            {
                //UnityEngine.Object.DestroyImmediate(unityJSPlugin);
                UnityEngine.Object.Destroy(unityJSPlugin);
                unityJSPlugin = null;
            }
        }
Ejemplo n.º 2
0
        public static void HandleUnitySendMessageDispatch(string target, string method, string message)
        {
            //Debug.Log("UnityJSPlugin: HandleUnitySendMessageDispatch: target: " + target + " method: " + method + " message: " + message);

            if (!plugins.ContainsKey(target))
            {
                //Debug.Log("UnityJSPlugin: HandleUnitySendMessageDispatch: missing target: " + target + " method: " + method + " message: " + message);
                return;
            }

            UnityJSPlugin obj = plugins[target];

            //Debug.Log("UnityJSPlugin: HandleUnitySendMessageDispatch: sending to obj: " + ((obj == null) ? "null" : "OBJ"));

            obj.HandleUnitySendMessage(method, message);
        }
Ejemplo n.º 3
0
        public IEnumerator StartWebView()
        {
            //Debug.Log("BridgeTransportWebView: StartWebView: url: " + url);

#if UNITY_ANDROID && !UNITY_EDITOR
            //Debug.Log("BridgeTransportWebView: StartWebView: Android");

            string sourceDir = Application.streamingAssetsPath;
            string destDir   = Application.persistentDataPath;

            string filesPath = sourceDir + "/files.txt";
            string filesData = null;
            if (filesPath.Contains("://")) // Android jar: URLs
            //Debug.Log("BridgeTransportWebView: StartWebView: www reading filesPath: " + filesPath);
            {
                var www = new WWW(filesPath);
                yield return(www);

                filesData = www.text;
            }
            else
            {
                //Debug.Log("BridgeTransportWebView: StartWebView: reading filesPath: " + filesPath);
                filesData = File.ReadAllText(filesPath);
            }

            //Debug.Log("BridgeTransportWebView: StartWebView: filesData: " + filesData);

            string[] fileNames = filesData.Split(new char[] { '\n' });

            foreach (string fileName in fileNames)
            {
                //Debug.Log("BridgeTransportWebView: StartWebView: fileName: " + fileName);

                if (fileName == "" ||
                    fileName.StartsWith(".") ||
                    fileName.EndsWith(".meta"))
                {
                    continue;
                }

                string sourceFile = sourceDir + "/" + fileName;
                string destFile   = destDir + "/" + fileName;

                //Debug.Log("BridgeTransportWebView: StartWebView: Copying sourceFile: " + sourceFile + " to destFile: " + destFile);

                if (File.Exists(destFile))
                {
                    File.Delete(destFile);
                }

                byte[] data = null;
                if (sourceFile.Contains("://")) // Android jar: URLs
                //Debug.Log("BridgeTransportWebView: www reading: " + sourceFile);
                {
                    var www = new WWW(sourceFile);
                    yield return(www);

                    data = www.bytes;
                }
                else
                {
                    data = System.IO.File.ReadAllBytes(sourceFile);
                }
                //Debug.Log("BridgeTransportWebView: read " + data.Length + " bytes from: " + sourceFile);

                System.IO.File.WriteAllBytes(destFile, data);
                //Debug.Log("BridgeTransportWebView: wrote " + data.Length + " bytes to: " + destFile);
            }
#endif

            startTime = Time.time;

            unityJSPlugin = gameObject.AddComponent <UnityJSPlugin>();

            unityJSPlugin.onJS             += HandleJS;
            unityJSPlugin.onResult         += HandleResult;
            unityJSPlugin.onError          += HandleError;
            unityJSPlugin.onLoaded         += HandleLoaded;
            unityJSPlugin.onConsoleMessage += HandleConsoleMessage;
            unityJSPlugin.onTexture        += HandleTexture;

            unityJSPlugin.Init(transparent: transparent);

            if (initialFlushCaches)
            {
                unityJSPlugin.FlushCaches();
            }

            unityJSPlugin.SetRect(webViewWidth, webViewHeight);
            unityJSPlugin.SetVisibility(visibility);

            string cleanURL = CleanURL(bridge.url);
            unityJSPlugin.LoadURL(cleanURL);

            yield break;
        }
Ejemplo n.º 4
0
 private void OnApplicationQuit()
 {
     //Debug.Log("BridgeTransportWebView: OnApplicationQuit");
     UnityJSPlugin.DestroyPlugins();
 }