105 lines
2.5 KiB
C#
105 lines
2.5 KiB
C#
using cfg.RedPoint;
|
||
using Debug = DebugUtil;
|
||
|
||
public partial class RedPointManager
|
||
{
|
||
public 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, object param = null)
|
||
{
|
||
var parent = GetNodeByID(parentID);
|
||
return AddDynamicNode(nodeType, parent, param);
|
||
}
|
||
|
||
public RedPointNode AddDynamicNode(NodeType nodeType, RedPointNode parent, object param = null)
|
||
{
|
||
_allocID++;
|
||
var node = GetANode(_allocID, nodeType, param);
|
||
if (node == null)
|
||
{
|
||
Debug.LogError($"添加动态节点失败!nodeType:{nodeType}");
|
||
return null;
|
||
}
|
||
|
||
node.Init();
|
||
|
||
if (parent != null)
|
||
{
|
||
node.parent = parent;
|
||
parent.AddChild(node);
|
||
parent.RefreshCount();
|
||
}
|
||
else
|
||
{
|
||
_treeRoots.Add(node);
|
||
}
|
||
|
||
_nodeDic.Add(_allocID, node);
|
||
return node;
|
||
}
|
||
|
||
public void ChangeNodeParent(RedPointNode node, RedPointNode parent)
|
||
{
|
||
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)
|
||
{
|
||
Debug.LogError("删除动态节点失败! node非法!");
|
||
return;
|
||
}
|
||
|
||
_nodeDic.Remove(_allocID);
|
||
if (node.parent == null)
|
||
_treeRoots.Remove(node);
|
||
else
|
||
{
|
||
node.parent.RemoveChild(node);
|
||
node.parent.RefreshCount();
|
||
}
|
||
|
||
if (isRecursive)
|
||
{
|
||
foreach (RedPointNode childNode in node)
|
||
{
|
||
RemoveDynamicNode(childNode);
|
||
}
|
||
}
|
||
|
||
node.Dispose();
|
||
}
|
||
|
||
public void RemoveDynamicNode(int id)
|
||
{
|
||
var node = GetNodeByID(id);
|
||
RemoveDynamicNode(node);
|
||
}
|
||
} |