Created
May 5, 2024 14:34
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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