Skip to content

基于Unity的轻量级红点提示系统,支持多样化红点类型和树形节点管理 | A lightweight red dot notification system for Unity with diverse dot types and tree-based node management

License

Notifications You must be signed in to change notification settings

qqw1584913629/RedDotSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔴 RedDotSystem

红点提示系统

一个基于 Unity 开发的轻量级、高扩展性的红点提示系统

English Document

License

演示

✨ 特性

🎯 多样化的红点类型

  • 普通红点 - 常规提示
  • 数值红点 - 显示具体数量
  • 新功能红点 - 特殊样式提示
  • 提示红点 - 轻量提醒
  • 重要红点 - 突出显示

🌲 树形节点管理

  • 层级结构 - 支持多父子节点关系
  • 状态传递 - 自动向上传递状态
  • 灵活配置 - 支持多样化节点设置

🛠 开发友好

  • 简单 API - 易于理解和使用
  • 示例场景 - 完整的演示项目
  • 可视化工具 - 便捷的配置界面

📁 项目结构

Assets/
├── Configs/        # 配置文件
│   └── RedDot/     # 红点系统配置
├── Editor/         # 编辑器扩展工具
│   └── RedDot/     # 红点配置工具
├── Prefabs/        # 预制体资源
│   ├── RedDotItem.prefab          # 基础红点
│   ├── RedDotItem_Free.prefab     # 免费标签
│   └── RedDotItem_New.prefab      # 新功能标签
├── Resources/      # 资源文件
├── Scenes/         # 示例场景
└── Scripts/        # 核心代码
    └── RedDot/     # 红点系统实现

🚀 安装步骤

📦 方式一:使用 Unity Package

  1. 前往 Releases 页面下载
  2. 选择最新版本的 RedDotSystem.unitypackage
  3. 将文件导入您的 Unity 项目中:
    • 双击下载的文件
    • 或在 Unity 中选择 Assets > Import Package > Custom Package

⚡ 方式二:克隆项目

# 克隆仓库
git clone https://github.com/qqw1584913629/RedDotSystem.git

# 或使用 SSH
git clone git@github.com:qqw1584913629/RedDotSystem.git

在 Unity Hub 中打开项目后,查看示例场景:

📂 Assets/Scenes/RedDotSampleScene.unity

🔧 配置说明

红点类型配置

通过 RedDotKeyAsset 配置红点的基础信息:

参数 说明
id 红点唯一标识
des 红点描述说明

红点系统示例

红点关系配置

通过 RedDotConfigAsset 配置红点的父子关系和显示类型:

参数 说明
key 对应 RedDotKeyAsset 中的 id
parentList 父节点列表
flags 红点显示类型(Default/Number/New/Tips/Important)

红点系统示例

🔨 编辑器工具

RedDotKey Editor

路径:Tool/RedDot/RedDotKey Editor

  • 配置红点基础信息
  • 自动生成红点枚举定义

红点系统示例

RedDotConfig Editor

路径:Tool/RedDot/RedDotConfig Editor

  • 可视化配置红点关系

红点系统示例

红点系统示例

📝 使用示例

无需每个红点都要手动初始化,只需要在需要的时候设置数量即可。

// 初始化红点信息
public class RedDotSingleton : MonoBehaviour
{
    private static RedDotSingleton _instance;
    public static RedDotSingleton Instance => _instance;
    public delegate void OnRdCountChange(RedDotNode node);
    public Dictionary<ERedDotKeyType, RedDotNode> AllRedDotNodes = new Dictionary<ERedDotKeyType, RedDotNode>();
    public RedDotConfigAsset _config;
    public void Awake()
    { 
        if (_instance == null)
            _instance = this;
        // TODO 根据自己项目的资源管理进行加载就好 这里演示直接Inspector拖动了
        // _config = Resources.Load<RedDotConfigAsset>(nameof(RedDotConfigAsset));
        InitRedDotTreeNode();
    }
    public void InitRedDotTreeNode()
    {
        // 创建所有节点
        foreach (var config in _config.AllRedDotConfigList)
        {
            if (!AllRedDotNodes.ContainsKey(config.key))
            {
                var node = new RedDotNode { rdType = config.key };
                AllRedDotNodes.Add(config.key, node);
            }
        }

        // 建立父子关系
        foreach (var config in _config.AllRedDotConfigList)
        {
            var node = AllRedDotNodes[config.key];
            foreach (var parentKey in config.parentList)
            {
                if (AllRedDotNodes.TryGetValue(parentKey, out var parentNode))
                {
                    node.parents.Add(parentNode);
                    parentNode.rdChildrenDic[config.key] = node;
                }
            }
        }
    }
    //...其余代码
}

开发过程中,只需要维护红点的数量即可,其他的不需要关注。

// 设置一个普通红点
RedDotSingleton.Instance.Set(ERedDotKeyType.Key1, 1, RedDotFlags.Default);

// 设置一个数值红点
RedDotSingleton.Instance.Set(ERedDotKeyType.Key1, 1, RedDotFlags.Number);

💡 提示:RedDotItem.cs 会在 Start 方法中自动设置订阅红点的事件,只需将其挂载在需要显示红点的物体上即可。

红点系统示例

⚠️ 注意事项

  1. 避免红点配置中的循环引用
  2. 合理规划红点层级结构,避免层级过深
  3. 及时清理不需要的红点配置
  4. 定期维护和更新红点状态

📋 开发计划

  • 想到再说

🔤 字体

本项目使用 Maple Font 字体。这是一款开源的等宽编程字体,具有圆角、连字和控制台图标等特性。

About

基于Unity的轻量级红点提示系统,支持多样化红点类型和树形节点管理 | A lightweight red dot notification system for Unity with diverse dot types and tree-based node management

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published