public static EditorTexture Icon(this UnityObject obj) { var icon = (Texture2D)EditorGUIUtility.ObjectContent(obj, obj?.GetType()).image; if (icon != null) { return(EditorTexture.Single(icon)); } return(null); }
public static EditorTexture Load(IResourceProvider resources, string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required) { using (ProfilingUtility.SampleBlock("Load Editor Texture")) { Ensure.That(nameof(resources)).IsNotNull(resources); Ensure.That(nameof(path)).IsNotNull(path); Ensure.That(nameof(resolutions)).HasItems(resolutions); var set = new EditorTexture(); var name = Path.GetFileNameWithoutExtension(path).PartBefore('@'); var extension = Path.GetExtension(path); var directory = Path.GetDirectoryName(path); // Try with explicit resolutions first foreach (var resolution in resolutions) { var width = resolution.width; // var height = resolution.height; var personalPath = Path.Combine(directory, $"{name}@{width}x{extension}"); var professionalPath = Path.Combine(directory, $"{name}@{width}x_Pro{extension}"); if (resources.FileExists(personalPath)) { set.personal.Add(width, resources.LoadTexture(personalPath, options)); } if (resources.FileExists(professionalPath)) { set.professional.Add(width, resources.LoadTexture(professionalPath, options)); } } if (set.personal.Count == 0) { if (required) { Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}"); } // Never return an empty set; the codebase assumes this guarantee return(null); } return(set); } }
private static EditorTexture GetBuiltInUnityTypeIcon(Type type) { var icon = (Texture2D)EditorGUIUtility.ObjectContent(null, type).image; // Change the blank file icon to a Unity-logo file icon if (icon == EditorGUIUtility.FindTexture("DefaultAsset Icon")) { icon = EditorGUIUtility.FindTexture("ScriptableObject Icon"); } if (icon != null) { return(EditorTexture.Single(icon)); } return(null); }
public static EditorTexture Load(IResourceProvider resources, string path, CreateTextureOptions options, bool required) { using (ProfilingUtility.SampleBlock("Load Editor Texture")) { Ensure.That(nameof(resources)).IsNotNull(resources); Ensure.That(nameof(path)).IsNotNull(path); var set = new EditorTexture(); var name = Path.GetFileNameWithoutExtension(path).PartBefore('@'); var extension = Path.GetExtension(path); var directory = Path.GetDirectoryName(path); var personalPath = Path.Combine(directory, $"{name}{extension}"); var professionalPath = Path.Combine(directory, $"{name}@Pro{extension}"); var texture = resources.LoadTexture(personalPath, options); if (texture != null) { set.personal.Add(texture.width, texture); } texture = resources.LoadTexture(professionalPath, options); if (texture != null) { set.professional.Add(texture.width, texture); } if (set.personal.Count == 0) { if (required) { Debug.LogWarning($"Missing editor texture: {name}\n{resources.DebugPath(path)}"); } // Never return an empty set; the codebase assumes this guarantee return(null); } return(set); } }
private static EditorTexture GetScriptTypeIcon(string scriptName) { var scriptObject = (UnityObject)EditorGUIUtility_GetScriptObjectFromClass.Invoke(null, new object[] { scriptName }); if (scriptObject != null) { var scriptIcon = (Texture2D)EditorGUIUtility_GetIconForObject.Invoke(null, new object[] { scriptObject }); if (scriptIcon != null) { return(EditorTexture.Single(scriptIcon)); } } var scriptPath = AssetDatabase.GetAssetPath(scriptObject); if (scriptPath != null) { switch (Path.GetExtension(scriptPath)) { case ".js": return(EditorTexture.Single((Texture2D)EditorGUIUtility.IconContent("js Script Icon").image)); case ".cs": return(EditorTexture.Single((Texture2D)EditorGUIUtility.IconContent("cs Script Icon").image)); case ".boo": return(EditorTexture.Single((Texture2D)EditorGUIUtility.IconContent("boo Script Icon").image)); } } return(null); }
public Root(GUIContent header) { label = header.text; icon = EditorTexture.Single(header.image); }
private void OnGUI() { EditorGUI.BeginDisabledGroup(EditorApplication.isCompiling); scroll = GUILayout.BeginScrollView(scroll); LudiqGUI.BeginHorizontal(); LudiqGUI.BeginVertical(); foreach (var configuration in configurations) { if (configuration.Any(i => i.visible)) { if (configurations.Count > 1) { Header(configuration.header.Replace(label + " ", "")); } EditorGUI.BeginChangeCheck(); using (Inspector.expandTooltip.Override(true)) { foreach (var item in configuration.Where(i => i.visible)) { LudiqGUI.Space(2); LudiqGUI.BeginHorizontal(); LudiqGUI.Space(4); var iconPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(Styles.iconSize), GUILayout.Height(Styles.iconSize), GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false)); EditorTexture icon = null; string tooltip = null; if (item is ProjectSettingMetadata) { icon = LudiqCore.Icons.projectSetting; tooltip = "Project Setting: Shared across users, local to this project. Included in version control."; } else if (item is EditorPrefMetadata) { icon = LudiqCore.Icons.editorPref; tooltip = "Editor Pref: Local to this user, shared across projects. Excluded from version control."; } if (icon != null) { using (LudiqGUI.color.Override(GUI.color.WithAlpha(0.6f))) { GUI.Label(iconPosition, new GUIContent(icon[Styles.iconSize], tooltip), GUIStyle.none); } } LudiqGUI.Space(6); LudiqGUI.BeginVertical(); LudiqGUI.Space(-3); LudiqGUI.InspectorLayout(item); LudiqGUI.EndVertical(); LudiqGUI.EndHorizontal(); } } if (EditorGUI.EndChangeCheck()) { configuration.Save(); InternalEditorUtility.RepaintAllViews(); } } } LudiqGUI.Space(8); if (GUILayout.Button("Reset to Defaults")) { if (EditorUtility.DisplayDialog("Reset to Defaults", "Are you sure you want to reset your preferences and project settings to default?", "Reset")) { foreach (var configuration in configurations) { configuration.Reset(); configuration.Save(); } InternalEditorUtility.RepaintAllViews(); } } LudiqGUI.Space(8); LudiqGUI.EndVertical(); LudiqGUI.Space(8); LudiqGUI.EndHorizontal(); GUILayout.EndScrollView(); EditorGUI.EndDisabledGroup(); }
public static void DrawDragAndDropPreviewLabel(Vector2 position, string content, EditorTexture icon) { DrawDragAndDropPreviewLabel(position, new GUIContent(content, icon?[IconSize.Small])); }
public EditorTexture LoadIcon(string path, bool required = true) { return(EditorTexture.Load(providers, path, EditorTexture.StandardIconResolutions, CreateTextureOptions.PixelPerfect, required)); }
public EditorTexture LoadTexture(string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required = true) { return(EditorTexture.Load(providers, path, resolutions, options, required)); }