5

【Unity 框架】 QFramework v1.0 使用指南 工具篇: 16. LiveCodingKit 写代码不用停...

 1 year ago
source link: https://www.cnblogs.com/liangxiegame/p/17098031.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【Unity 框架】 QFramework v1.0 使用指南 工具篇: 16. LiveCodingKit 写代码不用停止运行的利器 | Unity 游戏框架 | Unity 游戏开发 | Unity 独立游戏

我们在用 Unity 开发的时候,每次编写或修改一点代码就需要进行 停止运行->编写代码->等待编译->运行游戏。

而在很多情况下这个过程是一个比较耗神的过程,因为开发者需要等待,还需要动手操作。

在笔者体验过 GameMakerStudio 的 GMLive 插件后,发现不停止运行就可以直接查看代码编写的结果的体验非常丝滑。

于是笔者就在 QFramework 中写了一个类似的方案 LiveCodingKit。

使用方式很简单,首先在 QFramework 编辑器中可以看到 LiveCodingKit 面板,如下:

确保开启是勾选状态。

然后根据自己需要选择当编译完成时,对应的操作,一般情况下重新加载当前场景就够用了。

当然如果是场景和场景间有依赖关系,那么可以选择重启游戏。

然后随意运行一个带有脚本的场景,笔者选择的是 QFramework 自带的示例,如下:

然后新增代码如下:

public partial class UIBasicPanel : UIPanel
{
   protected override void OnInit(IUIData uiData = null)
   {
      mData = uiData as UIBasicPanelData ?? new UIBasicPanelData();
      
      BtnStart.onClick.AddListener(() =>
      {
         Debug.Log("开始游戏");
      });

      BtnStart.Rotation(Quaternion.Euler(0, 0, 90)); // 新增代码
   }
   

之后回到 Unity 直接等待编译(不用停止运行)。

编译完成后结果如下:

OK,结果没问题。

这就是 LiveCodingKit 的介绍,当你需要在代码中调整一些数值,写 OnGUI 代码,会非常方便,当然也有一些不适用的情况,这个就需要大家自行体验了。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK