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}"); if (resources.FileExists(personalPath)) { var personalTexture = resources.LoadTexture(personalPath, options); if (personalTexture != null) { set.personal.Add(personalTexture.width, personalTexture); } } if (resources.FileExists(professionalPath)) { var professionalTexture = resources.LoadTexture(professionalPath, options); if (professionalTexture != null) { set.professional.Add(professionalTexture.width, professionalTexture); } } 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); } }
public static EditorTexture Single(Texture texture) { if (texture == null) { return(null); } lock (singleCache) { if (!singleCache.TryGetValue(texture, out var editorTexture)) { editorTexture = new EditorTexture(texture); singleCache.Add(texture, editorTexture); } return(editorTexture); } }
public UnityObjectOption(string label, string typeLabel, EditorTexture typeIcon, UnityObject uo, bool?isSceneBound, FuzzyOptionMode mode) : base(mode) { this.label = label; this.typeLabel = typeLabel; this.typeIcon = typeIcon; this.isSceneBound = isSceneBound; value = uo; if (!ReferenceEquals(uo, null)) { getIcon = uo.Icon; } else { icon = typeIcon; } }
public UnityObjectOptionTree ( Type type, string typeLabel, EditorTexture typeIcon, Scene?scene, bool allowAssetObjects, Func <UnityObject, bool> predicate = null, string title = "Object" ) : base(new GUIContent(title)) { this.type = type ?? typeof(UnityObject); this.typeLabel = typeLabel; this.typeIcon = typeIcon; this.scene = scene; this.allowAssetObjects = allowAssetObjects; this.predicate = predicate; }
private static EditorTexture GetBuiltInUnityTypeIcon(Type type) { Texture2D icon = null; try { if (typeof(EditorWindow).IsAssignableFrom(type)) { try { icon = ((GUIContent)UnityEditorDynamic.EditorWindow.GetLocalizedTitleContentFromType(type))?.image as Texture2D; } catch { icon = null; } } if (icon == null) { icon = UnityEditorDynamic.EditorGUIUtility.FindTexture(type); } if (icon == null) { icon = (Texture2D)EditorGUIUtility.ObjectContent(null, type).image; } } catch (Exception) {} if (icon != null) { return(EditorTexture.Single(icon)); } return(null); }
public void Load() { storage.Bind(nameof(empty), () => EditorTexture.Single(ColorPalette.transparent.GetPixel())); // Messages storage.Bind(nameof(informationMessage), () => LudiqGUIUtility.LoadBuiltinTexture("console.infoicon")); storage.Bind(nameof(questionMessage), () => resources.LoadIcon("Icons/Messages/Question.png")); storage.Bind(nameof(warningMessage), () => LudiqGUIUtility.LoadBuiltinTexture("console.warnicon")); storage.Bind(nameof(successMessage), () => resources.LoadIcon("Icons/Messages/Success.png")); storage.Bind(nameof(errorMessage), () => LudiqGUIUtility.LoadBuiltinTexture("console.erroricon")); // States storage.Bind(nameof(warningState), () => LudiqGUIUtility.LoadBuiltinTexture("console.warnicon")); storage.Bind(nameof(successState), () => resources.LoadIcon("Icons/State/Success.png")); storage.Bind(nameof(errorState), () => LudiqGUIUtility.LoadBuiltinTexture("console.erroricon")); storage.Bind(nameof(progress), () => resources.LoadIcon("Icons/State/Progress.png")); // Versioning storage.Bind(nameof(upgrade), () => resources.LoadIcon("Icons/Versioning/Upgrade.png")); storage.Bind(nameof(upToDate), () => resources.LoadIcon("Icons/Versioning/UpToDate.png")); storage.Bind(nameof(downgrade), () => resources.LoadIcon("Icons/Versioning/Downgrade.png")); // Windows storage.Bind(nameof(supportWindow), () => resources.LoadIcon("Icons/Windows/SupportWindow.png")); storage.Bind(nameof(sidebarAnchorLeft), () => resources.LoadTexture("Icons/Windows/SidebarAnchorLeft.png", CreateTextureOptions.PixelPerfect)); storage.Bind(nameof(sidebarAnchorRight), () => resources.LoadTexture("Icons/Windows/SidebarAnchorRight.png", CreateTextureOptions.PixelPerfect)); // Configuration storage.Bind(nameof(editorPref), () => resources.LoadTexture("Icons/Configuration/EditorPref.png", new TextureResolution[] { 12, 24 }, CreateTextureOptions.PixelPerfect)); storage.Bind(nameof(projectSetting), () => resources.LoadTexture("Icons/Configuration/ProjectSetting.png", new TextureResolution[] { 12, 24 }, CreateTextureOptions.PixelPerfect)); // Other storage.Bind(nameof(@null), () => resources.LoadIcon("Icons/Null.png")); storage.Bind(nameof(generic), () => resources.LoadIcon("Icons/Generic.png")); storage.Bind(nameof(@new), () => resources.LoadIcon("Icons/New.png")); storage.Bind(nameof(folder), () => EditorTexture.Single(AssetDatabase.GetCachedIcon("Assets"))); }
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 static EditorTexture Icon(this UnityObject obj) { foreach (var handler in unityObjectIconHandlers) { if (handler(obj, out var handlerIcon)) { return(handlerIcon); } } var icon = AssetPreview.GetMiniThumbnail(obj); if (icon == null) { icon = (Texture2D)EditorGUIUtility.ObjectContent(obj, obj?.GetType()).image; } if (icon != null) { return(EditorTexture.Single(icon)); } return(null); }
public Root(GUIContent header) : base(FuzzyOptionMode.Branch) { label = header?.text ?? "Fuzzy"; icon = EditorTexture.Single(header?.image); }
public EditorTexture LoadIcon(string path, TextureResolution[] resolutions, bool required = true) { return(EditorTexture.Load(providers, path, resolutions, CreateTextureOptions.PixelPerfect, required)); }
public EditorTexture LoadTexture(string path, TextureResolution[] resolutions, CreateTextureOptions options, bool required = true) { return(EditorTexture.Load(providers, path, resolutions, options, required)); }