/// <summary> /// 获取子节点 /// </summary> public RedDotTreeNode GetChild(RangeString key) { if (_children == null) { return(null); } _children.TryGetValue(key, out RedDotTreeNode child); return(child); }
/// <summary> /// 获取子节点,如果不存在则添加 /// </summary> public RedDotTreeNode GetOrAddChild(RangeString key) { RedDotTreeNode child = GetChild(key); if (child == null) { child = AddChild(key); } return(child); }
/// <summary> /// 添加子节点 /// </summary> public RedDotTreeNode AddChild(RangeString key) { if (_children == null) { _children = new Dictionary <RangeString, RedDotTreeNode>(); } else if (_children.ContainsKey(key)) { throw new Exception("子节点添加失败,不允许重复添加:" + FullPath); } RedDotTreeNode child = new RedDotTreeNode(key.ToString(), this); _children.Add(key, child); RedDotMananger.Instance.onNodeNumChangedCallback?.Invoke(); return(child); }
/// <summary> /// 移除子节点 /// </summary> public bool RemoveChild(RangeString key) { if (_children == null || _children.Count == 0) { return(false); } RedDotTreeNode child = GetChild(key); if (child != null) { //子节点被删除 需要进行一次父节点刷新 RedDotMananger.Instance.MarkDirtyNode(this); _children.Remove(key); RedDotMananger.Instance.onNodeNumChangedCallback?.Invoke(); return(true); } return(false); }