暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EditorTests.cs 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using NUnit.Framework;
  2. using System;
  3. using System.IO;
  4. using UnityEngine;
  5. using UnityEngine.AdaptivePerformance;
  6. namespace UnityEditor.AdaptivePerformance.Editor.Tests
  7. {
  8. class AdaptivePerformanceGeneralSettingsTests
  9. {
  10. internal static readonly string[] s_TempSettingsPath = {"Temp", "Test", "Settings"};
  11. string testPathToSettings;
  12. UnityEngine.Object currentSettings = null;
  13. AdaptivePerformanceManagerSettings testManager = null;
  14. AdaptivePerformanceGeneralSettings testSettings = null;
  15. [SetUp]
  16. public void SetupTest()
  17. {
  18. testManager = ScriptableObject.CreateInstance<AdaptivePerformanceManagerSettings>();
  19. testSettings = ScriptableObject.CreateInstance<AdaptivePerformanceGeneralSettings>() as AdaptivePerformanceGeneralSettings;
  20. testSettings.Manager = testManager;
  21. testPathToSettings = AdaptivePerformanceGeneralSettingsTests.GetAssetPathForComponents(AdaptivePerformanceGeneralSettingsTests.s_TempSettingsPath);
  22. if (!string.IsNullOrEmpty(testPathToSettings))
  23. {
  24. testPathToSettings = Path.Combine(testPathToSettings, "Test_AdaptivePerformanceGeneralSettings.asset");
  25. AssetDatabase.CreateAsset(testSettings, testPathToSettings);
  26. AssetDatabase.SaveAssets();
  27. }
  28. EditorBuildSettings.TryGetConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, out currentSettings);
  29. EditorBuildSettings.AddConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, testSettings, true);
  30. }
  31. [TearDown]
  32. public void TearDownTest()
  33. {
  34. EditorBuildSettings.RemoveConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey);
  35. if (!string.IsNullOrEmpty(testPathToSettings))
  36. {
  37. AssetDatabase.DeleteAsset(testPathToSettings);
  38. }
  39. testSettings.Manager = null;
  40. UnityEngine.Object.DestroyImmediate(testSettings);
  41. testSettings = null;
  42. UnityEngine.Object.DestroyImmediate(testManager);
  43. testManager = null;
  44. if (currentSettings != null)
  45. EditorBuildSettings.AddConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, currentSettings, true);
  46. AssetDatabase.DeleteAsset(Path.Combine("Assets", "Temp"));
  47. }
  48. internal static string GetAssetPathForComponents(string[] pathComponents, string root = "Assets")
  49. {
  50. if (pathComponents.Length <= 0)
  51. return null;
  52. string path = root;
  53. foreach (var pc in pathComponents)
  54. {
  55. string subFolder = Path.Combine(path, pc);
  56. bool shouldCreate = true;
  57. foreach (var f in AssetDatabase.GetSubFolders(path))
  58. {
  59. if (String.Compare(Path.GetFullPath(f), Path.GetFullPath(subFolder), true) == 0)
  60. {
  61. shouldCreate = false;
  62. break;
  63. }
  64. }
  65. if (shouldCreate)
  66. AssetDatabase.CreateFolder(path, pc);
  67. path = subFolder;
  68. }
  69. return path;
  70. }
  71. }
  72. }