Пример #1
0
    private void LoadConfigUsingJson()
    {
        string[] paths = BetterStreamingAssets.GetFiles("\\", "*.txt", SearchOption.AllDirectories);

        for (int n = 0; n < paths.Length; ++n)
        {
            byte[] byteContents   = BetterStreamingAssets.ReadAllBytes(paths[n]);
            string contentsString = System.Text.Encoding.UTF8.GetString(byteContents);

            if ("clientConfig.txt" == paths[n])
            {
                LoadClientConfig(contentsString);
                Debug.Log("load clientconfig");
            }
            else
            if ("serverConfig.txt" == paths[n])
            {
                LoadServerConfig(contentsString);
                C2Session.Instance.OnInit();
            }
            else
            {
                Debug.Log($"zz : {paths[n]}");
            }
        }
    }
Пример #2
0
    // Start is called before the first frame update
    void Start()
    {
        BetterStreamingAssets.Initialize();

        string[] paths2 = BetterStreamingAssets.GetFiles("new_trash", "*.png", System.IO.SearchOption.AllDirectories);
        GameController = GameObject.FindGameObjectWithTag("GameController");
        sp             = GameController.GetComponent <SpritePickerAR>();



        int r = UnityEngine.Random.Range(0, paths2.Length);

        Debug.Log(r);

        string ok = paths2[r];

        ok = ok.Remove(0, 10);
        ok = ok.Replace(".png", string.Empty);

        Debug.Log(ok);


        this.name = ok;
        var sprite_res = Resources.Load <Sprite>("NewTrashToSpawn/" + ok);

        this.GetComponent <Image>().sprite = sprite_res;
    }
Пример #3
0
    static public void Import()
    {
        string   lastFilePath = "";
        DateTime dateTimeFile = new DateTime();

        foreach (string file in BetterStreamingAssets.GetFiles("SavedLayout", "*.json"))
        {
            var fileInfo = new FileInfo(file);
            if (DateTime.Compare(fileInfo.CreationTime, dateTimeFile) > 0)
            {
                lastFilePath = file;
                dateTimeFile = fileInfo.CreationTime;
            }
        }
        try
        {
            Config config = DeserializeFromFile(lastFilePath);

            foreach (Config.Element element in config.elements)
            {
                GameObject obj = GameObject.Find(element.name);
                obj.transform.position = element.position;
                obj.transform.rotation = element.rotation;
            }
        }
        catch
        {
        }
    }
Пример #4
0
        private void Initialize()
        {
            m_allStreamingAssets = BetterStreamingAssets.GetFiles("/", "*", SearchOption.AllDirectories);

            coroutineHost = gameObject.AddComponent <CoroutineHost>();

            // allocate something for mono heap to grow
            var bytes = new byte[200 * 1024 * 1024];

            Debug.LogFormat("Allocated {0}, mono heap size: {1}", bytes.Length, Profiler.GetMonoHeapSizeLong());
        }
Пример #5
0
    void Start()
    {
        string[] allfiles = BetterStreamingAssets.GetFiles("/", "*.*");

        foreach (string files in allfiles)
        {
            if (files.Contains("sea")) // checking of whether name matches or not
            {
                StartCoroutine("Process", files);
            }
        }
    }
Пример #6
0
    /// <summary>
    /// Método que crea la base de datos y la rellena.
    /// </summary>
    public void CreateDB()
    {
        ArrayPow2();

        //Creación de tablas si no existen
        _connection.CreateTable <Textura>();
        _connection.CreateTable <Buildings>();
        _connection.CreateTable <Numeracion>();

        try
        {
            if (this.GetTamtablaTexture() == 0)
            {
                //Sí la BBDD está vacia carga las texturas de prueba
                if (Application.platform == RuntimePlatform.Android)
                {
                    BetterStreamingAssets.Initialize();
                    string[] dirs = BetterStreamingAssets.GetFiles("texturasInicial", "*.*");


                    foreach (string nombreimage in dirs)
                    {
                        if (!nombreimage.Contains(".meta") && (nombreimage.Contains(".jpg") || nombreimage.Contains(".png")))
                        {
                            string[] subfile = nombreimage.Split('/');
                            GuardarImagen(BetterStreamingAssets.ReadAllBytes(nombreimage), subfile[1]);
                        }
                    }
                }
                else
                {
                    //analiza si hay nuevas fotos de prueba que añadir y las añade
                    string[] dirs = System.IO.Directory.GetFiles(@"Assets/StreamingAssets/texturasInicial");

                    foreach (string nombreimage in dirs)
                    {
                        if (!nombreimage.Contains(".meta") && (nombreimage.Contains(".jpg") || nombreimage.Contains(".png")))
                        {
                            string[] subfile = nombreimage.Split('\\');

                            GuardarImagen(File.ReadAllBytes(@"Assets/StreamingAssets/texturasInicial/" + subfile[1]), subfile[1]);
                        }
                    }
                }
            }
        }
        catch { Debug.Log("No existe la carpeta TexturaInicial"); }
        return;
    }
        //[Test]
        public void ReadAllBytesZeroFile()
        {
            NeedsTestData();

            foreach (var path in BetterStreamingAssets.GetFiles(TestDirName, "raw_compressable*", SearchOption.TopDirectoryOnly))
            {
                var bytes = BetterStreamingAssets.ReadAllBytes(path);
                for (int i = 0; i < bytes.Length; ++i)
                {
                    if (bytes[i] != 0)
                    {
                        Assert.Fail();
                    }
                }
            }
        }
Пример #8
0
    public List <string> GetLangs()
    {
        List <string> mainLangs = new List <string>();

        mainPaths.Clear();
        m_allStreamingAssets = BetterStreamingAssets.GetFiles("/", "*", SearchOption.AllDirectories);

        foreach (string path in m_allStreamingAssets)
        {
            if (path.Contains("main"))
            {
                mainLangs.Add(BetterStreamingAssets.ReadAllLines(path)[0]);
                mainPaths.Add(path.Replace("main", ""));
            }
        }
        return(mainLangs);
    }
Пример #9
0
    public void LoadLocalDB()
    {
        string[] jsonFiles = BetterStreamingAssets.GetFiles("\\LocalDB", "*.txt", SearchOption.AllDirectories);
        for (int n = 0; n < jsonFiles.Length; ++n)
        {
            byte[] byteContents = BetterStreamingAssets.ReadAllBytes(jsonFiles[n]);
            string dbText       = System.Text.Encoding.UTF8.GetString(byteContents);

            //string dbText = jsonFiles[n];  // 스트링에 로드된 텍스트 에셋을 저장

            Debug.Log(dbText);

            Schema schema = JsonMapper.ToObject <Schema>(dbText);  // 맵퍼를 이용해서, 텍스트를 매핑.

            localDatabase.Add(schema.nickname, schema);
        }
    }
        private void TestGetFiles(string dir, string pattern, SearchOption opt, int minCount, int maxCount)
        {
            var files      = GetRealFiles(dir, pattern, opt);
            var otherFiles = BetterStreamingAssets.GetFiles(dir, pattern, opt);

            System.Array.Sort(files);
            System.Array.Sort(otherFiles);

            Assert.AreEqual(files.Length, otherFiles.Length);

            Assert.GreaterOrEqual(files.Length, minCount);
            Assert.LessOrEqual(files.Length, maxCount);

            for (int i = 0; i < files.Length; ++i)
            {
                Assert.AreEqual(files[i], otherFiles[i]);
            }
        }
