Пример #1
0
        public static bool Load <T>(ref T item, string path) where T : IByteUtilizer, new()
        {
            var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
            var length = (int)stream.Length;

            byte[] bytes = new byte[length];
            stream.Read(bytes, 0, length);

            var reader = new ByteUtility.Reader(bytes);

            item = reader.ReadNextItem <T>();
            return(true);
        }
Пример #2
0
        public static bool Load <T>(ref T item, string folderName, string fileName) where T : IByteUtilizer, new()
        {
            string prefix     = Application.persistentDataPath + "/";
            string folderPath = prefix + folderName;
            string filePath   = folderPath + "/" + fileName;

            if (!File.Exists(filePath))
            {
                Debug.LogError($"File at [{filePath}] does not exist!");
                return(false);
            }

            var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            var length = (int)stream.Length;

            byte[] bytes = new byte[length];
            stream.Read(bytes, 0, length);

            var reader = new ByteUtility.Reader(bytes);

            item = reader.ReadNextItem <T>();
            return(true);
        }