Пример #1
0
    public static WWW SmartCreateWww(string resPath)
    {
    #if STANDALONE
        string url = Path.Combine(Application.streamingAssetsPath, resPath);
        if (!url.Contains("://"))
        {
            url = "file:///" + url;
        }
    #else
        XmlResourceList.Item item        = RemoteResourceList.GetItem(resPath);
        XmlResourceList.Item builintItem = BuiltinResourceList.GetItem(resPath);
        if (item == null || item.Deleted)
        {
            Debug.LogError("Resource not in ResourceList: " + resPath);
            return(null);
        }
        string url = "";
        if (builintItem != null && item.Version <= builintItem.Version)
        {
            url = Path.Combine(Application.streamingAssetsPath, resPath);
            if (!url.Contains("://"))
            {
                url = "file:///" + url;
            }
        }
        else
        {
            url = "file:///" + UnityEngine.Application.persistentDataPath + "/" + resPath;
        }
#endif
        return(new WWW(url));
    }
Пример #2
0
 public static WWW CreateRemoteWww(string resPath)
 {
     XmlResourceList.Item item = RemoteResourceList.GetItem(resPath);
     if (item == null || item.Deleted)
     {
         Debug.LogError("Resource not in ResourceList: " + resPath);
         //这里本来是返回null,但上层会出错,所以还是返回一个无效的www
         return(new WWW(GetResourceRemoteUrl(resPath)));
     }
     return(new WWW(GetResourceRemoteUrl(resPath)));
 }
Пример #3
0
    /// <summary>
    /// 下载资源
    /// </summary>
    /// <returns></returns>
    private IEnumerator DownloadRemoteResource()
    {
        if (AssetLoader.RemoteResourceList.GetCount() <= 0)
        {
            yield break;
        }

        XmlResourceList.Item[] items     = AssetLoader.RemoteResourceList.GetAllItems();
        XmlResourceList        localList = new XmlResourceList();
        XmlResourceList        saveList  = new XmlResourceList();

        string localFileInfoPath_ = Path.Combine(Application.persistentDataPath, RuntimeSetting.FileInfoPath);

        if (File.Exists(localFileInfoPath_))
        {
            localList.ReadFromXml(File.ReadAllText(localFileInfoPath_));
            Debug.Log(localFileInfoPath_ + " EXIST");
            Debug.Log("Total:" + localList.GetCount());
        }
        else
        {
            Debug.Log(localFileInfoPath_ + " NOT EXIST");
        }

        ChildMaxNum = items.Length;
        ChildNowNum = 0;
        for (int i = 0; i < ChildMaxNum; i++)
        {
            XmlResourceList.Item item        = items[i];
            XmlResourceList.Item localItem   = localList.GetItem(item.Path);
            XmlResourceList.Item builtinItem = AssetLoader.BuiltinResourceList.GetItem(item.Path);
            if (item.Deleted)
            {
                ChildNowNum++;
                continue;
            }

            if (builtinItem != null && item.Version <= builtinItem.Version)
            {
                ChildNowNum++;
                saveList.AddToItems(item);
                continue;
            }
            if (localItem != null && item.Version <= localItem.Version)
            {
                ChildNowNum++;
                saveList.AddToItems(item);
                continue;
            }

            if (item.Path.Contains("fileinfo.xml"))
            {
                continue;
            }

            string readPath  = AssetLoader.GetResourceRemoteUrl(item.Path);
            string writePath = Path.Combine(Application.persistentDataPath, item.Path);

            yield return(StartCoroutine(DownloadToLocal(readPath, writePath)));

            if (!File.Exists(writePath))
            {
                Debug.LogError("Download file failed:" + readPath);
                yield break;
            }
            ChildNowNum++;
            saveList.AddToItems(item);
        }
        Utility.CreateDirByFilePath(localFileInfoPath_);
        saveList.Save(localFileInfoPath_);
        Debug.Log("Write new resource list: " + localFileInfoPath_);
    }