Esempio n. 1
0
        public static Dictionary <string, object> LoadDictionaryFromStreamingAssets(string key)
        {
            BetterStreamingAssets.Initialize();
            string dataAsJson = BetterStreamingAssets.ReadAllText(key + JsonExtension);

            return(JsonConvert.DeserializeObject <Dictionary <string, object> >(dataAsJson, new GenericConverter()));
        }
Esempio n. 2
0
        public static T LoadNewtonsoftJsonFromStreamingAssets <T>(string key)
        {
            BetterStreamingAssets.Initialize();
            string dataAsJson = BetterStreamingAssets.ReadAllText(key + JsonExtension);

            return(JsonConvert.DeserializeObject <T>(dataAsJson, new JsonApiSerializerSettings()));
        }
Esempio n. 3
0
 static public Config DeserializeFromFile(string configPath)
 {
     if (BetterStreamingAssets.FileExists(configPath)) //File.Exists(configPath))
     {
         if (Path.GetExtension(configPath) == ".json")
         {
             string json = BetterStreamingAssets.ReadAllText(configPath);
             return(Deserialize(json, "json"));
         }
         else if (Path.GetExtension(configPath) == ".xml")
         {
             string xml = File.ReadAllText(configPath);
             return(Deserialize(xml, "xml"));
         }
         else
         {
             Debug.LogError("the configuration file format is not supported");
             throw new FormatException();
         }
     }
     else
     {
         Debug.LogError("configuration file not found");
         throw new FileNotFoundException();
     }
 }
Esempio n. 4
0
        public static T LoadJsonFromStreamingAssets <T>(string key)
        {
            BetterStreamingAssets.Initialize();
            string dataAsJson = BetterStreamingAssets.ReadAllText(key + JsonExtension);

            return(JsonUtility.FromJson <T>(dataAsJson));
        }
    public override void Save(eSaveType saveType)
    {
        strSave = "";

        JSONNode data;

        BetterStreamingAssets.Initialize();
        data = JSON.Parse(BetterStreamingAssets.ReadAllText(path));

        foreach (var iter in data)
        {
            strSave += iter.Value["skinName"] + ":";

            if (PlayerData.Instance.skinList.ContainsKey(iter.Value["skinName"]))
            {
                strSave += PlayerData.Instance.skinList[iter.Value["skinName"]].ToString();
            }
            else
            {
                strSave += false.ToString();
            }

            strSave += "/";
        }

        strSave = strSave.Remove(strSave.Length - 1);

        base.Save(saveType);
    }
Esempio n. 6
0
    void Start()
    {
        txt = gameObject.GetComponent <Text>();

        BetterStreamingAssets.Initialize();

        txt.text = BetterStreamingAssets.ReadAllText(fileName + ".txt");
    }
Esempio n. 7
0
    void creditos()
    {
        string texto;
        string arquivo;

        arquivo = "Credits.txt";

        BetterStreamingAssets.Initialize();
        texto         = BetterStreamingAssets.ReadAllText(arquivo);
        credito.text += texto;
    }
Esempio n. 8
0
 /// <summary>
 /// 读取文件内容
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="isUseSysIO"></param>
 /// <returns></returns>
 static private string ReadAssetAllText(string filePath)
 {
     if (isUseSysIO)
     {
         return(File.ReadAllText(filePath));
     }
     else
     {
         return(BetterStreamingAssets.ReadAllText(filePath));
     }
 }
Esempio n. 9
0
 private void LoadTargetData()
 {
     if (BetterStreamingAssets.FileExists(gameDataFileName))
     {
         loadedData = JsonUtility.FromJson <TargetData>(BetterStreamingAssets.ReadAllText(gameDataFileName));
         targets    = loadedData.targets;
         print("loadtargetdata successfull");
     }
     else
     {
         Debug.LogError("Cannot load game data!");
     }
 }
Esempio n. 10
0
    // Start is called before the first frame update
    void Start()
    {
        string          texto;
        string          arquivo;
        TextMeshProUGUI titulo;

        arquivo = "Title.txt";

        BetterStreamingAssets.Initialize();
        texto = BetterStreamingAssets.ReadAllText(arquivo);

        titulo      = gameObject.GetComponent <TextMeshProUGUI>();
        titulo.text = texto;
    }
Esempio n. 11
0
    private void Start()
    {
        Settings.PlayMode = 3;

        BetterStreamingAssets.Initialize();

        bool easy_exist   = BetterStreamingAssets.FileExists("/SudokuSample/easy.txt");
        bool medium_exist = BetterStreamingAssets.FileExists("/SudokuSample/medium.txt");
        bool hard_exist   = BetterStreamingAssets.FileExists("/SudokuSample/hard.txt");

        if (!easy_exist || !medium_exist || !hard_exist)
        {
            Settings.PlayMode = 0;
            return;
        }

        string easy_all_text   = BetterStreamingAssets.ReadAllText("/SudokuSample/easy.txt");
        string medium_all_text = BetterStreamingAssets.ReadAllText("/SudokuSample/medium.txt");
        string hard_all_text   = BetterStreamingAssets.ReadAllText("/SudokuSample/hard.txt");

        string[] easy_maps   = easy_all_text.Split('\n');
        string[] medium_maps = medium_all_text.Split('\n');
        string[] hard_maps   = hard_all_text.Split('\n');

        int easy_cnt = 0;

        foreach (var map in easy_maps)
        {
            fileManager.StartSaving($"easy{easy_cnt++}", map);
        }
        Settings.Easy_Cnt = easy_cnt;

        int medium_cnt = 0;

        foreach (var map in medium_maps)
        {
            fileManager.StartSaving($"medium{medium_cnt++}", map);
        }
        Settings.Medium_Cnt = medium_cnt;

        int hard_cnt = 0;

        foreach (var map in hard_maps)
        {
            fileManager.StartSaving($"hard{hard_cnt++}", map);
        }
        Settings.Hard_Cnt = hard_cnt;

        print($"Installed {easy_cnt}, {medium_cnt}, {hard_cnt}");
    }
Esempio n. 12
0
        /// <summary>
        /// 加载本地的Asset.info
        /// </summary>
        private List <AssetItem> LoadLocalAssetInfo(RuntimePlatform platform)
        {
            var retList = new List <AssetItem>();
            //优先加载persistent的Assets.info
            var persistentAssetInfoPath = BResources.GetAssetsInfoPath(BApplication.persistentDataPath, platform);

            if (File.Exists(persistentAssetInfoPath))
            {
                var content = File.ReadAllText(persistentAssetInfoPath);
                retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
            }
            //streaming 和其他的Assets.info
            else
            {
                //根据加载模式不同,寻找不同目录下的其他配置
                //打包时,本地会带一份ServerAssets.info以标记当前包携带的资源
                var loadArtRoot = BDLauncher.Inst.GameConfig.ArtRoot;
                switch (loadArtRoot)
                {
                case AssetLoadPathType.Persistent:
                case AssetLoadPathType.StreamingAsset:
                {
                    //TODO :BSA 读取,不需要Streaming前缀
                    var steamingAssetsInfoPath = IPath.Combine(BApplication.GetPlatformPath(platform), BResources.ASSETS_INFO_PATH);
                    //var steamingAssetsInfoPath = GetAssetsInfoPath(BDApplication.streamingAssetsPath, platform);
                    if (BetterStreamingAssets.FileExists(steamingAssetsInfoPath))
                    {
                        var content = BetterStreamingAssets.ReadAllText(steamingAssetsInfoPath);
                        retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
                    }
                }
                break;

                case AssetLoadPathType.DevOpsPublish:
                {
                    var path = GameConfig.GetLoadPath(loadArtRoot);
                    var devopsAssetInfoPath = BResources.GetAssetsInfoPath(path, platform);
                    if (File.Exists(devopsAssetInfoPath))
                    {
                        var content = File.ReadAllText(devopsAssetInfoPath);
                        retList = CsvSerializer.DeserializeFromString <List <AssetItem> >(content);
                    }
                }
                break;
                }
            }

            return(retList);
        }
Esempio n. 13
0
        /// <summary>
        /// Import the list of objects in objectList.
        /// </summary>
        protected virtual void Start()
        {
            string texto;
            string arquivo;

            if (autoLoadOnStart)
            {
                //variaveis
                arquivo = "Models.txt";
                Debug.Log(arquivo);
                BetterStreamingAssets.Initialize();
                texto = BetterStreamingAssets.ReadAllText(arquivo);
                int[] separacoes = new int[2];
                int   i = 0, cont = 0;
                //carregar a lista de objectos a importar
                do
                {
                    separacoes[0] = i;
                    Debug.Log("Entrou com cont = " + cont);
                    //pega o endereco do modelo
                    for (int j = 0; i < texto.Length && j < 8; i++)
                    {
                        if (texto[i] == '\n' || texto[i] == ' ')
                        {
                            if (j < 1)
                            {
                                separacoes[1] = i;
                            }
                            //Debug.Log(separacoes[j]);
                            j++;
                        }
                    }

                    //configura para carregar o modelo
                    ModelImportInfo mii = new ModelImportInfo();
                    mii.name = "object" + cont;
                    this.objectsList.Add(mii);
                    this.objectsList[cont].path = texto.Substring(separacoes[0], separacoes[1] - separacoes[0] - 1);
                    if (objectsList[cont].path[objectsList[cont].path.Length - 1] == 10)
                    {
                        objectsList[cont].path = objectsList[cont].path.Substring(0, objectsList[cont].path.Length - 2);
                    }
                    cont++;
                } while (i < texto.Length);

                //importar os  modelos
                ImportModelListAsync(objectsList.ToArray());
            }
        }
Esempio n. 14
0
 //Needed for damn Android StreamingAssets
 public void LoadCSVPaletteFromStreamingAssets(string path)
 {
     if (Application.platform == RuntimePlatform.Android)  //f*cking Android gotta be special
     {
         try{
             string encodedString = BetterStreamingAssets.ReadAllText(path);
             string filename      = getPaletteNameFromFilePath(path);
             LoadCSVPaletteFromEncodedString(pc.newPalette(true), encodedString, filename);
         } catch (Exception e) {
             Debug.LogWarning("Failed to load CSV: " + path); return;
         }
     }
     else
     {
         LoadCSVPalette(pc.newPalette(true), path);
     }
 }
Esempio n. 15
0
        private void loadLanguages()
        {
            if (!BetterStreamingAssets.FileExists("/lang/" + nameLanguagesFile + ".json"))
            {
                Debug.LogErrorFormat("Streaming asset not found: {0}", "/lang/" + nameLanguagesFile + ".json");
            }

            else
            {
                json = BetterStreamingAssets.ReadAllText("/lang/" + nameLanguagesFile + ".json");
                lang = JsonUtility.FromJson <Languages>(json);

                if (interfaceLanguages != null)
                {
                    interfaceLanguages.onChangeLanguage();
                }
            }
        }
Esempio n. 16
0
    private void ReadJson(string fileName)
    {
        var settings = new JsonSerializerSettings();

        BetterStreamingAssets.Initialize();


        #if UNITY_EDITOR
        //jsonPath = Application.streamingAssetsPath + "/"+fileName+".json";
        #endif

        //jsonStrng = File.ReadAllText(jsonPath);
        jsonStrng = BetterStreamingAssets.ReadAllText("/" + fileName + ".json");
        if (jsonStrng != null)
        {
            Leveldata = JsonConvert.DeserializeObject <LevelData>(jsonStrng, settings);
        }
        else
        {
            Debug.Log("JSON File not found ");
        }
    }
