Unity modify UnityEditor.DLL

1: Cause

In most cases, there is no need to modify the unity dll, because the strength does not allow it, no bb, my unity version 2017.4.25

 Unity 2017 introduced spriteAtlas new atlas method, but every time a new spriteAtlas is created, you have to find the files (folders) that need to open the atlas.

 

What I think is that when I click the "+" sign, I will directly enter all the folders that I need to type atlas, as shown below

Or directly pack the corresponding sprite I selected (I can’t figure this out)

So I wanted to write an editor script, thinking that Unity must have an interface in this respect, but I checked the api, no! ! ! ! ! ! ! !

It’s not really not, because I don’t have this version, and it’s not in 2018.1. I checked the interface in 2018.3.

In 2017, using Unityeditor.U2D does not exist.

2: Scheme

Unity open sourced the C# code  and then I wondered if I could modify it directly, click on the "+" sign to modify that field, and then download the corresponding source code to view the code inside

That's it, then I modified it a bit

Code explanation: AssetDatabase.GetAssetPath(Selection.objects[0]) gets the first file path

                System.IO.Directory.GetParent().name Gets the name of the parent folder of the file path

Then I naively thought that it was enough to just replace the UnityEditor.dll in unity with the compiled UnityEditor.dll, but when I opened unity, there was a problem. There is a problem! ! ! If you are okay, tell me

Then what to do? ? ?

3: The ultimate solution

Finally, I use ILSpy to open UnityEditor.dll (path: Unity\Editor\Data\Managed)

md is obviously there, why not let us use it (ILSpy can't directly modify the dll), I just want to change one line of code, it's so difficult. But the problem with ordinary programmers is that I know how to do it. Do I just want to give up like this?

Then I found a way to modify the dll on the Internet and found it feasible, but I haven’t tried it.

1: A worker must first sharpen his tools if he wants to do his job well:

             First find two tools (1): ildasm.exe: This is a software that generates IL files from DLL

                                          (2): ilasm.exe: This is the function to regenerate DLL from IL file

2: Generate IL

Open this software, copy UnityEditro.dll under unity, and then open it with ildasm. I can’t read it even if I open it, just save it.

Naming: normal means this is normal

Then, we also compile the downloaded c# source code

Then compile this dll into IL language with ildasm as before (why do this, because I don’t understand IL, it’s impossible to modify IL directly, you can only compare the two files to see the modified place)

Then open the two ILs for comparison (just open it with Notepad, and look for the method name AddPackable directly)

That's it, then I copy this part of IL to normal.IL

Save

3: Compile into DLL

Then compile this modified normal.IL into a DLL

Use ilasm.exe, add the command ilasm.exe /dll/resource=normal.res normal.il, and then press Enter

You will see that a normal.dll appears under your folder at the end.

Okay, then, rename this dll UnityEditor.dll, and copy it to the Data\Managed folder of unity. ok and then open unity

Found that there is no error, then we, try the effect

For example, we want to open this folder as an atlas, and create an atlas in this directory

OK, it's over! ! ! It is pure egg pain 2018.3, you can write your own editor script to add. But you can learn how to modify the dll and compile it back! ! !

Two tool addresses: ilasm ildasm

Link: https://pan.baidu.com/s/18KTRcza1lP8cZ0f7CjNB_g Extraction code: xabb 

Originally uploaded to csdn, but the points need to be 5 points and can not be modified. . . . . I really tmd,,,,

Guess you like

Origin blog.csdn.net/K20132014/article/details/89217298