コード例 #1
0
        IEnumerator InitAssetList()
        {
            string url = AssetManagerSetting.FilesCsvForStreaming;
            WWW    www = new WWW(url);

            yield return(www);

            assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath);
            if (string.IsNullOrEmpty(www.error))
            {
                string path, md5;

                using (StringReader stringReader = new StringReader(www.text))
                {
                    while (stringReader.Peek() >= 0)
                    {
                        string line = stringReader.ReadLine();
                        if (!string.IsNullOrEmpty(line))
                        {
                            string[] seg = line.Split(';');
                            path = seg[0];
                            md5  = seg[1];


                            assetList.Add(path, md5);

                            AssetManagerSetting.persistentAssetFileList.Remove(AssetManagerSetting.GetPlatformPath(path));
                        }
                    }
                }
            }

            assetList.Save(AssetManagerSetting.AssetFileListPath);
        }
コード例 #2
0
        public static AssetFileList DiffAssetFileList(AssetFileList current, AssetFileList update)
        {
            AssetFileList diffs = new AssetFileList();

            AssetFile gameConstItem = null;

            int count = update.list.Count;

            for (int i = 0; i < count; i++)
            {
                AssetFile item = update.list[i];

                if (item.path == AssetManagerSetting.GameConstName)
                {
                    gameConstItem = item;
                    continue;
                }

                if (!current.Has(item.path))
                {
                    diffs.Add(item);
                }
                else if (item.md5 != current.Get(item.path).md5)
                {
                    diffs.Add(item);
                }
            }

            if (gameConstItem != null)
            {
                diffs.Add(gameConstItem);
            }
            else
            {
                diffs.Add(new AssetFile(AssetManagerSetting.GameConstName, "md5"));
            }

            return(diffs);
        }
コード例 #3
0
        public static AssetFileList Deserialize(string txt)
        {
            AssetFileList list = new AssetFileList();

            using (StringReader stringReader = new StringReader(txt))
            {
                while (stringReader.Peek() >= 0)
                {
                    string line = stringReader.ReadLine();
                    if (!string.IsNullOrEmpty(line))
                    {
                        string[] seg = line.Split(';');
                        list.Add(seg[0], seg[1]);
                    }
                }
            }

            return(list);
        }
コード例 #4
0
        public static void CopyUpdateAsset(string serverRoot)
        {
            PathUtil.CheckPath(serverRoot, false);
            string updateAssetListPath = null;

            if (File.Exists(AssetManagerSetting.EditorUpdateAssetListPath))
            {
                updateAssetListPath = AssetManagerSetting.EditorUpdateAssetListPath;
            }
            else if (File.Exists(AssetManagerSetting.EditorFileCsvForStreaming))
            {
                updateAssetListPath = AssetManagerSetting.EditorFileCsvForStreaming;
            }

            if (!string.IsNullOrEmpty(updateAssetListPath))
            {
                AssetFileList assetFileList = AssetFileList.Read(updateAssetListPath);
                assetFileList.Add(new AssetFile("{0}/" + AssetManagerSetting.UpdateAssetListName, ""));

                int count = assetFileList.list.Count;
                for (int i = 0; i < count; i++)
                {
                    AssetFile item     = assetFileList.list[i];
                    string    path     = AssetManagerSetting.GetPlatformPath(item.path);
                    string    fromPath = AssetManagerSetting.EditorRootStream + "/" + path;
                    string    toPath   = serverRoot + "/" + path;

                    PathUtil.CheckPath(toPath);
                    File.Copy(fromPath, toPath, true);

                    if (i % 10 == 0)
                    {
                        UnityEditor.EditorUtility.DisplayProgressBar("拷贝目录", path, 1f * i / count);
                    }
                }
            }
            else
            {
                CopyAlleAsset(serverRoot);
            }

            UnityEditor.EditorUtility.ClearProgressBar();
        }
コード例 #5
0
        IEnumerator UpdateResource(string rootUrl)
        {
            // rootUrl = "http://www.ihaiu.com/StreamingAssets/"
            OnUpdateEnter();

            //获取服务器端的file.csv

            OnState("获取服务器端的file.csv");
            string updateAssetListUrl = AssetManagerSetting.GetServerFilesCsvURL(rootUrl);

            Debug.Log("UpdateAssetList URL: " + updateAssetListUrl);
            WWW www = new WWW(updateAssetListUrl);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                OnError("更新资源读取资源列表失败");
                Debug.LogErrorFormat("更新资源读取资源列表失败 updateAssetListUrl={0}, www.error={1}", updateAssetListUrl, www.error);
                www.Dispose();
                www = null;
                yield break;
            }

            AssetFileList updateAssetList = AssetFileList.Deserialize(www.text);

            www.Dispose();
            www = null;
            //Debug.Log("count: " + files.Length + " text: " + filesText);


            OnState("读取" + AssetManagerSetting.AssetFileListPath);
            if (assetList == null)
            {
                assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath);
            }

            List <AssetFile> diffs = AssetFileList.Diff(assetList, updateAssetList);

            AssetManagerSetting.persistentAssetFileList = AssetFileList.Read(AssetManagerSetting.PersistentAssetFileListPath);

            string path;
            //更新
            int count = diffs.Count;

            for (int i = 0; i < count; i++)
            {
                AssetFile item = diffs[i];
                path = AssetManagerSetting.GetPlatformPath(item.path);

                OnState("更新" + path);
                OnUpdateProgress((float)(i + 1) / (float)count);

                string url = rootUrl + path;
                www = new WWW(url);

                yield return(www);

                if (!string.IsNullOrEmpty(www.error))
                {
                    OnUpdateFailed(url);

                    www.Dispose();
                    www = null;
                    continue;
                }

                string localPath = AssetManagerSetting.RootPathPersistent + path;
                PathUtil.CheckPath(localPath, true);
                File.WriteAllBytes(localPath, www.bytes);

                www.Dispose();
                www = null;

                assetList.Add(item);

                AssetManagerSetting.persistentAssetFileList.Add(path, item.md5);
            }
            yield return(new WaitForEndOfFrame());


            assetList.Save(AssetManagerSetting.AssetFileListPath);
            AssetManagerSetting.persistentAssetFileList.Save(AssetManagerSetting.PersistentAssetFileListPath);


            // 更新完成
            OnUpdateEnd();
        }