Exemple #1
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);
        }
Exemple #2
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);
        }