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 / Dependencies / DependencyWindow.cs
Size: Mime:
using System;
using Fluctio.FluctioSim.EditorCore.Dependencies.DependencyTypes;
using Fluctio.FluctioSim.EditorUtils.EditorGeneral;
using Fluctio.FluctioSim.EditorUtils.Gui;
using UnityEditor;
using UnityEngine;

namespace Fluctio.FluctioSim.EditorCore.Dependencies
{
	public class DependencyWindow : ConfigurableEditorWindow
	{

		public override string Title => "Dependency Check";
		public override bool RequiresConstantRepaint => true;

		protected override void OnGUI()
		{
			base.OnGUI();
			SetupStyles();
			DrawDependencies();
		}

		#region Styles
		
		private static GUIStyle _dependencyStyle;
		private static GUIStyle _dependencyNameStyle;
		private static GUIStyle _dependencyTextStyle;
		private static GUIStyle _statusIconStyle;
		private static GUIStyle _actionButtonStyle;

		private static void SetupStyles()
		{
			_dependencyStyle ??= new GUIStyle(EditorStyles.helpBox)
			{
				stretchWidth = true,
				stretchHeight = false,
			};
			_dependencyNameStyle ??= new GUIStyle(GUI.skin.label)
			{
				fontStyle = FontStyle.Bold,
			};
			_dependencyTextStyle ??= new GUIStyle(GUI.skin.label)
			{
				wordWrap = true,
			};
			_statusIconStyle ??= new GUIStyle(GUI.skin.label)
			{
				fixedWidth = EditorGUIUtility.singleLineHeight*2,
				fixedHeight = EditorGUIUtility.singleLineHeight*2,
			};
			_actionButtonStyle ??= new GUIStyle(GUI.skin.button)
			{
				wordWrap = true,
				stretchHeight = false,
			};
		}
		
		#endregion
		
		#region Drawing
		
		private static void DrawDependencies()
		{
			DependencyCheck.Dependencies.ForEach(DrawDependency);
		}
		
		private static void DrawDependency(IDependency dependency)
		{
			var dependencyState = dependency.GetState();
			using (new EditorGUILayout.VerticalScope(_dependencyStyle))
			{
				using (new EditorGUILayout.HorizontalScope())
				{
					GUILayout.Box(dependencyState.Icon, _statusIconStyle);
					using (new EditorGUILayout.VerticalScope())
					{
						EditorGUILayout.LabelField(dependency.DisplayName, _dependencyNameStyle);
						EditorGUILayout.LabelField(dependencyState.Text, _dependencyTextStyle);
					}
				}
				using (new EditorGUILayout.HorizontalScope())
				{
					dependencyState.Actions.ForEach(DrawAction);
				}
			}
		}

		private static void DrawAction(Action action)
		{
			var buttonText = action.Method.GetDescription();
			if (EditorGUIExtensions.LeftClickButton(buttonText, _actionButtonStyle))
			{
				action();
			}
		}
		
		#endregion
		
	}
}