Beispiel #1
0
    //文件在apk包内,需要用www加载,用www.text取得字符串
    public static AssetFileTool LoadFromString(string data)
    {
        AssetFileTool aft = new AssetFileTool();

        try
        {
            using (StringReader sr = new StringReader(data))
            {
                aft.version = int.Parse(sr.ReadLine());
                string line = sr.ReadLine();
                aft.platform = line;
                while (line != null)
                {
                    AssetCell ac = new AssetCell();
                    if (ac.ReadData(line))
                    {
                        try
                        {
                            aft.assetCells.Add(ac.path, ac);
                        }
                        catch (Exception e)
                        {
                            Debug.Log(line + ": " + e.Message);
                        }
                    }
                    else
                    {
                        Debug.LogWarning("Asset file error " + line);
                    }
                    line = sr.ReadLine();
                }
                sr.Close();
            }
            return(aft);
        }
        catch (System.Exception e)
        {
            Debug.LogError("Asset file load error " + e);
            return(null);
        }
    }
Beispiel #2
0
    //文件在apk包外
    public static AssetFileTool LoadFromFile(string path)
    {
        if (!File.Exists(path))
        {
            Debug.LogError("Loaded asset is not exist. Path: " + path);
            return(null);
        }
        AssetFileTool aft = new AssetFileTool();

        try
        {
            using (StreamReader sr = new StreamReader(File.OpenRead(path)))
            {
                aft.version = int.Parse(sr.ReadLine());
                string line = sr.ReadLine();
                aft.platform = line;
                while (line != null)
                {
                    AssetCell ac = new AssetCell();
                    if (ac.ReadData(line))
                    {
                        if (aft.assetCells.ContainsKey(ac.path))
                        {
                            Debug.LogError("key repeat: " + ac.path);
                        }
                        aft.assetCells.Add(ac.path, ac);
                    }
                    line = sr.ReadLine();
                }
                sr.Close();
            }
            return(aft);
        }
        catch (System.Exception e)
        {
            Debug.LogError("Asset file load error " + e.Message);
            return(null);
        }
    }