コード例 #1
0
ファイル: AssetBundleUtil.cs プロジェクト: xfilson/dn_asset
        public static void LoadCache()
        {
            string cacheTxtFilePath = GetCacheFile();

            if (File.Exists(cacheTxtFilePath))
            {
                string       value = File.ReadAllText(cacheTxtFilePath);
                StringReader sr    = new StringReader(value);

                //读取缓存的信息
                while (true)
                {
                    string path = sr.ReadLine();
                    if (path == null)
                    {
                        break;
                    }
                    AssetCacheInfo cache = new AssetCacheInfo();
                    cache.fileHash  = sr.ReadLine();
                    cache.metaHash  = sr.ReadLine();
                    cache.bundleCrc = sr.ReadLine();
                    int depsCount = Convert.ToInt32(sr.ReadLine());
                    cache.depNames = new string[depsCount];
                    for (int i = 0; i < depsCount; i++)
                    {
                        cache.depNames[i] = sr.ReadLine();
                    }
                    _fileHashOld[path] = cache;
                    sr.ReadLine();//分隔符 ***************************
                }
            }
        }
コード例 #2
0
ファイル: AssetTarget.cs プロジェクト: xfilson/dn_asset
        public void Analyze()
        {
            if (_isAnalyzed)
            {
                return;
            }
            _isAnalyzed    = true;
            _cacheInfo     = AssetBundleUtil.GetCacheInfo(assetPath);
            _isFileChanged = _cacheInfo == null || !_cacheInfo.fileHash.Equals(GetHash()) || !_cacheInfo.metaHash.Equals(_metaHash);
            if (_cacheInfo != null)
            {
                _bundleCrc = _cacheInfo.bundleCrc;
                if (_isFileChanged)
                {
                    XDebug.Log("File was changed : ", assetPath);
                }
            }

            Object[] deps = EditorUtility.CollectDependencies(new Object[] { asset });
            var      res  = from s in deps
                            let path = AssetDatabase.GetAssetPath(s)
                                       where !path.StartsWith("Assets/Resources") && !(s is MonoScript)
                                       select path;

            var paths = res.Distinct().ToArray();

            for (int i = 0; i < paths.Length; i++)
            {
                if (!File.Exists(paths[i]) && !paths[i].Contains("unity_builtin_extra"))
                {
                    XDebug.Log("invalid:", paths[i]);
                    continue;
                }
                FileInfo    fi     = new FileInfo(paths[i]);
                AssetTarget target = AssetBundleUtil.Load(fi);
                if (target == null)
                {
                    continue;
                }

                AddDepend(target);
                target.Analyze();
            }
        }