Beispiel #1
0
        public static byte [] GetDataFromStreamingAssets(string path, long readOffset, long readSize, out long bytesRead)
        {
            byte[] data  = null;
            long   bread = 0;

#if UNITY_ANDROID && !UNITY_EDITOR
            // 1 for android, read streaming assets from android jar
            data      = FileUtilsAndroid.ReadDataFromAppJar(path, readOffset, readSize, out bread);
            bytesRead = bread;
#else
            // 2 for other devices, read streaming assets from filesystem
            var streamingPath = Application.streamingAssetsPath + "/" + path;
            if (File.Exists(streamingPath))
            {
                data      = ReadBytesFromFile(streamingPath, readOffset, readSize, out bread);
                bytesRead = bread;
            }
            else
            {
                //LogUtil.Debug("GetDataFromStreamingAssets: cannot find " + path);
                bytesRead = 0;
            }
#endif

            return(data);
        }
Beispiel #2
0
        public static string GetStringFromStreamingAssets(string path)
        {
            string data = null;

#if UNITY_ANDROID && !UNITY_EDITOR
            // 1 for android, read streaming assets from android jar
            long    bytesRead = 0;
            byte [] bytes     = FileUtilsAndroid.ReadDataFromAppJar(path, 0, 0, out bytesRead);
            if (bytes != null)
            {
                data = System.Text.Encoding.UTF8.GetString(bytes);
            }
#else
            // 2 for other devices, read streaming assets from filesystem
            var streamingPath = Application.streamingAssetsPath + "/" + path;
            if (File.Exists(streamingPath))
            {
                data = File.ReadAllText(streamingPath);
            }
            else
            {
                //LogUtil.Debug("GetStringFromStreamingAssets: cannot find " + path);
            }
#endif

            return(data);
        }
Beispiel #3
0
        public static bool IsFileExistsInStreamingAssets(string path)
        {
#if PROFILE_FILE
            Profiler.BeginSample("FileUtils.IsFileExistsInStreamingAssets");
#endif

#if UNITY_ANDROID && !UNITY_EDITOR
            bool res = FileUtilsAndroid.IsFileExistsInAppJar(path);
#else
            var  streamingPath = Application.streamingAssetsPath + "/" + path;
            bool res           = File.Exists(streamingPath);
#endif

#if PROFILE_FILE
            Profiler.EndSample();
#endif
            return(res);
        }
Beispiel #4
0
        public static bool CopyFile(string srcfile, string dstfile, bool overwrite)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            if (FileUtilsAndroid.IsFileExistsInAppJar(srcfile))
            {
                return(FileUtilsAndroid.CopyFileFromAppJar(srcfile, dstfile, overwrite));
            }
            else
            {
                string fullpath = GetFullPathOfFile(srcfile);
                File.Copy(fullpath, dstfile, overwrite);
                return(true);
            }
#else
            string fullpath = GetFullPathOfFile(srcfile);
            File.Copy(fullpath, dstfile, overwrite);
            return(true);
#endif
        }