Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Fluctio.FluctioSim.Common.Configuration;
using Fluctio.FluctioSim.EditorUtils.SettingsManagement.Table;
using UnityEditor;
using UnityEditor.SettingsManagement;

namespace Fluctio.FluctioSim.EditorUtils.SettingsManagement
{
	public static class SettingsManager
	{
		#region Common
		private static Settings Settings { get; } = new(Config.PackageId);
		private static HashSet<Assembly> Assemblies { get; } = new() { typeof(SettingsManager).Assembly };

		public static void AddExecutingAssembly()
		{
			Assemblies.Add(Assembly.GetCallingAssembly());
		}

		public static event Action BeforeChange {
			add => Settings.beforeSettingsSaved += value;
			remove => Settings.beforeSettingsSaved -= value;
		}
		
		public static event Action AfterChange {
			add => Settings.afterSettingsSaved += value;
			remove => Settings.afterSettingsSaved -= value;
		}
		#endregion
		
		#region Preferences
		private static readonly string PreferencesPath = $"Preferences/{Config.PrefixedName}";
		
		[SettingsProvider]
		private static SettingsProvider PreferencesProvider() =>
			new UserSettingsProvider(PreferencesPath, Settings, Assemblies.ToArray(), SettingsScope.User);
		
		public static UserSetting<T> Preference<T>(string key, T initialValue) =>
			new(Settings, $"{Config.PackageId}/{key}", initialValue, SettingsScope.User);
		
		public static TableSetting<TLabel, TInfo> TablePreference<TLabel, TInfo>(string key, TableDefinition<TLabel, TInfo> tableDefinition) =>
			new(Settings, $"{Config.PackageId}/{key}", tableDefinition, SettingsScope.User);
		
		public static void OpenPreferencesWindow() => SettingsService.OpenUserPreferences(PreferencesPath);
		#endregion

		#region Project Settings
		private static readonly string ProjectSettingsPath = $"Project/{Config.PrefixedName}";
		
		[SettingsProvider]
		private static SettingsProvider ProjectSettingsProvider() =>
			new UserSettingsProvider(ProjectSettingsPath, Settings, Assemblies.ToArray(), SettingsScope.Project);
		
		public static UserSetting<T> ProjectSetting<T>(string key, T initialValue) =>
			new(Settings, key, initialValue, SettingsScope.Project);
		
		public static TableSetting<TLabel, TInfo> TableProjectSetting<TLabel, TInfo>(string key, TableDefinition<TLabel, TInfo> tableDefinition) =>
			new(Settings, key, tableDefinition, SettingsScope.Project);

		public static void OpenProjectSettingsWindow() => SettingsService.OpenProjectSettings(ProjectSettingsPath);
		#endregion
	}
}