Пример #11
0
        // Use this for initialization
        public void Start()
        {
            var levelReached = PlayerPrefs.GetInt("levelReached", 0);

            BetterStreamingAssets.Initialize();
            var        paths        = BetterStreamingAssets.GetFiles("/", "*TD.json", SearchOption.TopDirectoryOnly);
            JSONObject customLevels = LevelManager.GetCustomLevels();
            var        i            = 0;

            LevelButtons = new LevelItem[paths.Length + customLevels.Count + 1];
            foreach (var path in paths)
            {
                var fname     = path.Split('_')[0];
                var level     = Instantiate(LevelButton, transform);
                var levelItem = level.GetComponent <LevelItem>();
                levelItem.SetName(i.ToString());
                levelItem.SetFilename(fname);
                levelItem.IsCustom = false;
                if (i <= levelReached)
                {
                    levelItem.SetInteractable(true);
                }

                LevelButtons[i] = levelItem;

                i++;
            }

            for (int j = 0; j < customLevels.Count; j++)
            {
                JSONObject jsonLevel = customLevels[j];
                var        level     = Instantiate(LevelButton, transform);
                var        levelItem = level.GetComponent <LevelItem>();
                levelItem.IsCustom = true;
                levelItem.SetName("C");
                levelItem.SetFilename(jsonLevel["Name"].str);
                levelItem.SetInteractable(true);

                LevelButtons[i] = levelItem;

                i++;
            }
        }
Пример #12
0
    private void loadCards()
    {
        var jsonFiles = BetterStreamingAssets.GetFiles("Json").Where(x => Path.GetExtension(x) == ".json").ToList();

        foreach (string level in jsonFiles)
        {
            Debug.Log("Found file");
            Debug.Log("Reading " + level);
            var jsonText = BetterStreamingAssets.ReadAllLines(level);
            foreach (var line in jsonText)
            {
                CardPairClass cpc = JsonUtility.FromJson <CardPairClass>(line);
                cardsData.Add(cpc);
            }
        }

        SortCards();

        Debug.Log("Finished loading cards.");
    }
Пример #13
0
    private void Awake()
    {
        BetterStreamingAssets.Initialize();

        Instance = this;
        //Inventorize availible laguages and make them availible
        foreach (string s in BetterStreamingAssets.GetFiles("Languages", "*.xml", SearchOption.AllDirectories))
        {
            AvailableLanguages.Add(s.Split('.')[0].Split('/')[1]);
        }
        //load english, if not availible load first langauge found
        if (LoadedLanguage == null)
        {
            if (AvailableLanguages.Contains("en"))
            {
                LoadLanguage("en");
            }
            else
            {
                LoadedLanguage = new LanguageContainer();
            }
        }
    }
Пример #14
0
    IEnumerator LoadJson()
    {
        var jsonToLoad = BetterStreamingAssets.GetFiles(filePath).Where(x => Path.GetExtension(x) == ".json").ToList();

        while (jsonToLoad.Count != 0)
        {
            var jsonFile = jsonToLoad[0];
            jsonToLoad.RemoveAt(0);
            var jsonText = BetterStreamingAssets.ReadAllText(jsonFile);
            try
            {
                JsonUtility.FromJsonOverwrite(jsonText, this);
            }
            catch (Exception e)
            {
                Debug.Log($"Falha ao carreggar {jsonFile}, erro: {e.Message}");
            }

            yield return(0);
        }

        Loaded = true;
        GameDataLoaded?.Invoke(this, EventArgs.Empty);
    }
