This article describes how to debug Lua in Unity. The specific solution is to use IntelliJ IDEA + EmmyLua.
step
Download and install IntelliJ IDEA https://www.jetbrains.com/idea/
Download EmmyLua, https://plugins.jetbrains.com/plugin/9768-emmylua
Open the plugins setting interface in IDEA (or enter File -> Settings -> Plugins from the menu),
click Install plugin from disk, select the downloaded LuaIDE-XXX.zip file, and restart IntelliJ IDEA after installation.
- Create a project: the menu goes to File -> New -> Project
- Set the existing source directory as the Sources directory: the menu goes to File -> Project Structure, select Modules -> Sources -> Add Content Root -> select the source root directory -> Mark as: Sources
- Breakpoint debugging: Run Unity, open IDEA menu Run -> Attach to Local Process, select Unity.exe
some problems:
- The breakpoint is invalid, and a xxx not found log appears in the IDEA console window
- Please make sure the Sources directory is set correctly
- Attaching to target program fails with Error: LuaInject.dll could not be loaded into the process
- Check whether the injection process is blocked by anti-virus and security guards
- Associate other extensions
IntelliJ IDEA common shortcut keys
Ctrl+N Find classes // Find lua files The following command to find files is more practical
Ctrl+Shift+N Find files
CTRL+SHIFT+ALT+N Find methods or variables in a class
CIRL+B / F4 find the source of the variable
CTRL+G locate line/jump line
Ctrl+Alt+L Format code
Ctrl+X delete line
Ctrl+D Duplicate line
Ctrl+R Replace text
Ctrl+F Find text
CIRL+U case switch
CTRL+Z go backward
Ctrl+P method parameter prompt
CTRL+SHIFT+Z forward
CTRL+ALT+F12 Explorer open folder
ALT+F1 Find the directory location where the file is located
Ctrl+F12, you can display the structure of the current file
Official document: https://emmylua.github.io/index.html
Official QQ exchange group: 29850775
If there are any mistakes, please point them out.
email:dxmdxm1992#gmail.com