NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/RedPoint/RedPointManager.Dynamic.cs

73 lines
1.8 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using cfg.RedPoint;
using UnityEngine;
using Debug = DebugUtil;
public partial class RedPointManager
{
const int RED_POINT_NODE_DYNAMIC_ID_START = 10000;
private int _allocID = RED_POINT_NODE_DYNAMIC_ID_START;
public RedPointNode AddDynamicNode(NodeType nodeType, int parentID)
{
_allocID++;
var node = GetANode(_allocID, nodeType);
if (node == null)
{
Debug.LogError($"添加动态节点失败!nodeType:{nodeType}");
return null;
}
if (parentID != RED_POINT_NODE_ROOT_FLAG)
{
var parent = GetNodeByID(parentID);
if (parent != null)
{
node.parent = parent;
parent.AddChild(node);
parent.SendChange();
}
else
{
Debug.LogError($"找不到父节点,parent id:{parentID}");
return null;
}
}
else
{
_treeRoots.Add(node);
}
_nodeDic.Add(_allocID, node);
node.Init();
return node;
}
public void RemoveDynamicNode(RedPointNode node)
{
if (node == null || node.ID <= RED_POINT_NODE_DYNAMIC_ID_START)
{
Debug.LogError("删除动态节点失败! node非法");
return;
}
_nodeDic.Remove(_allocID);
if (node.parent == null)
_treeRoots.Remove(node);
else
{
node.parent.RemoveChild(node);
node.parent.SendChange();
}
node.ForeachChild(RemoveDynamicNode);
node.Dispose();
node.SendChange();
}
public void RemoveDynamicNode(int id)
{
var node = GetNodeByID(id);
RemoveDynamicNode(node);
}
}