Пример #15
0
    /// <summary>
    /// Obtiene las imagenes que esten en la carpeta Imagen del movil
    /// </summary>
    public void ObtenerDeImage()
    {
        string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("/Android")) + "/Imagen";

        BetterStreamingAssets.Initialize();

        if (Application.platform == RuntimePlatform.Android)
        {
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
                string[] dirs = BetterStreamingAssets.GetFiles("Otratextura", "*.*");
                foreach (string nombreimage in dirs)
                {
                    if (!nombreimage.Contains(".meta"))
                    {
                        //Se almacena la imagen de prueba
                        string[]  subfile = nombreimage.Split('/');
                        Texture2D ss      = new Texture2D(2, 2);
                        byte[]    b       = BetterStreamingAssets.ReadAllBytes(nombreimage);
                        ss.LoadImage(b);
                        File.WriteAllBytes(path + "/Final.png", b);
                        File.OpenRead(path + "/Final.png");
                        //Se fuerza un escaneo de la imagen de prueba
                        using (AndroidJavaClass jcUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
                            using (AndroidJavaObject joActivity = jcUnityPlayer.GetStatic <AndroidJavaObject>("currentActivity"))
                                using (AndroidJavaObject joContext = joActivity.Call <AndroidJavaObject>("getApplicationContext"))
                                    using (AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass("android.media.MediaScannerConnection"))
                                        using (AndroidJavaClass jcEnvironment = new AndroidJavaClass("android.os.Environment"))
                                            using (AndroidJavaObject joExDir = jcEnvironment.CallStatic <AndroidJavaObject>("getExternalStorageDirectory"))
                                            {
                                                jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { path + "/Final.png" }, null, null);
                                            }
                    }
                }
                //aviso de carpeta creada
                Menu_aviso.SetActive(true);
                GameObject aviso = GameObject.Find("Aviso");
                aviso.GetComponent <Text>().text = "Agrege las fotos a la carpeta Imagen en tu galería y vuelve a pulsar";
            }
            else
            {
                string[] dirs = System.IO.Directory.GetFiles(path);

                if (dirs.Length == 1)
                {
                    //no hay fotos que añadir
                    Menu_aviso.SetActive(true);
                    GameObject aviso = GameObject.Find("Aviso");
                    aviso.GetComponent <Text>().text = "No hay fotos que agregar";
                }
                else
                {
                    bool ninguna_nueva = true;
                    foreach (string nombreimage in dirs)
                    {
                        if (!nombreimage.Contains(".meta") && (nombreimage.Contains(".png") || nombreimage.Contains(".jpg")) && !nombreimage.Contains("Final.png"))
                        {
                            //Se comprueba si las fotos han sido ya guardadas en la BBDD
                            string[] sub            = nombreimage.Split('/');
                            string[] separador      = sub[sub.Length - 1].Split('.');
                            string   nombrecorrecto = separador[0];
                            Textura  textura        = ds.TexturaEnBaseDeDatos(nombrecorrecto);
                            if (textura == null)
                            {
                                //si no llega aqui es que no habia nuevas fotos que añadir
                                ninguna_nueva = false;
                                byte[] b     = File.ReadAllBytes(nombreimage);
                                int    valor = ds.GetTamtablaTexture();

                                ds.GuardarImagen(b, sub[sub.Length - 1].ToString());
                                Control.AñadirFoto(valor, ds);
                            }
                        }
                    }

                    Menu_aviso.SetActive(true);
                    GameObject aviso = GameObject.Find("Aviso");
                    if (!ninguna_nueva)
                    {
                        aviso.GetComponent <Text>().text = "Se han añadido al menú de textura";
                    }
                    else
                    {
                        aviso.GetComponent <Text>().text = "No habia ninguna nueva foto que añadir";
                    }
                }
            }
        }
    }
 public void TestGetFilesThrow(string dir)
 {
     Assert.Throws <IOException>(() => BetterStreamingAssets.GetFiles(dir, null, SearchOption.TopDirectoryOnly));
 }
