コード例 #1
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;
        }
コード例 #2
0
 public void UpdateVisibility()
 {
     unityJSPlugin.SetVisibility(visibility);
 }