MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / TryGetPluginIcon

Method TryGetPluginIcon

Source/Editor/Plugins/PluginUtils.cs:20–50  ·  view source on GitHub ↗

Tries the get plugin icon (plugin may not have it). The plugin. The found texture asset to be used as a icon, or null if missing or invalid.

(Plugin plugin)

Source from the content-addressed store, hash-verified

18 /// <param name="plugin">The plugin.</param>
19 /// <returns>The found texture asset to be used as a icon, or null if missing or invalid.</returns>
20 public static Texture TryGetPluginIcon(Plugin plugin)
21 {
22 if (plugin == null)
23 throw new ArgumentNullException();
24
25 var type = plugin.GetType();
26 var assembly = type.Assembly;
27 var assemblyPath = Utils.GetAssemblyLocation(assembly);
28 var assemblyName = assembly.GetName().Name;
29 var dotEditorPos = assemblyName.LastIndexOf(".Editor", StringComparison.OrdinalIgnoreCase);
30 if (dotEditorPos != -1)
31 assemblyName = assemblyName.Substring(0, dotEditorPos);
32 var dotCSharpPos = assemblyName.LastIndexOf(".CSharp", StringComparison.OrdinalIgnoreCase);
33 if (dotCSharpPos != -1)
34 assemblyName = assemblyName.Substring(0, dotCSharpPos);
35 var assemblyDir = Path.GetDirectoryName(assemblyPath);
36
37 // Try path relative to the plugin binary
38 var iconPath = Path.Combine(assemblyDir, assemblyName + ".Icon.flax");
39 if (!File.Exists(iconPath))
40 {
41 // Try path relative to the plugin project Content
42 iconPath = Path.Combine(assemblyDir, "../../../../../Content", assemblyName + ".Icon.flax");
43 if (!File.Exists(iconPath))
44 {
45 return null;
46 }
47 }
48
49 return FlaxEngine.Content.LoadAsync<Texture>(iconPath);
50 }
51
52 private static int CountSubTypes(Type[] types, Type type)
53 {

Callers 1

PluginEntryMethod · 0.80

Calls 6

GetAssemblyLocationMethod · 0.80
SubstringMethod · 0.80
GetDirectoryNameMethod · 0.80
GetTypeMethod · 0.45
GetNameMethod · 0.45
ExistsMethod · 0.45

Tested by

no test coverage detected