Пример #17
0
    ///***************************************************///
    ///**************INITIALIZATION FUNCTIONS*************///
    ///***************************************************///
    void Start()
    {
        SLASH = (Application.platform == RuntimePlatform.Android ||
                 Application.platform == RuntimePlatform.OSXPlayer ||
                 Application.platform == RuntimePlatform.OSXEditor ||
                 Application.platform == RuntimePlatform.IPhonePlayer ||
                 Application.platform == RuntimePlatform.WindowsEditor ||
                 Application.platform == RuntimePlatform.WindowsPlayer)?"/":"\\";

        //defaultPalettePath = Application.streamingAssetsPath + "/Palettes";
        defaultPalettePath = Application.persistentDataPath; //SLASH+ "/Palettes";

        //Force set log path
        if (Application.platform == RuntimePlatform.Android ||
            Application.platform == RuntimePlatform.IPhonePlayer)
        {
            defaultJSONPath = Application.persistentDataPath;
        }
        else
        {
            defaultJSONPath = Application.streamingAssetsPath;
        }

        //Load all pre-baked CSV in streaming assets folder
        if (loadStreamingAssetsPalettes)
        {
            BetterStreamingAssets.Initialize();
            string[] paths;
            //f*cking Android gotta be special
            if (Application.platform == RuntimePlatform.Android)
            {
                paths = BetterStreamingAssets.GetFiles("Baked", "*.csv", SearchOption.AllDirectories);
            }
            else
            {
                paths = Directory.GetFiles(Application.streamingAssetsPath + SLASH + "Baked", "*.csv");
            }
            foreach (string path in paths)
            {
                string _path = path.Replace("\\", SLASH).Replace("/", SLASH);
                //Ignore specially tagged palettes
                string filename = getPaletteNameFromFilePath(_path);
                if (filename.Length >= 5 && filename.Substring(0, 5) == "[LOG]")
                {
                    Debug.Log("Found Log File. Ignoring"); continue;
                }
                //Load everything else
                LoadCSVPaletteFromStreamingAssets(_path);
            }
        }

        //Load all use-generated CSV
        //if(loadAllOnInit) { LoadAllCSVPalettes(); }
        if (loadAllOnInit)
        {
            LoadAllJSONPalettes();
        }

        //Init SImple File Browser (Mobile Android File Browser)
        InitSimpleFileBrowser();
    }
Пример #18
0
    // Start is called before the first frame update
    void Start()
    {
        BetterStreamingAssets.Initialize();

        string[] paths2 = BetterStreamingAssets.GetFiles("new_trash", "*.png", SearchOption.AllDirectories);



        /*
         * DirectoryInfo dir = new DirectoryInfo(Application.streamingAssetsPath);
         * Debug.Log("Path do tergo to " + Application.streamingAssetsPath);
         *
         * FileInfo[] info = dir.GetFiles("*.*");
         *
         *
         *
         *
         * int counter = 0;
         * int amount = 0;
         *
         *
         *
         *
         * foreach (FileInfo f in info) {
         *  amount++;
         * }
         *
         *
         *
         * arr = new String[amount/2];
         *
         * foreach (FileInfo f in info)
         * {
         *
         *
         *  string nazwa = f.ToString();
         *  Debug.LogWarning("f.Tostring() = " + nazwa);
         *  char last = nazwa[nazwa.Length - 1];
         *
         *  if (nazwa.Contains("meta") == false)
         *  {
         *
         *      Debug.LogWarning("Przed Splitowaniem");
         *      string[] words = nazwa.Split('\\');
         *
         *      foreach (var word in words)
         *      {
         *          Debug.LogWarning("Przed sprawdzeniem czy zawiera człon PNG");
         *          if (word.Contains("png") == true)
         *          {
         *              string wordexact = word.Replace(".png", string.Empty);
         *
         *              arr[counter] = wordexact;
         *              counter = counter + 1;
         *              Debug.LogWarning("Slowo dodane do listy.");
         *
         *          }
         *
         *      }
         *
         *
         *  }
         *
         * }/// wszystkie nazwy w stringu arrs */



        gm = GameObject.FindGameObjectWithTag("GameController");
        sp = gm.GetComponent <SpritePicker>();



        int r = UnityEngine.Random.Range(0, paths2.Length);

        Debug.Log(r);

        string ok = paths2[r];

        ok = ok.Remove(0, 10);
        ok = ok.Replace(".png", string.Empty);

        Debug.Log(ok);


        this.name = ok;
        var sprite_res = Resources.Load <Sprite>("NewTrashToSpawn/" + ok);

        this.GetComponent <SpriteRenderer>().sprite = sprite_res;
    }
