Can I reuse part of a native Unity class code in my game?

I’m making my first videogame. I’m creating my custom button class derived from UnityEngine.UI.Button, and I’ve overridden the custom inspector because I didn’t want the Transition property to appear, since it doesn’t need to be used.
Though, I needed the OnClick() list and the Navigation property to appear, along with the working Visualize button. To make it work, I took a look at unity-ui-hg-sync/UnityEditor.UI/UI/SelectableEditor.cs at master · dolow/unity-ui-hg-sync · GitHub, the native SelectableEditor source code. I took a look at how the private members where named so that I could access them using Reflection, and I also basically copied and pasted the button part (lines 177-184), which very small changes.

Now, I know that Unity posted their source code online with a reference-only license. Is what I’m doing legal in this sense or I shouldn’t worry?

If you are using code under the reference-only license other than for reference purposes, you’re likely violating the license.

Will they care about the 8 lines of code you copied? I doubt it, but I’d just rewrite those 8 lines instead of copying them verbatim. My 2 cents.

Are you sure? Because what I basically copied is just the code to display the toggle button (and I added two lines as well). Then I took a look at how the private members were named so that I could access them via reflection.

More specifically, I noticed that to actually display the Navigation arrows, there is an instruction called EditorPrefs.SetBool and an associated string “SelectableEditor.ShowNavigation” to enable/disable them. So I just inserted that instruction in my button code, and used reflection to get and set some private values.

Are all those things violating the license? If such a small thing is a violation, what is all of that online source code even for? I thought the license was for avoiding you copying the engine code and making your own engine based off of it, but taking some pieces of code from there to make your GAME work, why should that be a violation?

I think you mixed something up here. Untiy released the source code of the UnityEngine.dll and UnityEditor.dll under the reference only license. The uGUI system is completely seperate. Here’s the actual repository with a seperate license. In the beginning I think the original code was even under an MIT license as far as I remember correctly. However they changed it to this Unity Companion License. The uGUI system has been moved into a package now. When you check the Package Manager inside Unity, the UnityGUI package has this license attached which is that same iicense.

The UI system was designed from ground up to be extensible by Users. However the license does only allow the usage of the code in combination with Unity. So you’re not allowed to drag the code out and use it in plain C# with another engine that is not Unity. So this is a safeguard to provide max freedome within the usage inside a Unity project but does not allow to use the code outside Unity.

Didn’t really understand the first part of what you said. So, is what I did allowed or not?

Actually, this repo is MIT, you do whatever you want with it. Later Unity released a newer version of the UI with a different license, but that doesn’t mean anything if you don’t use that version with that license. As long as you stick to this source code, you can copy from it.

Is that link that I sent the version with the new license that I can copy from?

Yes. unity-ui-hg-sync/LICENSE at master · dolow/unity-ui-hg-sync · GitHub

Very good, thanks, I don’t need to delete everything.