private void AnalyzeAsset(string assetName, Asset hostAsset, DependencyData dependencyData, HashSet <string> scriptAssetNames) { string[] dependencyAssetNames = AssetDatabase.GetDependencies(assetName, false); foreach (string dependencyAssetName in dependencyAssetNames) { if (scriptAssetNames.Contains(dependencyAssetName)) { continue; } if (dependencyAssetName == assetName) { continue; } if (dependencyAssetName.EndsWith(".unity")) { // 忽略对场景的依赖 continue; } Stamp stamp = new Stamp(hostAsset.Name, dependencyAssetName); if (m_AnalyzedStamps.Contains(stamp)) { continue; } m_AnalyzedStamps.Add(stamp); string guid = AssetDatabase.AssetPathToGUID(dependencyAssetName); if (string.IsNullOrEmpty(guid)) { Debug.LogWarning(string.Format("Can not find guid by asset '{0}'.", dependencyAssetName)); continue; } Asset asset = m_ResourceCollection.GetAsset(guid); if (asset != null) { dependencyData.AddDependencyAsset(asset); } else { dependencyData.AddScatteredDependencyAsset(dependencyAssetName); List <Asset> scatteredAssets = null; if (!m_ScatteredAssets.TryGetValue(dependencyAssetName, out scatteredAssets)) { scatteredAssets = new List <Asset>(); m_ScatteredAssets.Add(dependencyAssetName, scatteredAssets); } scatteredAssets.Add(hostAsset); AnalyzeAsset(dependencyAssetName, hostAsset, dependencyData, scriptAssetNames); } } }
public DependencyData GetDependencyData(string assetName) { DependencyData dependencyData = new DependencyData(); if (m_DependencyDatas.TryGetValue(assetName, out dependencyData)) { return(dependencyData); } return(dependencyData); }
public void Analyze() { m_DependencyDatas.Clear(); m_ScatteredAssets.Clear(); m_CircularDependencyDatas.Clear(); m_AnalyzedStamps.Clear(); HashSet <string> scriptAssetNames = GetFilteredAssetNames("t:Script"); Asset[] assets = m_ResourceCollection.GetAssets(); int count = assets.Length; for (int i = 0; i < count; i++) { if (OnAnalyzingAsset != null) { OnAnalyzingAsset(i, count); } string assetName = assets[i].Name; if (string.IsNullOrEmpty(assetName)) { Debug.LogWarning(string.Format("Can not find asset by guid '{0}'.", assets[i].Guid)); continue; } DependencyData dependencyData = new DependencyData(); AnalyzeAsset(assetName, assets[i], dependencyData, scriptAssetNames); dependencyData.RefreshData(); m_DependencyDatas.Add(assetName, dependencyData); } foreach (List <Asset> scatteredAsset in m_ScatteredAssets.Values) { scatteredAsset.Sort((a, b) => a.Name.CompareTo(b.Name)); } m_CircularDependencyDatas.AddRange(new CircularDependencyChecker(m_AnalyzedStamps.ToArray()).Check()); if (OnAnalyzeCompleted != null) { OnAnalyzeCompleted(); } }