Hello, I’m building a script that detects if a MonoBehaviour is part of UnityEngine, the editor, or my own code.
I’ve been trying to use:
static bool IsUnityMonoBehaviour(MonoBehaviour monoBehaviour)
{
Assembly assembly = monoBehaviour.GetType().Assembly;
return assembly.FullName.StartsWith("UnityEngine") &&
assembly.FullName.StartsWith("UnityEditor");
}
to do this, but it doesn’t seem to work. It pings ‘true’ on both my own code, and on things like the camera.
Is there a way to do this?
Your code would need to be in its own assembly definition to not be picked up.
Maybe just check the namespace? Type.Namespace Property (System) | Microsoft Learn
What do you want to do this for as well?
Thanks a lot! Seems to work now.
Reason why I’m doing this is that the Hierarchy search functions are really underwhelming, so I’m trying to make myself a new helper window or make it better.
My main issue is that I can’t find a way to inject new buttons into the hierarchy’s top bar, and I suspect I would need to make an entire new hierarchy of my own just to do that.
Any ideas on how to shortcut this? Or wrap the old hierarchy somehow, so my buttons can go at the top?