Пример #19
0
    // Use this for initialization
    void Start()
    {
        if (string.IsNullOrEmpty(BetterStreamingAssets.Root))
        {
            BetterStreamingAssets.Initialize();
        }

        initMaps();

        string[] charElemFilePaths = BetterStreamingAssets.GetFiles("/CharacterElements/", "*.png", SearchOption.AllDirectories);

        foreach (string path in charElemFilePaths)
        {
            string lowerCasePath = path.ToLower();
            if (lowerCasePath.Contains("augenbrauen"))
            {
                elementTypeMap["Eyebrow"].Add(path);
            }
            else if (lowerCasePath.Contains("hemd"))
            {
                elementTypeMap["Shirt"].Add(path);
            }
            else if (lowerCasePath.Contains("body"))
            {
                elementTypeMap["Body"].Add(path);
            }
            else if (lowerCasePath.Contains("kleider") || lowerCasePath.Contains("onesies"))
            {
                elementTypeMap["Overall"].Add(path);
            }
            else if (lowerCasePath.Contains("shoes"))
            {
                elementTypeMap["Shoes"].Add(path);
            }
            else if (lowerCasePath.Contains("pants"))
            {
                elementTypeMap["Pants"].Add(path);
            }
            else if (lowerCasePath.Contains("hair") || lowerCasePath.Contains("helmet"))
            {
                elementTypeMap["Hair"].Add(path);
            }
            else if (lowerCasePath.Contains("kopfbedeckungen"))
            {
                elementTypeMap["Helmet"].Add(path);
            }
            else if (lowerCasePath.Contains("flecken"))
            {
                elementTypeMap["FacialFeatures"].Add(path);
            }
            else if (lowerCasePath.Contains("facialhair"))
            {
                elementTypeMap["FacialHair"].Add(path);
            }
            else if (lowerCasePath.Contains("headpiece"))
            {
                elementTypeMap["Headpiece"].Add(path);
            }
            else if (lowerCasePath.Contains("handheld"))
            {
                elementTypeMap["Handheld"].Add(path);
            }
            else if (lowerCasePath.Contains("makeup"))
            {
                elementTypeMap["Makeup"].Add(path);
            }
            else if (lowerCasePath.Contains("neckwear"))
            {
                elementTypeMap["Neckwear"].Add(path);
            }
            else if (lowerCasePath.Contains("wings"))
            {
                elementTypeMap["Wings"].Add(path);
            }
            else if (lowerCasePath.Contains("eyelids"))
            {
                elementTypeMap["Eyelids"].Add(path);
            }
            else
            {
                Debug.Log("Could not classify " + Path.GetFileName(path));
            }
        }

        initRandomCostume();
    }
