/// <summary>Get specific settings for a given build target.</summary>
        /// <param name="targetGroup">An enum that specifies which platform group this build is for.</param>
        /// <returns>The instance of <see cref="AdaptivePerformanceGeneralSettings"/> assigned to the key, or null if no instance is assigned.</returns>
        public AdaptivePerformanceGeneralSettings SettingsForBuildTarget(BuildTargetGroup targetGroup)
        {
            AdaptivePerformanceGeneralSettings ret = null;

            Settings.TryGetValue(targetGroup, out ret);
            return(ret);
        }
        public void OnPreprocessBuild(BuildReport report)
        {
            CheckInstalledProvider();

            // Always remember to clean up preloaded assets after build to make sure we don't
            // dirty later builds with assets that may not be needed or are out of date.
            CleanOldSettings();

            AdaptivePerformanceGeneralSettingsPerBuildTarget buildTargetSettings = null;

            EditorBuildSettings.TryGetConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, out buildTargetSettings);
            if (buildTargetSettings == null)
            {
                return;
            }

            AdaptivePerformanceGeneralSettings settings = buildTargetSettings.SettingsForBuildTarget(report.summary.platformGroup);

            if (settings == null)
            {
                return;
            }

            UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();

            if (!preloadedAssets.Contains(settings))
            {
                var assets = preloadedAssets.ToList();
                assets.Add(settings);
                PlayerSettings.SetPreloadedAssets(assets.ToArray());
            }
        }
 /// <summary>
 /// Set specific settings for a given build target.
 /// </summary>
 /// <param name="targetGroup">An enum that specifies which platform group this build is for.</param>
 /// <param name="settings">An instance of <see cref="AdaptivePerformanceGeneralSettings"/> to assign for the given key.</param>
 public void SetSettingsForBuildTarget(BuildTargetGroup targetGroup, AdaptivePerformanceGeneralSettings settings)
 {
     // Ensures the editor's "runtime instance" is the most current for standalone settings
     if (targetGroup == BuildTargetGroup.Standalone)
     {
         AdaptivePerformanceGeneralSettings.Instance = settings;
     }
     Settings[targetGroup] = settings;
 }
        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);
        }
        static void PlayModeStateChanged(PlayModeStateChange state)
        {
            AdaptivePerformanceGeneralSettingsPerBuildTarget buildTargetSettings = null;

            EditorBuildSettings.TryGetConfigObject(AdaptivePerformanceGeneralSettings.k_SettingsKey, out buildTargetSettings);
            if (buildTargetSettings == null)
            {
                return;
            }

            AdaptivePerformanceGeneralSettings instance = buildTargetSettings.SettingsForBuildTarget(BuildTargetGroup.Standalone);

            if (instance == null || !instance.InitManagerOnStart)
            {
                return;
            }

            instance.InternalPlayModeStateChanged(state);
        }
Exemple #6
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"));
        }
Exemple #8
0
        private void DisplayLoaderSelectionUI()
        {
            BuildTargetGroup buildTargetGroup = EditorGUILayout.BeginBuildTargetSelectionGrouping();

            try
            {
                bool buildTargetChanged = m_LastBuildTargetGroup != buildTargetGroup;
                if (buildTargetChanged)
                {
                    m_LastBuildTargetGroup = buildTargetGroup;
                }

                AdaptivePerformanceGeneralSettings settings = currentSettings.SettingsForBuildTarget(buildTargetGroup);
                if (settings == null)
                {
                    settings           = ScriptableObject.CreateInstance <AdaptivePerformanceGeneralSettings>() as AdaptivePerformanceGeneralSettings;
                    settings.hideFlags = HideFlags.HideInInspector;
                    currentSettings.SetSettingsForBuildTarget(buildTargetGroup, settings);
                    settings.name = $"{buildTargetGroup.ToString()} Settings";
                    AssetDatabase.AddObjectToAsset(settings, AssetDatabase.GetAssetOrScenePath(currentSettings));
                }

                var serializedSettingsObject = new SerializedObject(settings);
                serializedSettingsObject.Update();

                EditorGUILayout.LabelField($"Settings for {buildTargetGroup}", EditorStyles.boldLabel);

                SerializedProperty initOnStart = serializedSettingsObject.FindProperty("m_InitManagerOnStart");
                EditorGUIUtility.labelWidth = 260;
                EditorGUILayout.PropertyField(initOnStart, Content.k_InitializeOnStart);
                EditorGUILayout.Space();

                SerializedProperty loaderProp = serializedSettingsObject.FindProperty("m_LoaderManagerInstance");

                if (!CachedSettingsEditor.ContainsKey(buildTargetGroup))
                {
                    CachedSettingsEditor.Add(buildTargetGroup, null);
                }

                if (loaderProp.objectReferenceValue == null)
                {
                    var adaptivePerformanceManagerSettings = ScriptableObject.CreateInstance <AdaptivePerformanceManagerSettings>() as AdaptivePerformanceManagerSettings;
                    adaptivePerformanceManagerSettings.hideFlags = HideFlags.HideInInspector;
                    adaptivePerformanceManagerSettings.name      = $"{buildTargetGroup.ToString()} Providers";
                    AssetDatabase.AddObjectToAsset(adaptivePerformanceManagerSettings, AssetDatabase.GetAssetOrScenePath(currentSettings));
                    loaderProp.objectReferenceValue = adaptivePerformanceManagerSettings;
                    serializedSettingsObject.ApplyModifiedProperties();
                }

                var obj = loaderProp.objectReferenceValue;

                if (obj != null)
                {
                    loaderProp.objectReferenceValue = obj;

                    if (CachedSettingsEditor[buildTargetGroup] == null)
                    {
                        CachedSettingsEditor[buildTargetGroup] = UnityEditor.Editor.CreateEditor(obj) as AdaptivePerformanceManagerSettingsEditor;

                        if (CachedSettingsEditor[buildTargetGroup] == null)
                        {
                            Debug.LogError("Failed to create a view for Adaptive Performance Manager Settings Instance");
                        }
                    }

                    if (CachedSettingsEditor[buildTargetGroup] != null)
                    {
                        if (ResetUi)
                        {
                            ResetUi = false;
                            CachedSettingsEditor[buildTargetGroup].Reload();
                        }

                        CachedSettingsEditor[buildTargetGroup].BuildTarget = buildTargetGroup;
                        CachedSettingsEditor[buildTargetGroup].OnInspectorGUI();
                    }
                }
                else if (obj == null)
                {
                    settings.AssignedSettings       = null;
                    loaderProp.objectReferenceValue = null;
                }

                serializedSettingsObject.ApplyModifiedProperties();
            }
            catch (Exception ex)
            {
                Debug.LogError($"Error trying to display provider assignment UI : {ex.Message}");
            }

            EditorGUILayout.EndBuildTargetSelectionGrouping();
        }