Beispiel #1
0
        /// <summary>
        /// (not android ) only! Android资源不在目录!
        /// Editor返回文件系统目录,运行时返回StreamingAssets目录
        /// </summary>
        /// <param name="url"></param>
        /// <param name="withFileProtocol">是否带有file://前缀</param>
        /// <param name="newUrl"></param>
        /// <returns></returns>
        public static bool TryGetInAppStreamingUrl(string url, bool withFileProtocol, out string newUrl)
        {
            if (withFileProtocol)
            {
                newUrl = PackagePathUrl + url;
            }
            else
            {
                newUrl = PackagePath + url;
            }

#if UNITY_ANDROID
            // Android平台下StreamingAssetsPath,在apk包里面,使用原生插件做文件检查
            if (!ResAndroidPlugin.IsAssetExists(url))
            {
                return(false);
            }
#else
            if (!File.Exists(PackagePath + url))
            {
                return(false);
            }
#endif
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// check file exists of streamingAssets. On Android will use plugin to do that.
        /// </summary>
        /// <param name="path">relative path,  when file is "file:///android_asset/test.txt", the pat is "test.txt"</param>
        /// <returns></returns>
        public static bool IsStreamingAssetsExists(string path)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            return(ResAndroidPlugin.IsAssetExists(path));
#else
            return(File.Exists(Path.Combine(Application.streamingAssetsPath, path)));
#endif
        }
Beispiel #3
0
        public static string LoadTextFromStreamingAssets(string path)
        {
            if (!IsStreamingAssetsExists(path))
            {
                throw new Exception("Not exist StreamingAssets path: " + path);
            }

#if UNITY_ANDROID
            return(ResAndroidPlugin.GetAssetString(path));
#else
            return(File.ReadAllText(Path.Combine(Application.streamingAssetsPath, path)));
#endif
        }
Beispiel #4
0
        public static byte[] ReadAllBytes(string path)
        {
            var getResPathType = GetBundleFullPath(path, out var fullPath);

            if (getResPathType == ResPathType.Invalid)
            {
                return(null);
            }

#if UNITY_ANDROID
            if (getResPathType == ResPathType.InApp)
            {
                return(ResAndroidPlugin.GetAssetBytes(path));
            }
#endif
            return(File.ReadAllBytes(fullPath));
        }
Beispiel #5
0
        public static string ReadAllText(string path)
        {
            string fullPath;
            var    getResPathType = GetBundleFullPath(path, out fullPath);

            if (getResPathType == ResPathType.Invalid)
            {
                return(null);
            }

#if UNITY_ANDROID
            if (getResPathType == ResPathType.InApp)
            {
                return(ResAndroidPlugin.GetAssetString(path));
            }
#endif
            return(File.ReadAllText(fullPath));
        }