-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathIconUtility.cs
More file actions
50 lines (43 loc) · 1.66 KB
/
Copy pathIconUtility.cs
File metadata and controls
50 lines (43 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System.Collections.Generic;
using System.IO;
using UnityEngine;
namespace UnityEditor.ProBuilder
{
/// <summary>
/// Describes icon styles for pro and basic skin, or default (whatever the editor is currently using).
/// </summary>
enum IconSkin
{
Default,
Light,
Pro
};
static class IconUtility
{
static Dictionary<string, Texture2D> s_Icons = new Dictionary<string, Texture2D>();
static string s_IconFolderPath = "Packages/com.unity.probuilder/Editor Default Resources/Icons/";
[InitializeOnEnterPlayMode]
static void ResetStaticsOnLoad()
{
s_Icons.Clear();
}
/// <summary>
/// Load an icon from icons folder located in the package's 'Editor Default Resources'.
/// Naming convention is: "path/to/iconName" (without extension). Use the 'd_' prefix for dark skin icons.
/// No prefix or suffit for light skin icons. This method assumes the file is .png.
/// </summary>
/// <param name="iconName">Relative path to the icon without the file extension in the filename.</param>
/// <returns>A valid icon texture. Otherwise null is returned.</returns>
public static Texture2D GetIcon(string iconName)
{
Texture2D icon = null;
if (!s_Icons.TryGetValue(iconName, out icon))
{
string fullPath = Path.Combine(s_IconFolderPath, iconName + (Path.HasExtension(iconName)? string.Empty: ".png"));
icon = EditorGUIUtility.LoadIcon(fullPath);
s_Icons.Add(iconName, icon);
}
return icon;
}
}
}