public void VerifyGetAssetDatabasePath() { // File in the Assets folder structure string inputPath = @"c:\projects\MyUnityProject\Assets\materials\test.mat"; string expectedPath = "Assets/materials/test.mat"; string actualPath = MixedRealityToolkitFiles.GetAssetDatabasePath(inputPath); Assert.AreEqual(expectedPath, actualPath); // File in the Packages folder structure inputPath = "d:/source/projects/Packages/CoolFeature/textures/background.png"; expectedPath = "Packages/CoolFeature/textures/background.png"; actualPath = MixedRealityToolkitFiles.GetAssetDatabasePath(inputPath); Assert.AreEqual(expectedPath, actualPath); // File in the Library/PackageCache folder structure inputPath = @"c:\development\projects\space\Library\PackageCache\[email protected]\scriptable.asset"; expectedPath = "Packages/com.contoso.custompackage/scriptable.asset"; actualPath = MixedRealityToolkitFiles.GetAssetDatabasePath(inputPath); Assert.AreEqual(expectedPath, actualPath); // Edge cases inputPath = @"c:\projects\AssetsViewer\Assets\materials\test.mat"; expectedPath = "Assets/materials/test.mat"; actualPath = MixedRealityToolkitFiles.GetAssetDatabasePath(inputPath); Assert.AreEqual(expectedPath, actualPath); inputPath = "d:/source/projects/Packages/CoolFeature/MyAssets/textures/background.png"; expectedPath = "Packages/CoolFeature/MyAssets/textures/background.png"; actualPath = MixedRealityToolkitFiles.GetAssetDatabasePath(inputPath); Assert.AreEqual(expectedPath, actualPath); inputPath = @"c:\development\projects\space\Library\PackageCache\[email protected]\Core\StandardAssets\Textures\MRTK_Logo_Black.png"; expectedPath = "Packages/com.microsoft.mixedreality.toolkit.foundation/Core/StandardAssets/Textures/MRTK_Logo_Black.png"; actualPath = MixedRealityToolkitFiles.GetAssetDatabasePath(inputPath); Assert.AreEqual(expectedPath, actualPath); inputPath = @"c:\projects\AssetsViewer\Assets\StandardAssets\materials\test.mat"; expectedPath = "Assets/StandardAssets/materials/test.mat"; actualPath = MixedRealityToolkitFiles.GetAssetDatabasePath(inputPath); Assert.AreEqual(expectedPath, actualPath); }
private static void UpdateTestScriptIcons() { Texture2D icon = null; foreach (string iconPath in MixedRealityToolkitFiles.GetFiles(MixedRealityToolkitModuleType.StandardAssets, "Icons")) { if (iconPath.EndsWith("test_icon.png")) { icon = AssetDatabase.LoadAssetAtPath <Texture2D>(iconPath); break; } } if (icon == null) { Debug.Log("Couldn't find test icon."); return; } IEnumerable <string> testDirectories = MixedRealityToolkitFiles.GetDirectories(MixedRealityToolkitModuleType.Tests); foreach (string directory in testDirectories) { string[] scriptGuids = AssetDatabase.FindAssets("t:MonoScript", new string[] { MixedRealityToolkitFiles.GetAssetDatabasePath(directory) }); for (int i = 0; i < scriptGuids.Length; i++) { string scriptPath = AssetDatabase.GUIDToAssetPath(scriptGuids[i]); EditorUtility.DisplayProgressBar("Updating Icons...", $"{i} of {scriptGuids.Length} {scriptPath}", i / (float)scriptGuids.Length); MonoScript script = AssetDatabase.LoadAssetAtPath <MonoScript>(scriptPath); Texture2D currentIcon = getIconForObject?.Invoke(null, new object[] { script }) as Texture2D; if (currentIcon == null || !currentIcon.Equals(icon)) { setIconForObject?.Invoke(null, new object[] { script, icon }); copyMonoScriptIconToImporters?.Invoke(null, new object[] { script }); } } } EditorUtility.ClearProgressBar(); }