public static void SetupTest()
        {
            testManager = ScriptableObject.CreateInstance <AdaptivePerformanceManagerSettings>();

            adaptivePerformanceGeneralSettings         = ScriptableObject.CreateInstance <AdaptivePerformanceGeneralSettings>() as AdaptivePerformanceGeneralSettings;
            adaptivePerformanceGeneralSettings.Manager = testManager;


            testPathToSettings = GetAssetPathForComponents(s_TempSettingsPath);
            testPathToSettings = Path.Combine(testPathToSettings, $"Test_{ typeof(AdaptivePerformanceGeneralSettings).Name}.asset");
            if (!string.IsNullOrEmpty(testPathToSettings))
            {
                AssetDatabase.CreateAsset(adaptivePerformanceGeneralSettings, testPathToSettings);
                AssetDatabase.AddObjectToAsset(testManager, adaptivePerformanceGeneralSettings);

                AssetDatabase.SaveAssets();
            }

            testPathToGeneralSettings = GetAssetPathForComponents(s_TestGeneralSettings);
            testPathToGeneralSettings = Path.Combine(testPathToGeneralSettings, $"Test_{typeof(AdaptivePerformanceGeneralSettingsPerBuildTarget).Name}.asset");

            buildTargetSettings = ScriptableObject.CreateInstance <AdaptivePerformanceGeneralSettingsPerBuildTarget>();
            buildTargetSettings.SetSettingsForBuildTarget(BuildTargetGroup.Standalone, adaptivePerformanceGeneralSettings);
            if (!string.IsNullOrEmpty(testPathToSettings))
            {
                AssetDatabase.CreateAsset(buildTargetSettings, testPathToGeneralSettings);
                AssetDatabase.SaveAssets();

                EditorBuildSettings.TryGetConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, out currentSettings);
                EditorBuildSettings.AddConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, buildTargetSettings, true);
            }

            testPathToLoader = GetAssetPathForComponents(s_TempSettingsPath);
            // Setup Loader
            loader = ScriptableObject.CreateInstance(typeof(SimulatorProviderLoader)) as SimulatorProviderLoader;
            AssetDatabase.CreateAsset(loader, Path.Combine(testPathToLoader, $"Test_{typeof(SimulatorProviderLoader).Name}.asset"));
            testManager.loaders.Add(loader);

            // Setup Settings
            settings = ScriptableObject.CreateInstance(typeof(SimulatorProviderSettings)) as SimulatorProviderSettings;
            AssetDatabase.CreateAsset(settings, Path.Combine(testPathToLoader, $"Test_{typeof(SimulatorProviderSettings).Name}.asset"));
            //settings.logging = false;
            EditorBuildSettings.AddConfigObject(SimulatorProviderConstants.k_SettingsKey, settings, true);


            // Due to the Settings menu, we have to manually assigned the Simulator loader in tests.
            AdaptivePerformancePackageMetadataStore.AssignLoader(AdaptivePerformanceGeneralSettings.Instance.Manager, typeof(SimulatorProviderLoader).Name, BuildTargetGroup.Standalone);
        }
        internal static bool IsLoaderAssigned(string loaderTypeName, BuildTargetGroup buildTargetGroup)
        {
            var settings = AdaptivePerformanceGeneralSettingsPerBuildTarget.AdaptivePerformanceGeneralSettingsForBuildTarget(buildTargetGroup);

            if (settings == null)
            {
                return(false);
            }

            foreach (var loader in settings.AssignedSettings.loaders)
            {
                if (loader != null && String.Compare(loader.GetType().FullName, loaderTypeName) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            AssetDatabase.DeleteAsset("Assets/Adaptive Performance");

            AssetDatabase.CreateFolder("Assets", "Adaptive Performance");

            m_Settings      = ScriptableObject.CreateInstance <AdaptivePerformanceManagerSettings>() as AdaptivePerformanceManagerSettings;
            m_Settings.name = "Actual testable settings.";

            m_TestSettings         = ScriptableObject.CreateInstance <AdaptivePerformanceGeneralSettings>() as AdaptivePerformanceGeneralSettings;
            m_TestSettings.Manager = m_Settings;
            m_TestSettings.name    = "Standalone Settings Container.";

            m_TestSettingsPerBuildTarget = ScriptableObject.CreateInstance <AdaptivePerformanceGeneralSettingsPerBuildTarget>() as AdaptivePerformanceGeneralSettingsPerBuildTarget;
            m_TestSettingsPerBuildTarget.SetSettingsForBuildTarget(BuildTargetGroup.Standalone, m_TestSettings);

            var testPath = AdaptivePerformanceGeneralSettingsTests.GetAssetPathForComponents(s_TempSettingsPath);

            if (!string.IsNullOrEmpty(testPath))
            {
                AssetDatabase.CreateAsset(m_TestSettingsPerBuildTarget, Path.Combine(testPath, "Test_AdaptivePerformanceGeneralSettings.asset"));

                AssetDatabase.AddObjectToAsset(m_TestSettings, AssetDatabase.GetAssetOrScenePath(m_TestSettingsPerBuildTarget));

                AssetDatabase.CreateFolder(testPath, "Settings");
                testPath = Path.Combine(testPath, "Settings");
                AssetDatabase.CreateAsset(m_Settings, Path.Combine(testPath, "Test_AdaptivePerformanceSettingsManager.asset"));

                m_TestSettings.AssignedSettings = m_Settings;
                AssetDatabase.SaveAssets();
            }

            EditorBuildSettings.AddConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, m_TestSettingsPerBuildTarget, true);

            AdaptivePerformancePackageInitializationBootstrap.BeginPackageInitialization();

            TestPackage.Editor.TestPackage pkg = new TestPackage.Editor.TestPackage();
            AdaptivePerformancePackageMetadataStore.AddPluginPackage(pkg);
            AdaptivePerformancePackageInitializationBootstrap.InitPackage(pkg);

            TestLoaderBase.WasAssigned   = false;
            TestLoaderBase.WasUnassigned = false;
        }
        static void AssignAnyRequestedLoadersUpdate()
        {
            EditorApplication.update -= AssignAnyRequestedLoadersUpdate;

            LoaderAssignmentRequests reqs = GetAllRequestsInQueue(k_AssigningPackage);

            if (reqs.activeRequests == null || reqs.activeRequests.Count == 0)
            {
                return;
            }

            while (reqs.activeRequests.Count > 0)
            {
                var req = reqs.activeRequests[0];
                reqs.activeRequests.RemoveAt(0);

                var settings = AdaptivePerformanceGeneralSettingsPerBuildTarget.AdaptivePerformanceGeneralSettingsForBuildTarget(req.buildTargetGroup);

                if (settings == null)
                {
                    continue;
                }

                if (settings.AssignedSettings == null)
                {
                    var assignedSettings = ScriptableObject.CreateInstance <AdaptivePerformanceManagerSettings>() as AdaptivePerformanceManagerSettings;
                    settings.AssignedSettings = assignedSettings;
                    EditorUtility.SetDirty(settings);
                }

                if (!AdaptivePerformancePackageMetadataStore.AssignLoader(settings.AssignedSettings, req.loaderType, req.buildTargetGroup))
                {
                    req.installationState = InstallationState.Log;
                    req.logMessage        = $"Unable to assign {req.packageId} for build target {req.buildTargetGroup}.";
                    req.logLevel          = LogLevel.Error;
                    QueueLoaderRequest(req);
                }
            }

            ResetManagerUiIfAvailable();
        }
        public virtual void TearDownTest()
        {
            adaptivePerformanceGeneralSettings.Manager.loaders.Remove(loader);
            loader = null;

            EditorBuildSettings.RemoveConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey);

            if (!string.IsNullOrEmpty(testPathToGeneralSettings))
            {
                AssetDatabase.DeleteAsset(testPathToGeneralSettings);
            }

            if (!string.IsNullOrEmpty(testPathToSettings))
            {
                AssetDatabase.DeleteAsset(testPathToSettings);
            }

            adaptivePerformanceGeneralSettings.Manager = null;
            UnityEngine.Object.DestroyImmediate(adaptivePerformanceGeneralSettings);
            adaptivePerformanceGeneralSettings = null;

            UnityEngine.Object.DestroyImmediate(testManager);
            testManager = null;

            UnityEngine.Object.DestroyImmediate(buildTargetSettings);
            buildTargetSettings = null;

            if (currentSettings != null)
            {
                EditorBuildSettings.AddConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, currentSettings, true);
            }
            else
            {
                EditorBuildSettings.RemoveConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey);
            }

            AssetDatabase.DeleteAsset(Path.Combine("Assets", "Temp"));
        }