Giter Site home page Giter Site logo

ds_ui's Introduction

DsUi

适用版本: Godot Mono 4.x


DsUi是一款用于Godot Mono快速开发Ui的插件, 核心功能如下:

  • 提供Ui管理器UiManager.cs, 负责管理Ui生命周期
  • 根据Ui场景自动生成Ui节点属性代码, 支持生成唯一名称节点属性
  • 根据Ui场景文件自动生成打开Ui/关闭Ui/获取实例的函数
  • 支持Ui嵌套, 提供动态打嵌套Ui函数和场景内静态嵌套Ui功能
  • 提供Ui网格布局组件(UiGrid.cs), 更方便管理单个Cell
  • 支持类似Unity中的协程函数

使用该插件的意义

众所周知, 使用C#开发Godot游戏, 无法像GDS那样有原生特性支持($+节点名称), C#获取节点必须使用GetNode()函数, 或者[Export()]节点属性, 再到编辑器中拖拽赋值. 这样编写很麻烦, 如果使用GetNode()来获取节点, 场景中该节点移动位置或者更改名称, 那么GetNode()就无法获取到该节点, 这个时候就需要手动更改传入的节点路径, 当项目小还比较好改, 但是大项目重构节点, 那么代码需要更改的地方就非常多, 而且无法快速定位到哪些GetNode()函数需要更改.
在开发Ui时, 因为需要频繁获取节点, 上面的问题就会被放大
DsUi插件就是为了解决这个问题, 在编辑场景完成后动态生成节点代码, 这样代码中如果有引用更改, 就可以根据报错立刻定位到需要修改的位置 (不怕编译时报错, 就怕运行时才报错)


快速开始

  1. 安装插件

    • 下载源代码后, 将addons/ds_ui复制到你的工程的addons/ds_ui目录下
    • 点击编辑器右上角的Build
    • 项目/项目设置/插件中启用Ds_Ui插件
      如果插件正常被启用, 则可以在项目/工具目录下看到创建Ui, 重新生成当前Ui代码, 重新生成UiManager中的Ui函数这三个选项
      img.png
  2. 快速创建Ui

    • 点击项目/工具/创建Ui, 输入Ui名称, 点击创建, 教程Ui名称以MyUi为例
      img.png
      创建成功后会自动创建Ui场景和Ui脚本文件
    • 此时编辑Ui场景, 插件会实时生成对应的Ui节点代码
      gif.gif
    • 代码操作Ui
    //获取指定节点, 命名规则: L_ + 节点名称
    var button = L_Control.L_Button;
    //注意, 此时的对象是包裹类型, 需要从 Instance 属性中获取原生节点对象
    button.Instance.Pressed += () =>
    {
        
    };
    
    //如果 Button 是场景中唯一名称的节点, 那么获取 Button 节点可以使用 S_ + 节点名称 缩写方式
    S_Button.Instance.Pressed += () =>
    {
        
    };
    • 创建Ui时会在UiManager下自动创建打开Ui的函数, 那么打开Ui只需要调用以下代码
    UiManager.Open_MyUi();
    • 最后运行效果
      img.png
  3. 配置项

    • 配置文件路径: addons/ds_ui/DsUiConfig.cs

样例

本仓库包含样例代码, 入口文件为example/Example.cs
视频教程: https://www.bilibili.com/video/BV1Xp4y1c7p9

ds_ui's People

Contributors

xlljc avatar

Stargazers

 avatar  avatar 深淵の鴿子 avatar  avatar 陈不进 avatar 霧雨烨 avatar  avatar  avatar nppe6 avatar  avatar  avatar  avatar UndeadSheep avatar  avatar  avatar 布丁w avatar Kamisora avatar tang avatar  avatar CAB1 avatar 莫笑 avatar Litlot avatar  avatar  avatar xiejiang avatar  avatar  avatar  avatar List.Coder avatar Colby Weinman avatar  avatar Flamesky avatar  avatar

Watchers

tang avatar  avatar  avatar

Forkers

40412440

ds_ui's Issues

[Enhance] Add setting.

Now, if click create new ui, the scene file will save to src/ui.
Need a setting panel to modify this action.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.