Esempio n. 17
0
        /// <summary>
        /// Import the list of objects in objectList.
        /// </summary>
        protected virtual void Start()
        {
            if (autoLoadOnStart)
            {
                BetterStreamingAssets.Initialize();

                objectsList[0].path = BetterStreamingAssets.ReadAllText("path.txt");

                //resolve problemas caso o .txt tenha sido criado em um linux
                if (objectsList[0].path[objectsList[0].path.Length - 1] == 10)
                {
                    objectsList[0].path = objectsList[0].path.Substring(0, objectsList[0].path.Length - 2);
                }

                /*
                 * objectsList[0].loaderOptions.modelScaling = 0.1f;
                 * objectsList[0].loaderOptions.localEulerAngles.x = 90;
                 * objectsList[0].loaderOptions.localPosition.y = 0.7f;
                 */

                ImportModelListAsync(objectsList.ToArray());
            }
        }
Esempio n. 18
0
    private void LoadGameData()
    {
        // Path.Combine combines strings into a file path
        // Application.StreamingAssets points to Assets/StreamingAssets in the Editor, and the StreamingAssets folder in a build
        //string filePath = Path.Combine(Application.streamingAssetsPath, gameDataFileName);

        if (BetterStreamingAssets.FileExists(gameDataFileName))
        {
            // Read the json from the file into a string
            //string dataAsJson = File.ReadAllText(filePath);
            // Pass the json to JsonUtility, and tell it to create a GameData object from it

            //GameData loadedData = JsonUtility.FromJson<GameData>(dataAsJson);
            loadedData = JsonUtility.FromJson <GameData>(BetterStreamingAssets.ReadAllText(gameDataFileName));
            // Retrieve the allRoundData property of loadedData
            Debug.Log("gameDataFileName");
            Debug.Log(gameDataFileName);
            allRoundData = loadedData.allRoundData;
        }
        else
        {
            Debug.LogError("Cannot load game data!");
        }
    }
Esempio n. 19
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);
    }
