KEngine's Android Plugins is a jar. Load sync from android asset folder. Unity3D's WWW class can only load async from asset folder, disgusting.
Esempio n. 1
0
        /// <summary>
        /// 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)
        {
            newUrl = Path.GetFullPath((withFileProtocol ? AppBasePathWithProtocol : AppBasePath) + url);

            if (Application.isEditor)
            {
                // Editor进行文件检查
                if (!File.Exists(Path.GetFullPath(AppBasePath + url)))
                {
                    return(false);
                }
            }
            else if (Application.platform == RuntimePlatform.Android) // 注意,StreamingAssetsPath在Android平台時,壓縮在apk里面,不要使用File做文件檢查
            {
                return(KEngineAndroidPlugin.IsAssetExists(url));
            }

            // Windows/Editor平台下,进行大小敏感判断
            if (Application.isEditor)
            {
                var result = FileExistsWithDifferentCase(AppBasePath + url);
                if (!result)
                {
                    Log.Error("[大小写敏感]发现一个资源 {0},大小写出现问题,在Windows可以读取,手机不行,请改表修改!", url);
                }
            }

            return(true);
        }
Esempio n. 2
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 = ProductPathWithProtocol + url;
            else
                newUrl = ProductPathWithoutFileProtocol + url;

            // 注意,StreamingAssetsPath在Android平台時,壓縮在apk里面,不要做文件檢查了
            if (!Application.isEditor && Application.platform == RuntimePlatform.Android)
            {
                if (!KEngineAndroidPlugin.IsAssetExists(url))
                    return false;
            }
            else
            {
                // Editor, 非android运行,直接进行文件检查
                if (!File.Exists(ProductPathWithoutFileProtocol + url))
                {
                    return false;
                }
            }

            // Windows/Edtiro平台下,进行大小敏感判断
            if (Application.isEditor)
            {
                var result = FileExistsWithDifferentCase(ProductPathWithoutFileProtocol + url);
                if (!result)
                {
                    Log.Error("[大小写敏感]发现一个资源 {0},大小写出现问题,在Windows可以读取,手机不行,请改表修改!", url);
                }
            }
            return true;
        }
Esempio n. 3
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 (Application.platform == RuntimePlatform.Android)
                return KEngineAndroidPlugin.IsAssetExists(path);

            var fullPath = Path.Combine(Application.streamingAssetsPath, path);
            return File.Exists(fullPath);
        }
Esempio n. 4
0
        /// <summary>
        /// Load file from 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 byte[] LoadSyncFromStreamingAssets(string path)
        {
            if (!IsStreamingAssetsExists(path))
                throw new Exception("Not exist StreamingAssets path: " + path);

            if (Application.platform == RuntimePlatform.Android)
                return KEngineAndroidPlugin.GetAssetBytes(path);

            var fullPath = Path.Combine(Application.streamingAssetsPath, path);
            return ReadAllBytes(fullPath);
        }
Esempio n. 5
0
        /// <summary>
        /// Load file. 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 byte[] LoadAssetsSync(string path)
        {
            string fullPath = GetResourceFullPath(path, false);

            if (string.IsNullOrEmpty(fullPath))
            {
                return(null);
            }

            if (Application.platform == RuntimePlatform.Android)
            {
                return(KEngineAndroidPlugin.GetAssetBytes(fullPath));
            }

            return(ReadAllBytes(fullPath));
        }