Beispiel #1
0
 public Sprite LoadSprite(string path, int width, int height)
 {
     return(FileHelper.ReadToSprite(path, width, height));
 }
Beispiel #2
0
 public Texture2D LoadTexture(string path, int width, int height)
 {
     return(FileHelper.ReadToTexture2D(path, width, height));
 }
Beispiel #3
0
 public byte[] LoadRes(string path)
 {
     return(FileHelper.ReadByteArray(path));
 }
Beispiel #4
0
 public string LoadStr(string path)
 {
     return(FileHelper.ReadTxtToStr(path));
 }
Beispiel #5
0
        /// <summary>
        /// 加载Androidmanifest
        /// </summary>
        /// <returns></returns>
        public bool LoadAssetManifest()
        {
            AssetBundleConfig config = null;

            switch (ABConfig.configWritingMode)
            {
            case ConfigWritingMode.Binary:
                if (FileHelper.JudgeFilePathExit(GetABConfigLocalPath()))
                {
                    if (configAB != null)
                    {
                        configAB.Unload(false);
                    }
                    configAB = AssetBundle.LoadFromFile(GetABConfigLocalPath());
                    TextAsset textAsset = configAB.LoadAsset <TextAsset>(ABConfigName);

                    if (textAsset == null)
                    {
                        Debug.LogError("AssetBundleConfig is no exist!");
                        return(false);
                    }
                    //反序列化,得到打包的信息
                    MemoryStream    stream = new MemoryStream(textAsset.bytes);
                    BinaryFormatter bf     = new BinaryFormatter();
                    config = (AssetBundleConfig)bf.Deserialize(stream);
                    stream.Close();
                }
                else
                {
                    AFLogger.e("AssetbundleConfig文件不存在");
                    return(false);
                }
                break;

            case ConfigWritingMode.TXT:
                string abJson = "";
                if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB)
                {
                    abJson = FileHelper.ReadTxtToStr(GetABConfigLocalPath());
                    if (abJson.Equals(""))
                    {
                        AFLogger.e("AssetbundleConfig文件不存在或者内容为空");
                        return(false);
                    }
                }
                else if (ABConfig.ABResLoadfrom == ABResLoadFrom.StreamingAssetAB)
                {
                    string    abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName;
                    TextAsset textAsset    = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset;
                    abJson = textAsset.text;
                }
                config = SerializeHelper.FromJson <AssetBundleConfig>(abJson);
                break;

            case ConfigWritingMode.XML:
                XmlDocument  xml = new XmlDocument();
                MemoryStream ms  = null;
                if (ABConfig.ABResLoadfrom == ABResLoadFrom.PersistentDataPathAB)
                {
                    xml.Load(GetABConfigLocalPath());
                }
                else
                {
                    string    abConfigPath = "AF-ABForLocal/AF-InfoFile" + GetVersionStr() + "/" + GetStrByPlatform() + ABConfigName;
                    TextAsset textAsset    = ResManager.Instance.LoadSync(ResLoadInfo.Allocate(ResFromType.ResourcesRes, abConfigPath, false)) as TextAsset;

                    //由于编码问题,要设置编码方式
                    byte[] encodeString = System.Text.Encoding.UTF8.GetBytes(textAsset.text);
                    //以流的形式来读取
                    ms = new MemoryStream(encodeString);
                    xml.Load(ms);
                }
                if (xml == null)
                {
                    AFLogger.e("AssetbundleConfig文件不存在或者内容为空");
                    return(false);
                }
                XmlSerializer xmldes = new XmlSerializer(typeof(AssetBundleConfig));
                StringReader  sr     = new StringReader(xml.InnerXml);
                config = (AssetBundleConfig)xmldes.Deserialize(sr);
                if (ms != null)
                {
                    ms.Close();
                    ms.Dispose();
                }
                if (sr != null)
                {
                    sr.Close();
                    sr.Dispose();
                }
                break;
            }
            ResManager.Instance.CacheABConfig(config);
            return(true);
        }