private void PostProcessScene(Scene scene, string reliableScenePath, Dictionary <int, string> preexistingPrefabInstances) { Log.Debug("Processing scene: {0} ({1})", scene.name, scene.path); if (!buildTimer.IsRunning) { buildTimer.Start(); BuildInfoSettings.ReportToOpen = null; } if (BuildInfoSettings.Instance.collectAssetsDetails && detailsCollector == null) { bool checkCompressedSize = false; if (UnityVersionAgnostic.IsGetRawTextureDataSupported) { checkCompressedSize = BuildInfoSettings.Instance.checkAssetsCompressedSize; } detailsCollector = new BuildInfoAssetDetailsCollector(checkCompressedSize); } try { toolOverheadTimer.Start(); var sceneIndex = processedScenes.Count; if (processedScenesNonAltered.Contains(scene.path)) { Log.Debug("Scene {0} already processed, ignoring", scene.path); } else { AssetProperty[] details; CollectUsedAssets(scene, reliableScenePath, assetsUsedByScenes, preexistingPrefabInstances, detailsCollector, out details); processedScenes.Add(reliableScenePath); scenesDetails.Add(details); processedScenesNonAltered.Add(scene.path); } } finally { toolOverheadTimer.Stop(); } }
private static void CollectUsedAssets(Scene scene, string sceneName, Dictionary <string, AssetInfo> assets, Dictionary <int, string> preexistingPrefabInstances, BuildInfoAssetDetailsCollector collector, out AssetProperty[] sceneDetails) { List <AssetProperty> details = new List <AssetProperty>(); Func <string, UnityEngine.Object, AssetInfo> touchEntry = (assetPath, asset) => { AssetInfo entry; if (!assets.TryGetValue(assetPath, out entry)) { entry = new AssetInfo() { path = assetPath, }; assets.Add(assetPath, entry); } if (collector != null && entry.details == null) { bool isMainAsset = true; if (!AssetDatabase.IsMainAsset(asset) && !string.IsNullOrEmpty(AssetDatabase.GetAssetPath(asset))) { isMainAsset = false; } if (isMainAsset) { details.Clear(); Log.Debug("Collecting details for asset: {0}", assetPath); collector.CollectForAsset(details, asset, assetPath); entry.details = details.ToArray(); } else { Log.Debug("Not a main asset: {0} {1}", asset.name, AssetDatabase.GetAssetPath(asset)); } } if (!string.IsNullOrEmpty(sceneName)) { int sceneIndex = entry.scenes.BinarySearch(sceneName); if (sceneIndex < 0) { entry.scenes.Insert(~sceneIndex, sceneName); } } return(entry); }; var legacySpriteHandler = UnityVersionAgnostic.IsUsingLegacySpriteAtlases ? BuildInfoProcessorUtils.CreateLegacyAtlasHandler(touchEntry) : null; // include inactive ones too var sceneRoots = scene.GetRootGameObjects(); sceneDetails = null; if (collector != null) { Log.Debug("Collecting scene details: {0}", sceneName); sceneDetails = collector.CollectForCurrentScene(sceneRoots); } Log.Debug("Processing scene objects for scene: {0}", sceneName); IEnumerable <UnityEngine.Object> objects = EditorUtility.CollectDependencies(sceneRoots).Where(x => x); foreach (var obj in objects) { string assetPath; var dep = obj; if (!EditorUtility.IsPersistent(dep)) { if (dep is GameObject) { // hopefully this will work some day :( // if (PrefabUtility.GetPrefabInstanceStatus(dep) == PrefabInstanceStatus.Connected) // { // // assetPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(dep); // } if (preexistingPrefabInstances != null) { // well, let's see if the workaround worked preexistingPrefabInstances.TryGetValue(dep.GetInstanceID(), out assetPath); } else { assetPath = null; } if (string.IsNullOrEmpty(assetPath)) { continue; } dep = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath); if (dep == null) { continue; } } else { continue; } } else { assetPath = AssetDatabase.GetAssetPath(dep); } if (string.IsNullOrEmpty(assetPath)) { Log.Debug(dep, "empty path: name: {0}, scene: {1}", dep.name, sceneName); continue; } touchEntry(assetPath, dep); if (legacySpriteHandler != null && dep is UnitySprite) { legacySpriteHandler((UnitySprite)dep, assetPath); } } // add lightmaps Log.Debug("Processing lightmaps for scene: {0}", sceneName); foreach (var data in UnityEngine.LightmapSettings.lightmaps) { if (data.GetDirectional()) { touchEntry(AssetDatabase.GetAssetPath(data.GetDirectional()), data.GetDirectional()); } if (data.GetLight()) { touchEntry(AssetDatabase.GetAssetPath(data.GetLight()), data.GetLight()); } } // now check lightmap settings var lightmapSettings = BuildInfoProcessorUtils.GetLightmapSettings(); for (var prop = new SerializedObject(lightmapSettings).GetIterator(); prop.Next(true);) { if (prop.propertyType == SerializedPropertyType.ObjectReference) { var obj = prop.objectReferenceValue; if (obj && EditorUtility.IsPersistent(obj)) { string path = AssetDatabase.GetAssetPath(obj); touchEntry(path, obj); } } } }