Skip to content

Commit

Permalink
add warning icon and text when plugin can't function for some reason …
Browse files Browse the repository at this point in the history
…(e.g. missing package dependency)
  • Loading branch information
hybridherbst committed Dec 30, 2023
1 parent b81d3da commit 8ce0ab4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Runtime/Scripts/Extensions/DracoImport.cs
Expand Up @@ -10,6 +10,10 @@ public override GltfImportPluginContext CreateInstance(GLTFImportContext context
{
return new DracoImportContext();
}

#if !HAVE_DRACO
public override string Warning => "Please add the package \"com.atteneder.draco\" to your project for Draco mesh compression support.";
#endif
}

public class DracoImportContext: GltfImportPluginContext
Expand Down
4 changes: 4 additions & 0 deletions Runtime/Scripts/Extensions/Ktx2Import.cs
Expand Up @@ -10,6 +10,10 @@ public override GltfImportPluginContext CreateInstance(GLTFImportContext context
{
return new Ktx2ImportContext();
}

#if !HAVE_KTX
public override string Warning => "Please add the package \"com.atteneder.ktx\" version v1.3+ to your project for KTX2 texture support.";
#endif
}

public class Ktx2ImportContext: GltfImportPluginContext
Expand Down
4 changes: 4 additions & 0 deletions Runtime/Scripts/Extensions/MeshoptImport.cs
Expand Up @@ -10,6 +10,10 @@ public override GltfImportPluginContext CreateInstance(GLTFImportContext context
{
return new MeshoptImportContext();
}

#if !HAVE_MESHOPT_DECOMPRESS
public override string Warning => "Please add the package \"com.unity.meshopt.decompress\" to your project for Meshopt compression support.";
#endif
}

public class MeshoptImportContext: GltfImportPluginContext
Expand Down
17 changes: 17 additions & 0 deletions Runtime/Scripts/GLTFSettings.cs
Expand Up @@ -129,7 +129,22 @@ internal static void OnPluginsGUI(IEnumerable<GltfPlugin> plugins)
{
plugin.Enabled = GUILayout.Toggle(plugin.Enabled, "", GUILayout.Width(12));
var label = new GUIContent(displayName, plugin.Description);
EditorGUI.BeginDisabledGroup(!plugin.Enabled);
var expanded2 = EditorGUILayout.Foldout(expanded, label);

if (plugin.Enabled && !string.IsNullOrEmpty(plugin.Warning))
{
// calculate space that the label needed
var labelSize = EditorStyles.foldout.CalcSize(label);
var warningIcon = EditorGUIUtility.IconContent("console.warnicon.sml");
warningIcon.tooltip = plugin.Warning;
// show warning if needed
var lastRect = GUILayoutUtility.GetLastRect();
var warningRect = new Rect(lastRect.x + labelSize.x + 4, lastRect.y, 32, 16);
EditorGUI.LabelField(warningRect, warningIcon);
}

EditorGUI.EndDisabledGroup();
if (expanded2 != expanded)
{
expanded = expanded2;
Expand All @@ -140,6 +155,8 @@ internal static void OnPluginsGUI(IEnumerable<GltfPlugin> plugins)
{
EditorGUI.indentLevel += 1;
EditorGUILayout.HelpBox(plugin.Description, MessageType.None);
if (!string.IsNullOrEmpty(plugin.Warning))
EditorGUILayout.HelpBox(plugin.Warning, MessageType.Warning);
EditorGUI.BeginDisabledGroup(!plugin.Enabled);
editorCache.TryGetValue(plugin.GetType(), out var editor);
Editor.CreateCachedEditor(plugin, null, ref editor);
Expand Down
3 changes: 2 additions & 1 deletion Runtime/Scripts/Plugins/GltfPlugin.cs
Expand Up @@ -6,7 +6,8 @@ public abstract class GltfPlugin: ScriptableObject
{
public abstract string DisplayName { get; }
public abstract string Description { get; }
public virtual string HelpUrl => "";
public virtual string HelpUrl => null;
public bool Enabled { get; set; } = true;
public virtual string Warning => null;
}
}

0 comments on commit 8ce0ab4

Please sign in to comment.