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.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Threading;
using Fluctio.FluctioSim.EditorUtils.OperatingSystem;
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using Object = UnityEngine.Object;

namespace Fluctio.FluctioSim.EditorUtils.EditorGeneral
{
	public static class EditorUtil
	{
		
		public static readonly Thread MainThread = Thread.CurrentThread;
		
		public static bool DidEditorJustOpen
		{
			get => SessionState.GetBool("DidEditorJustOpen", true);
			private set => SessionState.SetBool("DidEditorJustOpen", value);
		}

		[InitializeOnLoadMethod]
		private static void Init()
		{
			if (DidEditorJustOpen)
			{
				EditorUpdateEvents.UpdateOnce += () =>
				{
					DidEditorJustOpen = false;
				};
			}
		}

		public static GuiTheme GuiTheme => EditorGUIUtility.isProSkin ? GuiTheme.Dark : GuiTheme.Light;
		
		public static GUIStyle InlineIconStyle { get; } = new()
		{
			fixedWidth = EditorGUIUtility.singleLineHeight,
			fixedHeight = EditorGUIUtility.singleLineHeight,
			padding = new RectOffset(1, 1, 1, 1),
		};

		[Pure]
		public static string GetDescription(this MemberInfo element)
		{
			var displayNameAttribute = element.GetCustomAttribute<DescriptionAttribute>();
			var displayName = displayNameAttribute != null
				? displayNameAttribute.Description
				: ObjectNames.NicifyVariableName(element.Name);
			return displayName;
		}

		public static string AssetsFolder
		{
			get
			{
				var dataPath = Application.dataPath;
				return Platform.Type == PlatformType.Windows
					? dataPath.Replace('/', '\\')
					: dataPath;
			}
		}

		public static string ProjectFolder => Path.GetFullPath("..", AssetsFolder);

		private static string GetAssetPath(string parentFolderGuid, params string[] pathComponents)
		{
			var folderPath = AssetDatabase.GUIDToAssetPath(parentFolderGuid);
			var pathInFolder = Path.Combine(pathComponents);
			var assetPath = Path.Combine(folderPath, pathInFolder);
			return assetPath;
		}

		public static T LoadAsset<T>(string parentFolderGuid, params string[] pathComponents) where T : Object
		{
			var assetPath = GetAssetPath(parentFolderGuid, pathComponents);
			var fullPath = Path.GetFullPath(assetPath);
			var asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
			if (asset == null && File.Exists(fullPath))
			{
				throw new FileNotFoundException($"Could not load {typeof(T).Name} asset", fullPath);
			}
			return asset;
		}

		public static IEnumerable<GameObject> GetDescendants(this GameObject gameObject, bool includeSelf)
		{
			if (includeSelf)
			{
				yield return gameObject;
			}

			foreach (Transform child in gameObject.transform)
			{
				var descendants = GetDescendants(child.gameObject, true);
				foreach (var descendant in descendants)
				{
					yield return descendant;
				}
			}
		}

		public static IEnumerable<GameObject> GetDescendants(this Scene scene)
		{
			var rootObjects = scene.GetRootGameObjects();
			foreach (var rootObject in rootObjects)
			{
				var descendants = GetDescendants(rootObject, true);
				foreach (var descendant in descendants)
				{
					yield return descendant;
				}
			}
		}
		
	}

	public enum GuiTheme
	{
		Light,
		Dark,
	}
}