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    
ai.fluctio.fluctio-sim / EditorCore / HierarchyIcons / HierarchyIconsSettings.cs
Size: Mime:
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Fluctio.FluctioSim.Common.Icons;
using Fluctio.FluctioSim.EditorUtils.EditorGeneral;
using Fluctio.FluctioSim.EditorUtils.Gui;
using Fluctio.FluctioSim.EditorUtils.SettingsManagement;
using Fluctio.FluctioSim.EditorUtils.SettingsManagement.Table;
using Fluctio.FluctioSim.Utils.Extensions;
using UnityEditor;
using UnityEditor.SettingsManagement;
using UnityEngine;
using static Fluctio.FluctioSim.EditorUtils.SettingsManagement.SettingsManager;

namespace Fluctio.FluctioSim.EditorCore.HierarchyIcons
{
	public static class HierarchyIconsSettings
	{
		
		[InitializeOnLoadMethod]
		private static void InitSettings() => AddExecutingAssembly();

		[UserSetting]
		private static readonly UserSetting<bool> IsEnabledSetting = Preference("HierarchyIconsSettings.IsEnabled", true);
		public static bool IsEnabled => IsEnabledSetting.value;

		[UserSetting]
		private static readonly UserSetting<int> IconsLimitSetting = Preference("HierarchyIconsSettings.IconsLimit", 4);
		public static int IconsLimit => IconsLimitSetting.value;
		
		[UserSetting]
		private static readonly UserSetting<bool> ShowHiddenComponentsSetting = Preference("HierarchyIconsSettings.ShowHiddenComponents", false);
		public static bool ShowHiddenComponents => ShowHiddenComponentsSetting.value;
		
		[UserSetting]
		private static readonly UserSetting<bool> ShowDisabledComponentsSetting = Preference("HierarchyIconsSettings.ShowDisabledComponents", false);
		public static bool ShowDisabledComponents => ShowDisabledComponentsSetting.value;
		
		[UserSetting]
		private static readonly UserSetting<bool> ShowNoneJointsSetting = Preference("HierarchyIconsSettings.ShowNoneJoints", false);
		public static bool ShowNoneJoints => ShowNoneJointsSetting.value;

		[UserSetting]
		private static readonly UserSetting<GameObjectIconMode> GameObjectIconModeSetting = Preference("HierarchyIconsSettings.GameObjectIconMode", GameObjectIconMode.HideGameObjectIcon);
		public static GameObjectIconMode GameObjectIconMode => GameObjectIconModeSetting.value;

