npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gongxh/bit-condition

v0.0.12

Published

基于creator的条件系统库

Readme

bit-condition

条件显示系统,用于实现 UI 红点、解锁提示等动态显示功能。

简介

bit-condition 是基于 Cocos Creator 的条件显示系统,提供灵活的条件判断和自动更新机制。适用于需要根据游戏数据动态控制 UI 显示的场景,如红点系统、功能解锁、任务提示等。

核心特性

  • 🎯 条件变化自动通知关联节点
  • 🔄 支持 Any(任一)和 All(全部)条件组合模式
  • 🎨 装饰器注册条件类型
  • ⚡ 定时批量更新,性能优化
  • 🔌 继承基类轻松扩展自定义条件

安装

npm install @gongxh/bit-condition

使用说明

条件模块 (ConditionModule)

场景中的条件系统管理组件,负责定时更新所有条件。

配置属性

  • updateDeltaTime - 条件更新间隔(秒,默认 0.3)

使用方式

  • 在场景根节点或管理节点上添加 ConditionModule 组件
  • 组件会自动初始化所有注册的条件

条件基类 (ConditionBase)

所有条件的抽象基类,需要继承并实现。

必须实现的方法

  • onInit() - 条件初始化,注册监听等
  • evaluate() - 判断条件是否满足,返回 boolean

可调用的方法

  • tryUpdate() - 手动触发条件更新

属性

  • type - 条件类型(自动设置)

条件节点 (ConditionNode)

UI 节点上的组件,用于响应条件变化。

配置属性

  • conditionTypes - 需要监听的条件类型列表
  • modeType - 条件模式(Any 或 All)
  • onNotify - 条件变化回调函数 (canShow: boolean) => void

使用方式

  • 在需要动态显示的 UI 节点上添加 ConditionNode 组件
  • 配置条件类型和模式
  • 设置回调函数处理显示逻辑

条件模式 (ConditionMode)

  • ConditionMode.Any (0) - 任意一个条件满足即可
  • ConditionMode.All (1) - 所有条件都必须满足

条件管理器 (ConditionManager)

全局条件管理,提供静态方法。

主要方法

  • initCondition() - 初始化所有条件(由 ConditionModule 自动调用)
  • _addUpdateCondition(conditionType) - 手动标记条件需要更新
  • _nowUpdateConditionNode(node) - 立即更新指定节点

装饰器

使用 @condition(conditionType) 装饰器注册条件类:

import { condition, ConditionBase } from '@gongxh/bit-condition';

@condition(ConditionType.NewMail)
export class NewMailCondition extends ConditionBase {
    protected onInit(): void {
        // 初始化逻辑
    }
    
    protected evaluate(): boolean {
        // 条件判断逻辑
        return MailSystem.hasUnreadMail();
    }
}

典型使用流程

  1. 添加模块 - 在场景中添加 ConditionModule 组件
  2. 定义条件类型 - 使用枚举定义条件类型
  3. 实现条件类 - 继承 ConditionBase 并使用装饰器注册
  4. 添加条件节点 - 在 UI 节点上添加 ConditionNode 组件
  5. 触发更新 - 数据变化时调用 ConditionManager._addUpdateCondition()

详细 API 请查看 bit-condition.d.ts 类型定义文件。

依赖

许可证

MIT License

作者

bit老宫 (gongxh)
邮箱: [email protected]

源码仓库