Exemplo n.º 1
0
        public async UniTask <LoadResult <byte[]> > LoadBytesAsync(string filename)
        {
            await UniTask.WaitWhile(() => processCount > 0);

            ++processCount;
            try
            {
                var fullPath = GetPath(filename);

                try
                {
                    using (var fileStream = System.IO.File.OpenRead(fullPath))
                    {
                        var bytes = new byte[fileStream.Length];
                        await fileStream.ReadAsync(bytes, 0, bytes.Length).AsUniTask();

                        return(new LoadResult <byte[]>(bytes));
                    }
                }
                catch (DirectoryNotFoundException ex)
                {
                    return(LoadResult <byte[]> .CreateNotFound(ex));
                }
                catch (FileNotFoundException ex)
                {
                    return(LoadResult <byte[]> .CreateNotFound(ex));
                }
            }
            finally
            {
                --processCount;
            }
        }
Exemplo n.º 2
0
        public LoadResult <byte[]> LoadBytes(string filename)
        {
            if (!PlayerPrefs.HasKey(filename))
            {
                return(LoadResult <byte[]> .CreateNotFound());
            }
            var value = PlayerPrefs.GetString(filename);

            return(new LoadResult <byte[]>(System.Convert.FromBase64String(value)));
        }
Exemplo n.º 3
0
        public LoadResult <byte[]> LoadBytes(string filename)
        {
            var fullPath = GetPath(filename);

            try
            {
                var bytes = System.IO.File.ReadAllBytes(fullPath);
                return(new LoadResult <byte[]>(bytes));
            }
            catch (DirectoryNotFoundException ex)
            {
                return(LoadResult <byte[]> .CreateNotFound(ex));
            }
            catch (FileNotFoundException ex)
            {
                return(LoadResult <byte[]> .CreateNotFound(ex));
            }
        }