Esempio n. 20
0
    // Update is called once per frame
    void Update()
    {
        if (Imported == 1)
        {
            Imported = 2;

            //arrumar a(s) frase(s)
            string texto;
            string arquivo;

            //ler o arquivo do modelo
            arquivo = "model" + index + ".txt";
            BetterStreamingAssets.Initialize();
            texto = BetterStreamingAssets.ReadAllText(arquivo);

            //separacoes tera 9 pontos, o inicio, o fim do endereco, o fim das 3 variavies de posicao, fim das 3 variaveis de angulacao e fim da variavel de escala
            int[] separacoes = new int[9];

            //como possui um unico arquivo, e necessario percorrer todos os outros modelos ate chegar no desejado
            int aux = 0, x = 0, j = 0;
            for (; aux < texts3D.Length; aux++)
            {
                j             = 1;
                separacoes[0] = x;
                for (; x < texto.Length + 1 && j < 9; x++)
                {
                    //detecta o fim do campo pelo \n e pelo ' ' quando j<8 pois quando j=8 temos o texto que pode ter ' ', temos x == texto.Length para quando acabou o arquivo e nao tem uma linha em branco
                    if (x == texto.Length || texto[x] == '\n' || (texto[x] == ' ' && j < 8))
                    {
                        separacoes[j] = x;
                        j++;
                    }
                    //remove . dos numeros, j<8 pois quando j=8 temos o texto
                    else if (j < 8 && texto[x] == '.')
                    {
                        texto = texto.Remove(x, 1);
                        texto = texto.Insert(x, ",");
                    }
                }
                if (x == texto.Length)
                {
                    separacoes[8] = x;
                }

                //avisa caso haja caracteres invalidos no arquivo (na maioria dos casos resultara em erro de leitura)
                int linha = 1, coluna = 1;
                for (int l = 0; l < texto.Length - 1; l++)
                {
                    if (texto[l] == '\n')
                    {
                        linha++;
                        coluna = 1;
                    }
                    if (((texto[l] == '\n' || texto[l] == ' ') && (texto[l + 1] == '\n' || texto[l + 1] == ' ')) || (texto[l] < '0' && texto[l] > '9' && texto[l] != '.' && texto[l] != ' ' && texto[l] != '\n'))
                    {
                        Debug.Log("Erro de formatacao do arquivo de posicao da frase de indice " + index + "\nNa linha " + linha + " e coluna " + coluna);
                    }
                    if (texto[l] != '\n')
                    {
                        coluna++;
                    }
                }

                //carregar opcoes do modelo
                points[aux].transform.localPosition   = new Vector3(float.Parse(texto.Substring(separacoes[0], separacoes[1] - separacoes[0])), float.Parse(texto.Substring(separacoes[1] + 1, separacoes[2] - separacoes[1] - 1)), float.Parse(texto.Substring(separacoes[2], separacoes[3] - separacoes[2])));
                texts3DT[aux].transform.localPosition = new Vector3(float.Parse(texto.Substring(separacoes[3] + 1, separacoes[4] - separacoes[3] - 1)), float.Parse(texto.Substring(separacoes[4] + 1, separacoes[5] - separacoes[4] - 1)), float.Parse(texto.Substring(separacoes[5], separacoes[6] - separacoes[5])));
                Texts3D[aux].text = texto.Substring(separacoes[7] + 1, separacoes[8] - separacoes[7] - 1);



                texts3D[aux].transform.localScale = new Vector3(float.Parse(texto.Substring(separacoes[6] + 1, separacoes[7] - separacoes[6] - 1)), float.Parse(texto.Substring(separacoes[6] + 1, separacoes[7] - separacoes[6] - 1)), float.Parse(texto.Substring(separacoes[6] + 1, separacoes[7] - separacoes[6] - 1)));
            }
        }


        //CODIGO RELACIONADO COM: INTERACAO MARCADORES
        marker1Found = marker1NewTrackableEventHandlerComponent.MarkerFound;
        marker2Found = marker2NewTrackableEventHandlerComponent.MarkerFound;
        MarkersFound();

        if (UseLine)
        {
            setLines();//atualiza as linhas para ir do ponto origem até seu elemento respetivo
        }

        if (typeOfInformation == TypeOfInformation.canvasOfImages)//FOI ESCOLHIDO CANVASOFIMAGES
        {
            for (int i = 0; i < images.Length; i++)
            {
                images[i].transform.position = imagesT[i].transform.position;  //posiciona as images de myCanvas na posicao dos objetos emty
            }
            if (informationFollowARCamera)
            {
                InfoFollowARCamera(images);
            }
        }
        else if (typeOfInformation == TypeOfInformation.texts3D)//FOI ESCOLHIDO TEXTS3D
        {
            for (int i = 0; i < Texts3D.Length; i++)
            {
                Texts3D[i].transform.position = texts3DT[i].transform.position; //posiciona os texts3D na posicao dos objetos emty
            }
            if (informationFollowARCamera)
            {
                InfoFollowARCamera(Texts3D);
            }
        }
        else if (typeOfInformation == TypeOfInformation.sprites)//FOI ESCOLHIDO SPRITES
        {
            for (int i = 0; i < sprites.Length; i++)
            {
                sprites[i].transform.position = spritesT[i].transform.position;//posiciona os sprites na posicao dos objetos emty
            }
            if (informationFollowARCamera)
            {
                InfoFollowARCamera(sprites);
            }
        }
    }
Esempio n. 21
0
 public void FileToData()
 {
     data = JSON.Parse(BetterStreamingAssets.ReadAllText(path));
 }