Пример #20
0
        /************
        * EDITOR
        * **********/
        public static IEnumerator LoadAllDatabasesFromFile()
        {
            //Clear Databases
            conversationDatabase.Clear();
            itemDatabase.Clear();
            npcDatabase.Clear();

            //Initialise BSA
            BetterStreamingAssets.Initialize();

            //Get File Headers
            string[] conversationHeaders = BetterStreamingAssets.GetFiles("conversations", "*.xml", SearchOption.AllDirectories);
            string[] itemHeaders         = BetterStreamingAssets.GetFiles("items", "*.xml", SearchOption.AllDirectories);
            string[] npcHeaders          = BetterStreamingAssets.GetFiles("npcs", "*.xml", SearchOption.AllDirectories);

            //Load Conversations
            if (conversationHeaders.Length <= 0)
            {
                Debug.LogError("No XML Files to Load.");
            }

            for (int i = 0; i < conversationHeaders.Length; i++)
            {
                Stream           stream           = BetterStreamingAssets.OpenRead(conversationHeaders[i]);
                XmlSerializer    serializer       = new XmlSerializer(typeof(ConversationData));
                ConversationData conversationdata = (ConversationData)serializer.Deserialize(stream);
                stream.Close();
                conversationDatabase.Add(conversationdata.ID, conversationdata);
            }

            Debug.Log("Load converastions to database complete.");

            //Load Items
            if (itemHeaders.Length <= 0)
            {
                Debug.LogError("No XML Files to Load.");
            }

            for (int i = 0; i < itemHeaders.Length; i++)
            {
                Stream        stream     = BetterStreamingAssets.OpenRead(itemHeaders[i]);
                XmlSerializer serializer = new XmlSerializer(typeof(ItemData));
                ItemData      itemdata   = (ItemData)serializer.Deserialize(stream);
                stream.Close();
                itemDatabase.Add(itemdata.ID, itemdata);
            }

            Debug.Log("Load items to database complete.");

            //Load NPCs
            if (npcHeaders.Length <= 0)
            {
                Debug.LogError("No XML Files to Load.");
            }

            for (int i = 0; i < npcHeaders.Length; i++)
            {
                Stream        stream     = BetterStreamingAssets.OpenRead(npcHeaders[i]);
                XmlSerializer serializer = new XmlSerializer(typeof(NPCData));
                NPCData       npcdata    = (NPCData)serializer.Deserialize(stream);
                stream.Close();
                npcDatabase.Add(npcdata.ID, npcdata);
            }

            Debug.Log("Load NPCs to database complete.");

            yield break;
        }
