Esempio n. 1
0
    public IEnumerator ExtractResourceCoroutine()
    {
        var _7zPath = Path.Combine(Application.persistentDataPath, _compressUpdaterFile);

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

        BetterStreamingAssets.Initialize();

        _writeStream = new FileStream(_7zPath, FileMode.CreateNew);

        _readStream = BetterStreamingAssets.OpenRead(_compressUpdaterFile);

        _fileAsyncState = new AsyncFileOp.FileAsyncState(_readStream, _writeStream, true);


        AsyncFileOp.CopyAsync(_fileAsyncState);

        while (true)
        {
            if (_fileAsyncState.isDone)
            {
                var path1 = Path.Combine(Application.persistentDataPath, _compressUpdaterFile);
                _extractState = ExtractState.ING;
                plugin_7z.Extract7z(path1, Application.persistentDataPath, this.gameObject.name);

                break;
            }

            yield return(null);
        }
    }
        public void TestOpenReadCompareWithProjectFiles()
        {
            var files = GetRealFiles("/", null, SearchOption.AllDirectories);

            foreach (var f in files)
            {
                using (var a = File.OpenRead("Assets/StreamingAssets/" + f))
                    using (var b = BetterStreamingAssets.OpenRead(f))
                    {
                        Assert.IsTrue(StreamsEqual(a, b), f);
                    }
            }

            Assert.Throws <FileNotFoundException>(() => BetterStreamingAssets.OpenRead("FileThatShouldNotExist"));
        }
    public void LoadExpressions()
    {
        if (images == null)
        {
            images = new Dictionary <string, Sprite>();
        }
        string nameWithoutAccentuation;

        foreach (var expressao in expressoes)
        {
            if (images.ContainsKey(expressao))
            {
                continue;
            }

            if (nome == "André")
            {
                nameWithoutAccentuation = "Andre";
            }
            else if (nome == "Valéria")
            {
                nameWithoutAccentuation = "Valeria";
            }
            else
            {
                nameWithoutAccentuation = nome;
            }

            var filePath = CharacterImageLocation + "/" + nameWithoutAccentuation + "/" + expressao + ".png"; //Get path of folder
            Debug.Log(filePath);
            if (!BetterStreamingAssets.FileExists(filePath))
            {
                continue;
            }
            Texture2D tex = new Texture2D(2, 2);

            using (var stream = BetterStreamingAssets.OpenRead(filePath))
            {
                MemoryStream ms = new MemoryStream();
                stream.CopyTo(ms);
                tex.LoadImage(ms.ToArray());
                images[expressao] = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height),
                                                  new Vector2(0.5f, 0.5f),
                                                  100.0f);
            }
        }
    }
Esempio n. 4
0
    //Called by Central
    public void LoadLanguage(string languageCode)
    {
        string path = "Languages/" + languageCode + ".xml";

        if (!BetterStreamingAssets.FileExists(path))
        {
            Debug.LogErrorFormat("Streaming asset not found: {0}", path);
        }
        else
        {
            using (var stream = BetterStreamingAssets.OpenRead(path))
            {
                var serializer = new System.Xml.Serialization.XmlSerializer(typeof(LanguageContainer));
                LoadedLanguage = (LanguageContainer)serializer.Deserialize(stream);
            }
            OnNewLanguageLoaded.Invoke();
        }
    }
Esempio n. 5
0
    public Sprite LoadPortrait()
    {
        if (portrait != null)
        {
            return(portrait);
        }
        var filePath = CharacterPortraitLocation + id + ".png"; //Get path of folder

        using (var stream = BetterStreamingAssets.OpenRead(filePath))
        {
            MemoryStream ms = new MemoryStream();
            stream.CopyTo(ms);
            Texture2D tex = new Texture2D(100, 100);

            tex.LoadImage(ms.ToArray());
            portrait = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height),
                                     new Vector2(0.5f, 0.5f),
                                     100.0f);
        }
        return(portrait);
    }
Esempio n. 6
0
        internal static void LoadFileData(Action callback = null)
        {
#if !UNITY_ANDROID
            Stream GenerateStreamFromStreamingAsset(string fileName)
            {
                var filePath = Path.Combine(Application.streamingAssetsPath, fileName);

                var stream = File.Open(filePath, FileMode.Open, FileAccess.Read);

                return(stream);
            }
#else
            BetterStreamingAssets.Initialize();

            Stream GenerateStreamFromStreamingAsset(string fileName)
            {
                var stream = BetterStreamingAssets.OpenRead(fileName);

                return(stream);
            }
#endif

            Stream characterDataStream = GenerateStreamFromStreamingAsset("character_data.json");
            Stream locationDataStream  = GenerateStreamFromStreamingAsset("location_data.json");
            // SCENES ARE BEING LOADED FROM A CSV INSTEAD OF FROM AN .ODS
            // BECAUSE ANDROID'S STREAMING ASSETS ARE A PAIN IN THE BUTT,
            // AND THE TOOL I FOUND TO SOLVE THAT (BETTER STREAMING ASSETS)
            // DOESN'T SUPPORT LOADING COMPRESSED FILES, AND AN .ODS FILE
            // IS A COMPRESSED FILE.
            Stream scenesStream     = GenerateStreamFromStreamingAsset("scenes.csv");
            Stream adventuresStream = GenerateStreamFromStreamingAsset("adventures.csv");

            Data.FileData = Run.LoadGameData(characterDataStream, locationDataStream, scenesStream, adventuresStream, callback);

            characterDataStream.Close();
            locationDataStream.Close();
            scenesStream.Close();
        }
Esempio n. 7
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;
        }