Esempio n. 22
0
        private void OnImportComplete()
        {
            //ocorre se estiver no Question controller 1s
            if (first_question.GetComponent <I_QuestionController1>() != null)
            {
                first_question.GetComponent <I_QuestionController1>().Active = true;
                first_question.GetComponent <I_QuestionController1>().QuestionObjects[0].SetActive(true);
            }
            else
            if (first_question.GetComponent <I_QuestionController2>() != null)
            {
                first_question.GetComponent <I_QuestionController2>().Active = true;
                first_question.GetComponent <I_QuestionController2>().AnswerAlternatives[0].SetActive(true);
            }
            else        //ocorre no Imported_ActiveInformation
            {
                //coloca o modelo como filho do filho do marcador 1
                Model = gameObject.transform.GetChild(0).gameObject;
                Model.transform.SetParent(Marker.transform.GetChild(0).transform);

                string texto;
                string arquivo;
                //ler o arquivo do modelo
                arquivo = "models.txt";
                BetterStreamingAssets.Initialize();
                texto = BetterStreamingAssets.ReadAllText(arquivo);

                //separacoes tera 9 pontos, o inicio, o fim do endereco, o fim das 3 variavies de posicao, fimdas 3 variaveis de angulacao e fim da variavel de escala
                int[] separacoes = new int[9];

                int aux = 0, i = 0;

                for (int j = 0; i < texto.Length && j < 9; i++)
                {
                    if (aux == 0 && j == 0)
                    {
                        j++;
                    }
                    if (texto[i] == '\n' || texto[i] == ' ')
                    {
                        separacoes[j] = i;
                        j++;
                    }
                    //remove . from the numbers
                    else if (j > 0 && texto[i] == '.')
                    {
                        texto = texto.Remove(i, 1);
                        texto = texto.Insert(i, ",");
                    }
                }
                if (i == texto.Length)
                {
                    separacoes[8] = i;
                }

                float div = this.Marker.transform.localScale.x;

                Debug.Log(new Vector3(float.Parse(texto.Substring(separacoes[4] + 1, separacoes[5] - separacoes[4])), float.Parse(texto.Substring(separacoes[5], separacoes[6] - separacoes[5])), float.Parse(texto.Substring(separacoes[6], separacoes[7] - separacoes[6]))));
                if (div != 0)
                {
                    Model.transform.localPosition = new Vector3(float.Parse(texto.Substring(separacoes[1] + 1, separacoes[2] - separacoes[1] - 1)) / div, float.Parse(texto.Substring(separacoes[2] + 1, separacoes[3] - separacoes[2] - 1)) / div, float.Parse(texto.Substring(separacoes[3], separacoes[4] - separacoes[3])) / div);
                }
                else
                {
                    Debug.Log("Error, Marker scale is 0");
                }

                Model.transform.Rotate(Model.transform.localRotation.x * -1, Model.transform.localRotation.y * -1, Model.transform.localRotation.z * -1);
                Model.transform.Rotate(float.Parse(texto.Substring(separacoes[4] + 1, separacoes[5] - separacoes[4])), float.Parse(texto.Substring(separacoes[5], separacoes[6] - separacoes[5])), float.Parse(texto.Substring(separacoes[6], separacoes[7] - separacoes[6])));
                Model.transform.localScale = new Vector3(float.Parse(texto.Substring(separacoes[7] + 1, separacoes[8] - separacoes[7] - 1)), float.Parse(texto.Substring(separacoes[7] + 1, separacoes[8] - separacoes[7] - 1)), float.Parse(texto.Substring(separacoes[7] + 1, separacoes[8] - separacoes[7] - 1)));

                active_info.MyObject = Model;
                active_info.Imported = 1;
            }

            //indica que os modelos foram importados
            imported = true;



            //parte do codigo original
            if (progressText != null)
            {
                progressText.text = "";
            }
            if (progressSlider != null)
            {
                progressSlider.value = 100.0f;
                //progressSlider.gameObject.SetActive(false);
            }
            if (progressImage != null)
            {
                progressImage.fillAmount = 1f;
                progressImage.gameObject.SetActive(false);
            }
            gameObject.SetActive(false);
        }
Esempio n. 23
0
    void Start()
    {
        BetterStreamingAssets.Initialize();

        typeName = BetterStreamingAssets.ReadAllText("config-type.txt");
    }