Skip to content

Instantly share code, notes, and snippets.

@badscotsman
Created May 5, 2024 14:34
Show Gist options
  • Save badscotsman/31b7f88315e1aa746592e556d4623e65 to your computer and use it in GitHub Desktop.
Save badscotsman/31b7f88315e1aa746592e556d4623e65 to your computer and use it in GitHub Desktop.
Draw a logo at the top of components in the Unity Inspector based on namespace.
using UnityEditor;
using UnityEngine;
namespace MyNamespace.Common.EditTime
{
[CustomEditor(typeof(MonoBehaviour), true), CanEditMultipleObjects]
public class NamespaceCustomLogoDrawer : UnityEditor.Editor
{
private const string NAMESPACE_PREFIX = "MyNamespace";
private Texture2D _namespaceIcon;
private void OnEnable()
{
_namespaceIcon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/Images/My Logo.png");
if (_namespaceIcon == null)
{
Debug.LogError($"Failed to load the '{NAMESPACE_PREFIX}' namespace icon for Editor drawer.");
}
}
public override void OnInspectorGUI()
{
if (target.GetType().Namespace != null && target.GetType().Namespace.StartsWith(NAMESPACE_PREFIX))
{
Rect rect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(25));
GUI.Label(rect, _namespaceIcon);
}
base.OnInspectorGUI();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment