private static void ValidateInstantiationNoClone(Scene newScene, string expectedPath) { EditorSceneManager.SaveScene(newScene, expectedPath); AssetDatabase.Refresh(); var dependencies = new List <Object>(); ReferenceUtils.GetSceneDependencies(expectedPath, dependencies); var expectedDependencies = new List <string>(); foreach (var dep in TestUtils.k_NoCloneReferences) { expectedDependencies.Add(dep); } var dependencyPaths = GetDependencyPaths(dependencies); foreach (var expectedDep in expectedDependencies) { Assert.IsTrue(dependencyPaths.Contains(expectedDep), $"{expectedDep} is not found in dependencies"); } Assert.AreEqual(expectedDependencies.Count, dependencies.Count); }
public void TestGetSceneDependencies() { var assetPaths = TestUtils.k_TestSceneDependenciesClonable.Concat(TestUtils.k_TestSceneDependenciesReference); var assets = new List <Object>(); // Load all assets foreach (var assetPath in assetPaths) { var type = AssetDatabase.GetMainAssetTypeAtPath(assetPath); var obj = AssetDatabase.LoadAssetAtPath(assetPath, type); Assert.NotNull(obj, "Asset should not be null"); assets.Add(obj); } // Get scene dependencies var dependencies = new List <Object>(); ReferenceUtils.GetSceneDependencies(TestUtils.k_TestSceneDependenciesScene, dependencies); var missingAssets = new List <Object>(); var extraDependencies = new List <Object>(); foreach (var asset in assets) { var foundAsset = dependencies.Find(obj => obj.GetInstanceID() == asset.GetInstanceID()); if (foundAsset == null) { missingAssets.Add(asset); } } Assert.IsEmpty(missingAssets, $"Some assets were not found through the dependencies: {missingAssets.Select(obj => obj.name)}"); foreach (var dependency in dependencies) { var foundAsset = assets.Find(obj => obj.GetInstanceID() == dependency.GetInstanceID()); if (foundAsset == null) { extraDependencies.Add(dependency); } } var extraDeps = string.Join(",", extraDependencies.Select(dep => AssetDatabase.GetAssetPath(dep))); Assert.IsEmpty(extraDependencies, $"Found extra dependencies: {extraDeps}"); }
private static void ValidateInstantiation(string newScenePath, Object newSceneAsset, IEnumerable <string> clonedAssetPaths, IEnumerable <string> referencedAssetPaths) { Assert.NotNull(newSceneAsset, "newSceneAsset"); var validateScenePath = AssetDatabase.GetAssetPath(newSceneAsset); Assert.AreEqual(validateScenePath, newScenePath, "newSceneAsset"); // Check for Cloned asset directory existence: var cloneAssetDirectoryName = Path.GetFileNameWithoutExtension(newScenePath); var newSceneDirectory = Path.GetDirectoryName(newScenePath).Replace("\\", "/"); var clonedAssetDirectory = Path.Combine(newSceneDirectory, cloneAssetDirectoryName).Replace("\\", "/"); Assert.IsTrue(Directory.Exists(clonedAssetDirectory), $"Cloned asset directory {clonedAssetDirectory} doesn't exists"); var expectedDependencyPaths = new HashSet <string>(); foreach (var cloneableDep in clonedAssetPaths) { var depName = Path.GetFileName(cloneableDep); expectedDependencyPaths.Add(Path.Combine(clonedAssetDirectory, depName).Replace("\\", "/")); } foreach (var path in expectedDependencyPaths) { Assert.IsTrue(File.Exists(path), $"Expected ClonedAsset asset {path} doesn't exists"); } var clonedDependencies = new List <Object>(); ReferenceUtils.GetSceneDependencies(newScenePath, clonedDependencies); Assert.AreEqual(clonedAssetPaths.Count() + referencedAssetPaths.Count(), clonedDependencies.Count, "Nb of dependencies"); var clonedDependencyPaths = GetDependencyPaths(clonedDependencies); foreach (var expectedDep in expectedDependencyPaths) { Assert.IsTrue(clonedDependencyPaths.Contains(expectedDep), $"Expected ClonedAsset asset {expectedDep} doesn't exists"); } }