71 lines
1.5 KiB
C#
71 lines
1.5 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2021-03-10
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "RedPointNode" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace G
|
|
{
|
|
/// <summary>
|
|
/// 类功能描述
|
|
/// </summary>
|
|
public class RedPointNode
|
|
{
|
|
public string nodeName;
|
|
public RedPointNode parentNode;
|
|
public int pointNum = 0;
|
|
public readonly Dictionary<string, RedPointNode> childs = new Dictionary<string, RedPointNode>();
|
|
|
|
public RedPointProxy.OnRedpointBroadcast numChangeFunc; // 发生变化的回调函数
|
|
|
|
public void SetRedPointNum(int num)
|
|
{
|
|
if (childs.Count > 0)
|
|
{
|
|
return;
|
|
//throw new Exception("红点数量只能设置最后一个子节点");
|
|
}
|
|
pointNum = num;
|
|
|
|
//广播
|
|
numChangeFunc?.Invoke(num);
|
|
if (parentNode != null)
|
|
{
|
|
parentNode.ChangeRedPointNum();
|
|
}
|
|
}
|
|
|
|
public void ChangeRedPointNum()
|
|
{
|
|
int num = 0;
|
|
foreach (var node in childs.Values)
|
|
{
|
|
num += node.pointNum;
|
|
}
|
|
|
|
pointNum = num;
|
|
//广播
|
|
numChangeFunc?.Invoke(num);
|
|
|
|
if (parentNode != null)
|
|
parentNode.ChangeRedPointNum();
|
|
}
|
|
|
|
public void SyncRedPoint()
|
|
{
|
|
//广播
|
|
numChangeFunc?.Invoke(pointNum);
|
|
}
|
|
}
|
|
}
|