コード例 #1
0
        private bool AssignLoaderToSettings(AdaptivePerformanceManagerSettings settings, string loaderTypeName, BuildTargetGroup buildTargetGroup = BuildTargetGroup.Standalone)
        {
            if (String.IsNullOrEmpty(loaderTypeName))
            {
                return(false);
            }

            return(AdaptivePerformancePackageMetadataStore.AssignLoader(m_Settings, loaderTypeName, buildTargetGroup));
        }
コード例 #2
0
        private bool SettingsHasLoaderOfType(AdaptivePerformanceManagerSettings settings, string loaderTypeName)
        {
            bool wasFound = false;

            foreach (var l in m_Settings.loaders)
            {
                if (String.Compare(l.GetType().FullName, loaderTypeName) == 0)
                {
                    wasFound = true;
                }
            }
            return(wasFound);
        }
        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(AdaptivePerformanceManagerSettings settings, string loaderTypeName)
        {
            if (settings == null)
            {
                return(false);
            }

            foreach (var l in settings.loaders)
            {
                if (l != null && String.Compare(l.GetType().FullName, loaderTypeName) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #5
0
        public void SetupAdaptivePerformanceManagerTest()
        {
            m_Manager = ScriptableObject.CreateInstance <AdaptivePerformanceManagerSettings>();
            m_Manager.automaticLoading = false;

            m_Loaders = new List <AdaptivePerformanceLoader>();

            for (int i = 0; i < m_LoaderCount; i++)
            {
                DummyLoader dl = ScriptableObject.CreateInstance(typeof(DummyLoader)) as DummyLoader;
                dl.id         = i;
                dl.shouldFail = (i != m_LoaderIndexToWin);
                m_Loaders.Add(dl);
                m_Manager.loaders.Add(dl);
            }
        }
コード例 #6
0
        public void TestLoaderAssignmentSerializes()
        {
            Assert.IsNotNull(m_Settings);
            string loaderTypeName = LoaderTypeNameForBuildTarget(BuildTargetGroup.Standalone);

            Assert.IsFalse(String.IsNullOrEmpty(loaderTypeName));
            AssignLoaderToSettings(m_Settings, loaderTypeName);
            Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName));

            m_Settings = null;
            var settings = EditorUtilities.GetInstanceOfTypeFromAssetDatabase <AdaptivePerformanceManagerSettings>();

            m_Settings = settings as AdaptivePerformanceManagerSettings;
            Assert.IsNotNull(m_Settings);

            Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName));
            Assert.IsTrue(TestLoaderBase.WasAssigned);
        }
        /// <summary>
        /// Assigns a loader of type loaderTypeName to the settings instance. Will instantiate an
        /// instance if one can't be found in the user's project folder before assigning it.
        /// </summary>
        /// <param name="settings">An instance of <see cref="AdaptivePerformanceManagerSettings"/> to add the loader to.</param>
        /// <param name="loaderTypeName">The full type name for the loader instance to assign to settings.</param>
        /// <param name="buildTargetGroup">The build target group being assigned to.</param>
        /// <returns>True if assignment succeeds, false if not.</returns>
        public static bool AssignLoader(AdaptivePerformanceManagerSettings settings, string loaderTypeName, BuildTargetGroup buildTargetGroup)
        {
            var instance = EditorUtilities.GetInstanceOfTypeWithNameFromAssetDatabase(loaderTypeName);

            if (instance == null || !(instance is AdaptivePerformanceLoader))
            {
                instance = EditorUtilities.CreateScriptableObjectInstance(loaderTypeName,
                                                                          EditorUtilities.GetAssetPathForComponents(EditorUtilities.s_DefaultLoaderPath));
                if (instance == null)
                {
                    return(false);
                }
            }

            var assignedLoaders = settings.loaders;
            AdaptivePerformanceLoader newLoader = instance as AdaptivePerformanceLoader;

            if (!assignedLoaders.Contains(newLoader))
            {
                assignedLoaders.Add(newLoader);
                settings.loaders = new List <AdaptivePerformanceLoader>();

                var allLoaders = GetAllLoadersForBuildTarget(buildTargetGroup);

                foreach (var ldr in allLoaders)
                {
                    var newInstance = EditorUtilities.GetInstanceOfTypeWithNameFromAssetDatabase(ldr.loaderType) as AdaptivePerformanceLoader;

                    if (newInstance != null && assignedLoaders.Contains(newInstance))
                    {
                        settings.loaders.Add(newInstance);
#if UNITY_EDITOR
                        var loaderHelper = newLoader as AdaptivePerformanceLoaderHelper;
                        loaderHelper?.WasAssignedToBuildTarget(buildTargetGroup);
#endif
                    }
                }

                EditorUtility.SetDirty(settings);
                AssetDatabase.SaveAssets();
            }

            return(true);
        }
コード例 #8
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;
        }
        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"));
        }
        /// <summary>
        /// Remove a previously assigned loader from settings. If the loader type is unknown or
        /// an instance of the loader can't be found in the project folder, no action is taken.
        ///
        /// Removal will not delete the instance from the project folder.
        /// </summary>
        /// <param name="settings">An instance of <see cref="AdaptivePerformanceManagerSettings"/> to add the loader to.</param>
        /// <param name="loaderTypeName">The full type name for the loader instance to remove from settings.</param>
        /// <param name="buildTargetGroup">The build target group being removed from.</param>
        /// <returns>True if removal succeeds, false if not.</returns>
        public static bool RemoveLoader(AdaptivePerformanceManagerSettings settings, string loaderTypeName, BuildTargetGroup buildTargetGroup)
        {
            var instance = EditorUtilities.GetInstanceOfTypeWithNameFromAssetDatabase(loaderTypeName);

            if (instance == null || !(instance is AdaptivePerformanceLoader))
            {
                return(false);
            }

            AdaptivePerformanceLoader loader = instance as AdaptivePerformanceLoader;

            if (settings.loaders.Contains(loader))
            {
                settings.loaders.Remove(loader);
                EditorUtility.SetDirty(settings);
                AssetDatabase.SaveAssets();
#if UNITY_EDITOR
                var loaderHelper = loader as AdaptivePerformanceLoaderHelper;
                loaderHelper?.WasUnassignedFromBuildTarget(buildTargetGroup);
#endif
            }

            return(true);
        }
コード例 #11
0
 public void TeardownAdaptivePerformanceManagerTest()
 {
     Object.Destroy(m_Manager);
     m_Manager = null;
 }