Remote File Explorer是一个跨平台的远程文件浏览器,用户通过Unity Editor就能操作运行在手机上的游戏或是应用的的目录文件。比如当项目打包运行到设备上时,可通过Remote File Explorer直接浏览设备上的目录文件,并进行下载,上传,删除等操作。尤其是Unity+Lua开发环境下的调试利器,当然,这里的调试不是指代码的逐行调试,而是泛指定位排查问题
在很多场景下利用Remote File Explorer都可以极大的提高开发调试效率。例如:
接下来,将以一些具体的案例,来演示Remote File Explorer工具的使用。下面用例的代码都可以在Remote File Explorer Demo找到
local obj = CS.UnityEngine.Object.FindObjectOfType(typeof(CS.Game.ChangeTextColor)) local textComponent = obj:GetComponent(typeof(CS.UnityEngine.UI.Text)); textComponent.text = "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" 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)
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"); // 将log文件下载到本地 } }
本工具是采用Unity的包形式,可以通过Unity Package Manager直接安装
这里介绍两种常用方式
https://github.com/iwiniwin/unity-remote-file-explorer.git
,单击"Add"按钮后完成安装详细安装方式可以查看使用文档,更多将本工具作为包进行安装的方式可查看Unity官方文档
安装本工具后,可通过"Window > Analysis > Remote File Explorer"打开本工具窗口,将自动启动服务器
给项目的任意游戏对象添加FileExplorerClient组件
如果是固定连接到某台机器上,可直接通过Inspector面板在"Host"域输入这台机器的IP地址,然后勾选"Connect Automatically",则会在应用启动时自动连接
如果希望应用启动后能主动选择连接到哪台机器,则可在Debug模式下封装一套简单的UI,使开发人员能够输入想要连接到的IP地址。例如在自己的菜单中添加一个条目或按钮,点击后弹出输入窗口。在成功获取到的IP地址后,将其赋值给FileExplorerClient组件的"Host"属性,然后调用FileExplorerClient组件的"StartConnect"方法开启连接
也可以使用本工具自带的一个简易UI,给项目的任意游戏对象添加FileExplorerWindow组件(此时不用再额外添加FileExplorerClient组件)
游戏启动后将自动打开连接窗口
详细的图文功能介绍请查看使用文档