Unity's custom Attributes source code

Hello Everyone!

I am studying Unity’s custom Attributes, such as ToolTip, RequireComponent, SerializeField and so forth. I am interested in looking into their source code (i.e, the class RequireComponent.cs and also who processes them). From Visual Studio I can navigate and take a look in the code.

However, I am unable to find the class (or any other Attribute class) on the GitHub repository: GitHub - Unity-Technologies/UnityCsReference: Unity C# reference source code. I thought this repo would contain all the C# source code used in the Unity Engine and Editor.

So my question is, what am I missing? Did I misinterpreted what code would be put in GitHub?

Thank you!

Almost all of the implementation of how the attributes are used and handled is done through native code, however.

1 Like

Thanks

So a while back, we’re talking like Unity 4 or 5, I started down the path of pulling this all apart. I didn’t completely document it or anything, nor explore all of it (and yes, a bit of it is closed behind closed native code). But I wanted to add many of my own features to the existing editor attribute system and did so.

How I went about it was to first create my own “SPEditor” class that hijacked all editor’s for anything that inherited from MonoBehaviour (unless that class specifically declared its own Editor script). And this was it:

Then I reflected out entry points into a lot of the internal stuff that were non-public, and did so here:

(note - this code has not been tested in 2019 versions, and if any of the reflected methods changed names, it can potentially be misleading)

With this I created an assortment of custom attributes that had extra features on top of the existing PropertyDrawer and the sort offered.

Like modifiers (attributes that ran code, but didn’t draw stuff, on a serialized field):

And other attributes (these mostly override the way unity handles arrays and propertydrawers which I hated. As well as a bunch of custom behaviours.):
https://github.com/lordofduct/spacepuppy-unity-framework-3.0/tree/master/SpacepuppyUnityFrameworkEditor/PropertyAttributeDrawers

You could maybe check out that to get some direction into unearthing where in the UnityEditor.dll you would want to look.