2023-10-19 15:00:19 +08:00
|
|
|
|
using cfg.RedPoint;
|
|
|
|
|
|
using Debug = DebugUtil;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class RedPointManager
|
|
|
|
|
|
{
|
2023-11-02 20:02:10 +08:00
|
|
|
|
public const int RED_POINT_NODE_DYNAMIC_ID_START = 10000;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
|
|
private int _allocID = RED_POINT_NODE_DYNAMIC_ID_START;
|
|
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
public RedPointNode AddDynamicNode(NodeType nodeType, int parentID, object param = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var parent = GetNodeByID(parentID);
|
|
|
|
|
|
return AddDynamicNode(nodeType, parent, param);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RedPointNode AddDynamicNode(NodeType nodeType, RedPointNode parent, object param = null)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
_allocID++;
|
2023-11-02 20:02:10 +08:00
|
|
|
|
var node = GetANode(_allocID, nodeType, param);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
if (node == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError($"添加动态节点失败!nodeType:{nodeType}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
node.Init();
|
|
|
|
|
|
|
|
|
|
|
|
if (parent != null)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2023-11-02 20:02:10 +08:00
|
|
|
|
node.parent = parent;
|
|
|
|
|
|
parent.AddChild(node);
|
|
|
|
|
|
parent.RefreshCount();
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_treeRoots.Add(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_nodeDic.Add(_allocID, node);
|
|
|
|
|
|
return node;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-02 20:02:10 +08:00
|
|
|
|
public void ChangeNodeParent(RedPointNode node, RedPointNode parent)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
2023-11-02 20:02:10 +08:00
|
|
|
|
if (node == null || !node.IsDynamic)
|
|
|
|
|
|
{
|
|
|
|
|
|
DebugUtil.LogError($"cant change parent,node is Invalid!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var oldParent = node.parent;
|
|
|
|
|
|
if (oldParent == parent)
|
|
|
|
|
|
return;
|
|
|
|
|
|
if (oldParent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
oldParent.RemoveChild(node);
|
|
|
|
|
|
oldParent.RefreshCount();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
node.parent = parent;
|
|
|
|
|
|
if (parent != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parent.AddChild(node);
|
|
|
|
|
|
parent.RefreshCount();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_treeRoots.Add(node);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveDynamicNode(RedPointNode node, bool isRecursive = true)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (node == null || !node.IsDynamic)
|
2023-10-19 15:00:19 +08:00
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("删除动态节点失败! node非法!");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_nodeDic.Remove(_allocID);
|
|
|
|
|
|
if (node.parent == null)
|
|
|
|
|
|
_treeRoots.Remove(node);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
node.parent.RemoveChild(node);
|
2023-11-02 20:02:10 +08:00
|
|
|
|
node.parent.RefreshCount();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isRecursive)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (RedPointNode childNode in node)
|
|
|
|
|
|
{
|
|
|
|
|
|
RemoveDynamicNode(childNode);
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2023-11-02 20:02:10 +08:00
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
|
node.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveDynamicNode(int id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var node = GetNodeByID(id);
|
|
|
|
|
|
RemoveDynamicNode(node);
|
|
|
|
|
|
}
|
2023-11-02 20:02:10 +08:00
|
|
|
|
}
|