[remote file browser] unity + Lua development and debugging tool

Time:2022-5-15

Remote File ExplorerIs a cross platformRemote file browser, users can operate the directory files of games or applications running on mobile phones through unity editor. For example, when a project is packaged and run on a device, you can useRemote File ExplorerBrowse the directory files on the device directly, and download, upload, delete and other operations. Especially the debugging tool in unity + Lua development environment. Of course, debugging here does not refer to line by line debugging of code, but generally refers to locating and troubleshooting problems

play

In many scenarios, using remote file explorer can greatly improve the efficiency of development and debugging. For example:

  • An exception occurs when the application is running on the real machine. It is speculated that it may be caused by the loss of key resources. At this time, you can directly browse the relevant files on the mobile phone through this tool to check whether the key resources exist
  • Through this tool, you can directly pull various files such as log files or memory analysis files on the mobile phone, and bid farewell to the data line
  • If the project adopts xlua or slua development, when the real machine is developed and debugged, the modified Lua code can be uploaded directly through this tool, and the application can take effect after restarting. So as to avoid the tedious process of rebuilding the application every time the code is modified, and greatly improve the debugging efficiency

Next, some specific cases will be used to demonstrate the use of the remote file explorer tool. The codes of the following use cases can be found inRemote File Explorer Demofind

Use case 1 – no need to repackage and modify code logic

  1. After the client is packaged and started, the initial interface is shown in the figure below. The text of “Hello, wlrod” is intentionally misspelled to demonstrate how to fix this error through remote file explorer without repackaging

  1. In unityeditor, open the remote file explorer tool window through “Window > remote file explorer”, and view the server IP through the stats panel

  1. Enter the correct server IP in the client, and then click Connect. After the connection is successful, the state of the stats panel will be displayed as “established”

  1. The spelling error is in this filechangetextcontent.luaIf it is wrong in the, modify the contents of the file as follows (mainly correct the spelling of “Hello, wlrod” to “Hello, world”)
local obj = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.Game.ChangeTextColor))
local textComponent = obj:GetComponent(typeof(CS.UnityEngine.UI.Text));
textComponent.text = "Hello, World"
  1. Through the remote file explorer tool window, goto to application Persistentdatapath directory. Lua files in this directory will be loaded preferentially (this is determined by the Lua loading mechanism in the project. For details, please refer toXLuaManager.cs

  1. Dragchangetextcontent.luaUpload files to this directory. After restarting the client, the spelling error of “Hello, wlrod” will be fixed. The complete operation process is shown below

  1. In addition, the logic of c# code can be modified by using the hotfix feature of xlua. For example, the color of “Hello, world” text is red set by c# code, which can be modifiedchangetextcontent.luaThe file sets the text to green, as shown below
local obj = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.Game.ChangeTextColor))
local textComponent = obj:GetComponent(typeof(CS.UnityEngine.UI.Text));
textComponent.text = "Hello, World"

xlua.hotfix(CS.Game.ChangeTextColor, "Start", function(self)
    self:GetComponent(typeof(CS.UnityEngine.UI.Text)).color = CS.UnityEngine.Color.green
    xlua.hotfix(CS.Game.ChangeTextColor, "Start", nil)
end)
  1. Then do the same operation and upload the file to application Persistentdatapath directory. After restarting the client, the text color will change. The complete operation process is shown below

Use case 2 – directly pull the log file on the mobile phone

  1. If a fixed file is pulled frequently, such as log file or performance analysis file. You can configureCustomMenuAttributeAdd a custom pull operation for the file. Pull the log file with game Log as an example, add a method decorated with custommenuattribute
using UnityEngine;
using RemoteFileExplorer.Editor;

public class TestAttribute
{
    [CustomMenu("pull game log")]
    public static void PullLog(ManipulatorWrapper manipulator)
    {
        string remoteLogPath = manipulator.GetRemotePath("Application.persistentDataPath") + "/Logs/game.log";
        manipulator. Download(remoteLogPath, Application.dataPath.Replace("/Assets", "") + "/Logs/game.log");  //  Download the log file locally
    }
}
  1. After the code is added, reopen the remote file explorer tool window and the “custom” menu will appear. After clicking the menu, the pulllog method will be executed

  1. After the connection is established successfully, you can pull the game with one click through the “pull game log” operation Log file. The complete operation process is shown below

install

This tool adopts unitypackageForm, can be throughUnity Package ManagerDirect installation

Here are two common methods

  • Open the “Window > package manager” window, click the “+” button on the left side of the status bar, select “add package from git URL”, and then enter the GIT address of the tool in the text boxhttps://github.com/iwiniwin/unity-remote-file-explorer.git, click the “add” button to complete the installation
  • Or directly clone the tool to the “packages” directory of the project

Detailed installation methods can be viewedWorking with documents, you can see more ways to install this tool as a packageUnity official document

use

After installing the tool, you can open the tool window through “Window > Analysis > remote file explorer”, and the server will start automatically

Add to any GameObject of the projectFileExplorerClientassembly

If you are fixedly connected to a machine, you can directly enter the IP address of the machine in the “host” field through the inspector panel, and then check “connect automatically” to automatically connect when the application starts

If you want to actively choose which machine to connect to after the application starts, you can package a simple UI in the debug mode to enable developers to enter the IP address they want to connect to. For example, add an item or button in your own menu, and click it to pop up the input window. After successfully obtaining the IP address, assign it to the “host” attribute of the fileexplorerclient component, and then call the “startconnect” method of the fileexplorerclient component to open the connection

You can also use a simple UI that comes with this tool to add to any game object of the projectFileExplorerWindowComponents (no need to add additional components at this time)FileExplorerClientComponents)

The connection window will open automatically after the game starts

Function list

Please check the detailed picture and text function introductionWorking with documents

  • Through “goto” in the status bar, you can directly jump to some predefined paths of unity
  • By clicking the path bar, you can open the input box to enter the path directly, jump or copy the current path
  • Right click the selected folder or file to support downloading
  • Right click the selected folder or file to support deletion
  • Right click the blank area to support uploading folders or files
  • Right click the blank area to refresh the contents of the current path
  • It supports dragging folders or files directly from the unity project window to this tool for uploading
  • It supports dragging folders or files directly from the system file browser to upload to this tool
  • Through the “status” panel of this tool, you can view the connection status and information of connected devices, which can be used to identify which device is connected
  • Through configurationBeforeUploadAttributeCustomize additional operations during uploading, such as automatic encryption when uploading Lua code
  • Through configurationCustomMenuAttributeCustom action menu

link

Recommended Today

5、 Subquery

(1) Guan Yu’s bank card number is “6225547858741263”. You can query the bank card information with more balance than Guan Yu, and display the card number, ID card, name and balance. –Scheme I: declare @gyBalance money select @gyBalance = (select CardMoney from BankCard where CardNo=’6225547858741263′) Select cardno, account code, ID card, realName name, cardmoney balance […]