		#region Specific icons settings
		private static readonly TableDefinition<HierarchyIconLabel, HierarchyIconInfo> IconsInfoTable = new(
			IsFoldout: true,
			Title: "Specific Icons Settings",
			Rows: new Dictionary<string, TableRowDefinition<HierarchyIconLabel, HierarchyIconInfo>>
			{
				["GameObject"] = new(
					new HierarchyIconLabel(DefinedIcons.GameObject, "GameObject Icons"),
					new HierarchyIconInfo(new Color32(77, 0, 255, 255))),
				["ComponentJoint"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentJoint, "Joints"),
					new HierarchyIconInfo(new Color32(0, 139, 255, 255))),
				["ComponentStructure"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentStructure, "Body and Geom"),
					new HierarchyIconInfo(new Color32(255, 115, 0, 255))),
				["ComponentColor"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentColor, "Color"),
					new HierarchyIconInfo()),
				["ComponentSize"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentSize, "Size"),
					new HierarchyIconInfo()),
				["ComponentPhysicalProperties"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentPhysicalProperties, "Physical Properties"),
					new HierarchyIconInfo()),
				["ComponentHeightMapLayer"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentHeightMapLayer, "Height Map Layer"),
					new HierarchyIconInfo(new Color32(255, 115, 0, 255))),
				["ComponentAgent"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentAgent, "Agents"),
					new HierarchyIconInfo(new Color32(255, 0, 0, 255))),
				["ComponentSensor"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentSensor, "Sensors"),
					new HierarchyIconInfo(new Color32(140, 0, 255, 255))),
				["ComponentActuator"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentActuator, "Actuators"),
					new HierarchyIconInfo(new Color32(5, 168, 27, 255))),
				["ComponentRewardAdder"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentRewardAdder, "Reward Adder"),
					new HierarchyIconInfo(new Color32(252, 0, 255, 255))),
				["ComponentEpisodeEnder"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentEpisodeEnder, "Episode Ender"),
					new HierarchyIconInfo(new Color32(252, 0, 255, 255))),
				["ComponentMujocoChainReseter"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentMujocoChainReseter, "MuJoCo Chain Reseter"),
					new HierarchyIconInfo(new Color32(252, 0, 255, 255))),
				["ComponentComponentEnabler"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentComponentEnabler, "Component Enabler"),
					new HierarchyIconInfo(new Color32(252, 0, 255, 255))),
				["LogInfoAction"] = new(
					new HierarchyIconLabel(DefinedIcons.LogInfoAction, "Log Info Action"),
					new HierarchyIconInfo(new Color32(252, 0, 255, 255))),
				["ComponentRandomization"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentRandomization, "Randomization"),
					new HierarchyIconInfo(new Color32(252, 0, 255, 255))),
				["ComponentRewardCalculator"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentRewardCalculator, "Reward Calculators"),
					new HierarchyIconInfo()),
				["ComponentTrigger"] = new(
					new HierarchyIconLabel(DefinedIcons.ComponentTrigger, "Triggers"),
					new HierarchyIconInfo()),
				["MoreComponents"] = new(
					new HierarchyIconLabel(DefinedIcons.MoreComponents, "More Components", true),
					new HierarchyIconInfo(new Color32(77, 0, 255, 255))),
			},
			DrawHeader: () =>
			{
				GUILayout.Label("Icon Type", EditorStyles.boldLabel, GUILayout.Width(EditorGUIUtility.labelWidth));
				GUILayout.Label("Draw Icon?", EditorStyles.boldLabel, GUILayout.Width(EditorGUIUtility.singleLineHeight * 5));
				GUILayout.Label("Icon Color", EditorStyles.boldLabel, GUILayout.Width(EditorGUIUtility.singleLineHeight * 5));
			},
			DrawRow: (label, info, searchContext) => {
				using (new ColorScope(info.Color))
				{
					var whiteIcon = DefinedIcons.GetWhiteVersion(label.Icon) ?? label.Icon;
					GUILayout.Label(whiteIcon, EditorUtil.InlineIconStyle);	
				}
				GUILayout.Label(label.Description, EditorStyles.label, GUILayout.Width(EditorGUIUtility.labelWidth - EditorUtil.InlineIconStyle.fixedWidth));
			
				using (new EditorGUI.DisabledScope(label.FixIsEnabled))
				{
					info.IsEnabled = EditorGUILayout.Toggle(info.IsEnabled, EditorStyles.toggle, GUILayout.Width(EditorGUIUtility.singleLineHeight));
				}
				GUILayout.Space(EditorGUIUtility.singleLineHeight * 4);
				using (new EditorGUI.DisabledScope(!info.IsEnabled))
				{
					info.Color = EditorGUILayout.ColorField(info.Color, GUILayout.Width(EditorGUIUtility.singleLineHeight * 5));
				}
			}
		);
		
		[UserSetting]
		private static readonly TableSetting<HierarchyIconLabel, HierarchyIconInfo> IconsInfoSetting = TablePreference("HierarchyIconsSettings.IconsInfo", IconsInfoTable);
		public static HierarchyIconInfo GameObjectIconInfo => IconsInfoSetting["GameObject"];
		public static HierarchyIconInfo MoreComponentsIconInfo => IconsInfoSetting["MoreComponents"];
		public static ProxyLookup<Texture2D, HierarchyIconInfo, HierarchyIconInfo> IconsInfo =>
			IconsInfoSetting.GetLookup(row => row.Label.Icon).ToProxyLookup((key, value) => value.SingleOrDefault());
		#endregion
		
		[UserSettingBlock("Hierarchy Icons")]
		[SuppressMessage("ReSharper", "UnusedMember.Local")]
		private static void DrawSettings(string searchContext)
		{
			IsEnabledSetting.value = SettingsGUILayout.SettingsToggle(
				"Enable Hierarchy Icons Drawer", 
				IsEnabledSetting, searchContext);
			using var isEnabledScope = new EditorGUI.DisabledScope(!IsEnabledSetting.value);
			
			IconsLimitSetting.value = SettingsGUILayout.SettingsSlider(
				new GUIContent(
					"Max Icons Amount",
					"Maximum amount of icons in a row"),
				IconsLimitSetting, 2, 10, searchContext);

			ShowHiddenComponentsSetting.value = SettingsGUILayout.SettingsToggle(
				new GUIContent(
					"Show Hidden Components",
					"Show components with HideFlags containing HideInInspector"),
				ShowHiddenComponentsSetting, searchContext);

			ShowDisabledComponentsSetting.value = SettingsGUILayout.SettingsToggle(
				new GUIContent(
					"Show Disabled Components",
					"Show components which were disabled in inspector"),
				ShowDisabledComponentsSetting, searchContext);

			ShowNoneJointsSetting.value = SettingsGUILayout.SettingsToggle(
				new GUIContent(
					"Show 'None' Joints",
					"Show Joints with JointType set to None"),
				ShowNoneJointsSetting, searchContext);
			
			// TODO: add reset context menu
			GameObjectIconInfo.IsEnabled = SettingsGUILayout.SearchableToggle(
				"Draw GameObject Icon",
				GameObjectIconInfo.IsEnabled, searchContext);

			using (new EditorGUI.DisabledScope(!GameObjectIconInfo.IsEnabled))
			{
				GameObjectIconModeSetting.value = SettingsGUIExtension.SettingsDropdown(
					new GUIContent(
						"Repeating GameObject Icon",
						"This setting indicates what will happen when the first Component icon is the same as the GameObject icon"), 
					GameObjectIconModeSetting, searchContext);
			}
			
			SettingsGUIExtension.SettingsTable(IconsInfoSetting, searchContext);
		}
		
	}
}