/// <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); }
/// <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); }