官方为什么不出套常用组件库?全要自己造轮子!!!

虚拟列表,tabbar,切换按钮,combobox下拉列表,这些常用了为什么没有官方库呀:rofl:

自己写了个SwitchButton的组件

import { _decorator, Component, Node, CCBoolean, EventHandler, log } from 'cc';
import { DEV } from 'cc/env';
const { ccclass, property } = _decorator;
/**
 * 用法:
 * 1.创建一个空节点(可命名为:btnSwitch),并添加SwitchButton组件
 * 2.在btnSwitch节点下添加两个子节点,并命名分别为:on、off,他们分别对应开和关状态
 * 3.在btnSwitch节点上侦听click事件,并添加事件处理函数
 */
@ccclass('SwitchButton')
export class SwitchButton extends Component {
    // @property
    private _isChecked: boolean = false;
    @property({
        type: CCBoolean,
        tooltip: DEV && '是否为开启状态'
    })
    public set isChecked(value: boolean) {
        if (value != null) this._isChecked = value;
        this._updateCheckMark();
    }
    public get isChecked() {
        return this._isChecked;
    }

    @property({
        type: EventHandler,
        tooltip: DEV && 'i18n:COMPONENT.button.click_events',
    })
    public checkEvents:EventHandler = new EventHandler();

    onLoad() {
        this._updateCheckMark();
    }

    onEnable() {
        this.node.on(Node.EventType.TOUCH_END, this.toggle, this);
    }

    onDisable() {
        this.node.off(Node.EventType.TOUCH_END, this.toggle, this);
    }

    toggle(event) {
        this.isChecked = !this.isChecked;
        this._updateCheckMark();
        if (this.checkEvents) {
            EventHandler.emitEvents([this.checkEvents], this, this.isChecked);
            this.node.emit("click", this.isChecked);
        }
    }

    _updateCheckMark() {
        let nodeON:Node = this.node.getChildByName('on');
        let nodeOFF:Node = this.node.getChildByName('off');
        if (nodeON) {
            nodeON.active = !!this.isChecked;
        }else{
            log('Node on is unexist');
        }
        if (nodeOFF) {
            nodeOFF.active = !!!this.isChecked;
        }else{
            log('Node off is unexist');
        }
    }
}

image

没人维护.

因为cocos creator之类的游戏引擎,本质上是渲染引擎。而不是纯粹地为了开发游戏而制作的工具。godot火很大一方面就是面向游戏开发者,大量ui节点几乎让新人开发者完全免去了自己造轮子的必要。
官方搞这些很费时间,人手不够。
如果有很多ui方面的需求,个人建议,用fariygui

1赞

我看寻道大千好像是引入fairygui

这就是引擎得厉害之处

官方可能想让社区生态做,但版本变化太快,小功能也很少有人一直维护下去。现在就是死循环

2赞

现在store能卖钱了,官方更不可能自己出了,哎,使用钞能力吧

现在好多都上store,但store上面的产品质量也是参差不齐

1赞

哥们也是前端吧,我也是习惯了 element antd 啥的,ε=(´ο`*)))唉

我是游戏前端,原来是用白鹭引擎做游戏,白鹭引擎把自己玩死了。只好到cocos碗里来了,用cocos做游戏过程中发现它好多游戏中常用ui功能都要自己去封装。

也就少量组件没有

说实话有些组件官方不一定有你写的好

还不如自己写了

让用户永远都有做不完的事 才是能让这个工具最长寿的秘诀