Пример #21
0
    IEnumerator Start()
    {
        BetterStreamingAssets.Initialize();
        webViewObject = (new GameObject("WebViewObject")).AddComponent <WebViewObject>();
        webViewObject.Init(
            cb: (msg) =>
        {
            Debug.Log(string.Format("CallFromJS[{0}]", msg));
            HandleIncomingMessage(msg);
        },
            err: (msg) =>
        {
            Debug.Log(string.Format("CallOnError[{0}]", msg));
        },
            started: (msg) =>
        {
            Debug.Log(string.Format("CallOnStarted[{0}]", msg));
        },
            hooked: (msg) =>
        {
            Debug.Log(string.Format("CallOnHooked[{0}]", msg));
        },
            ld: (msg) =>
        {
            Debug.Log(string.Format("CallOnLoaded[{0}]", msg));
#if UNITY_EDITOR_OSX || (!UNITY_ANDROID && !UNITY_WEBPLAYER && !UNITY_WEBGL)
            // NOTE: depending on the situation, you might prefer
            // the 'iframe' approach.
            // cf. https://github.com/gree/unity-webview/issues/189
#if true
            webViewObject.EvaluateJS(@"
                  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
                    window.Unity = {
                      call: function(msg) {
                        window.webkit.messageHandlers.unityControl.postMessage(msg);
                      }
                    }
                  } else {
                    window.Unity = {
                      call: function(msg) {
                        window.location = 'unity:' + msg;
                      }
                    }
                  }
                ");
#else
            webViewObject.EvaluateJS(@"
                  if (window && window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.unityControl) {
                    window.Unity = {
                      call: function(msg) {
                        window.webkit.messageHandlers.unityControl.postMessage(msg);
                      }
                    }
                  } else {
                    window.Unity = {
                      call: function(msg) {
                        var iframe = document.createElement('IFRAME');
                        iframe.setAttribute('src', 'unity:' + msg);
                        document.documentElement.appendChild(iframe);
                        iframe.parentNode.removeChild(iframe);
                        iframe = null;
                      }
                    }
                  }
                ");
#endif
#elif UNITY_WEBPLAYER || UNITY_WEBGL
            webViewObject.EvaluateJS(
                "window.Unity = {" +
                "   call:function(msg) {" +
                "       parent.unityWebView.sendMessage('WebViewObject', msg)" +
                "   }" +
                "};");
#endif
            webViewObject.EvaluateJS(@"Unity.call('ua=' + navigator.userAgent)");
        },
            //transparent: false,
            //zoom: true,
            //ua: "custom user agent string",
#if UNITY_EDITOR
            separated: false,
#endif
            enableWKWebView: true,
            wkContentMode: 0);  // 0: recommended, 1: mobile, 2: desktop
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
        webViewObject.bitmapRefreshCycle = 1;
#endif
        // cf. https://github.com/gree/unity-webview/pull/512
        // Added alertDialogEnabled flag to enable/disable alert/confirm/prompt dialogs. by KojiNakamaru · Pull Request #512 · gree/unity-webview
        //webViewObject.SetAlertDialogEnabled(false);

        // cf. https://github.com/gree/unity-webview/pull/550
        // introduced SetURLPattern(..., hookPattern). by KojiNakamaru · Pull Request #550 · gree/unity-webview
        //webViewObject.SetURLPattern("", "^https://.*youtube.com", "^https://.*google.com");

        // cf. https://github.com/gree/unity-webview/pull/570
        // Add BASIC authentication feature (Android and iOS with WKWebView only) by takeh1k0 · Pull Request #570 · gree/unity-webview
        //webViewObject.SetBasicAuthInfo("id", "password");

        // webViewObject.SetMargins(5, 100, 5, Screen.height / 4);
        webViewObject.SetVisibility(true);


        //HandleIncomingMessage("{\"action\": \"Initialize\", \"payload\": \"{\\\"name\\\": \\\"afonso\\\", \\\"player\\\": \\\"maduro\\\"}\"}");

#if UNITY_IPHONE || UNITY_STANDALONE_OSX
        webViewObject.SetScrollBounceEnabled(false);
#endif

#if !UNITY_WEBPLAYER && !UNITY_WEBGL
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            //var sourcePath = System.IO.Path.Combine(Application.streamingAssetsPath, Url);
            var sourceBasePath = Application.streamingAssetsPath;
            //var sourceBasePath = "jar:file:/" + Application.dataPath + "!/assets/";
            var      destinationPath = Application.persistentDataPath;
            var      index           = System.IO.Path.Combine(destinationPath, "index.html");
            string[] files           = BetterStreamingAssets.GetFiles(System.IO.Path.Combine(Url == "" ? "/" : Url), "*", System.IO.SearchOption.AllDirectories);
            //string[] directories = System.IO.Directory.GetDirectories(sourcePath);
            string[] directories = GetPathArrayDirectories(files);

            foreach (string dirPath in directories)
            {
                System.IO.Directory.CreateDirectory(System.IO.Path.Combine(destinationPath, dirPath));
            }

            foreach (string newPath in files)
            {
                string fromPath = System.IO.Path.Combine(sourceBasePath, newPath);
                string toPath   = System.IO.Path.Combine(destinationPath, newPath);

                if (fromPath.Contains("://"))
                {
                    // Android
                    UnityWebRequest unityWebRequest = UnityWebRequest.Get(fromPath);
                    yield return(unityWebRequest.SendWebRequest());

                    byte[] result = unityWebRequest.downloadHandler.data;
                    System.IO.File.WriteAllBytes(toPath, result);
                }
                else
                {
                    System.IO.File.Copy(fromPath, toPath, true);
                }
            }

            webViewObject.LoadURL("file://" + index);
        }
#else
        if (Url.StartsWith("http"))
        {
            webViewObject.LoadURL(Url.Replace(" ", "%20"));
        }
        else
        {
            webViewObject.LoadURL("StreamingAssets/" + Url + "index.html");
        }
#endif
        yield break;
    }