Debugging open source UGUI source code in Unity

Debugging open source UGUI source code in Unity

I've been a bit decadent recently, and I haven't written an article for a long time. In order to motivate myself, I'm going to open a new pit: Combining official documents, my own experience, and my own understanding to briefly sort out and analyze the source code of UGUI .

I feel like I can write this series for a year, and I don’t have to worry about finding content or articles anymore, haha.

I saw that many people on the Internet have tried this, but they gave up after writing a few articles. I hope I can stick to it as much as possible.

Okay, enough nonsense, let's start today's content officially.

Today is the beginning of the whole series, mainly introducing how to embed the official open source UGUI source code into the project for debugging.

Environment build

We first need to download the corresponding version of the UGUI source code on the official github , because the official only provides a partial version of the source code, you need to pay attention when searching.

For the purpose of research and learning, in order not to affect the daily development (the installation directory will be modified in the later process), we can find a version close to daily use, such as our daily use 2017.4.37f1, when studying the UGUI source code, The version I downloaded is 2017.3.1f1, although the version is different, but the difference is not big.

After the source code is downloaded, download and install the corresponding Unity.

Then enter the directory unity installation directory: C:\Program Files\Unity\2017.3.1f1\Editor\Data\UnityExtensions\Unity, find GUISystemthe folder, and move it out of the installation directory (you can also delete it directly after backup).

GUISystemThis folder is the library after UGUI compilation, if not removed, there will be conflicts later.

After 2019.2, the source code is added to the installation directory in the form of a package, and there is no need to download it from github. The specific project reference is: C:\Program Files\Unity\2019.4.26f1\Unity\Editor\Data\Resources\PackageManager\BuiltInPackagesData\Resources\PackageManager\BuiltInPackages\com.unity.ugui.

Here we are for the purpose of learning and research, so we can use 2017 directly.

Then use the corresponding version of unity to create a new project. For example UnityUI, after entering the editor at this time, the relevant parts of UGUI cannot be used. We will add the downloaded source code to the project, and it can be used after the compilation is completed.

Note that when adding the source code, you can only add UnityEditor.UIand UnityEngine.UI, and the directory name can be modified after adding. The whole process is actually equivalent to writing a code and moving it in. There is nothing complicated.

For example, I just added the source code to Assets/Unity:

insert image description here

Also, if you keep the original directory unchanged, sometimes an error may be reported, so it is best to change the name of the directory. For example, I changed the UnityEditor.UIdirectory to Editorthe following:

insert image description here

At this point, our entire environment is set up. You can use the IDE you usually use, such as Rider, VS, etc. to debug the source code to observe and learn the source code.

Summarize

Today's content is not much, but it is very important. Many students study the source code only by looking at the code, which may not be very efficient.

I believe that after setting up the debugging environment according to today's content, the learning and understanding of source code can greatly improve the efficiency.

The following articles will focus on the event system to conduct research on the UGUI source code, step by step, try to be clear and clear, and hope to be helpful to everyone.

Guess you like

Origin blog.csdn.net/woodengm/article/details/123330992