public CGameplayTagNode(string InTag, CGameplayTagNode InParentNode) { Tag = InTag; ParentNode = InParentNode; List <CGameplayTag> ParentCompleteTags = new List <CGameplayTag>(); CGameplayTagNode CurNode = InParentNode; // 只要有父亲node while (CurNode.IsValid()) { ParentCompleteTags.Add(CurNode.GetCompleteTag()); CurNode = CurNode.GetParentTagNode(); } //完整的tag名称 string CompleteTagString = InTag; if (ParentCompleteTags.Count > 0) { CompleteTagString = string.Format("{0}.{1}", ParentCompleteTags[0].GetTagName(), InTag); } CGameplayTag tag = new CGameplayTag(CompleteTagString); CompleteTagWithParents.GameplayTags.Add(tag); CompleteTagWithParents.ParentTags.AddRange(ParentCompleteTags); }
/** * Helper function to insert a tag into a tag node array * * @param Tag Tag to insert * @param ParentNode Parent node, if any, for the tag * @param NodeArray Node array to insert the new node into, if necessary (if the tag already exists, no insertion will occur) * @return Index of the node of the tag */ private int InsertTagIntoNodeArray(string Tag, CGameplayTagNode ParentNode, List <CGameplayTagNode> NodeArray) { int InsertionIdx = -1; int WhereToInsert = -1; // See if the tag is already in the array for (int CurIdx = 0; CurIdx < NodeArray.Count; ++CurIdx) { var node = NodeArray[CurIdx]; if (!node.IsValid()) { continue; } if (node.GetSimpleTagName() == Tag) { InsertionIdx = CurIdx; break; } if (WhereToInsert == -1) { int v = string.CompareOrdinal(node.GetSimpleTagName(), Tag); // Insert new node before this if (v > 0) { WhereToInsert = CurIdx; } } } if (InsertionIdx != -1) { return(InsertionIdx); } // Insert at end if (WhereToInsert == -1) { WhereToInsert = NodeArray.Count; } // Don't add the root node as parent CGameplayTagNode TagNode = new CGameplayTagNode(Tag, ParentNode != GameplayRootTag ? ParentNode : null); // Add at the sorted location NodeArray.Insert(WhereToInsert, TagNode); InsertionIdx = WhereToInsert; CGameplayTag GameplayTag = TagNode.GetCompleteTag(); GameplayTagNodeMap.Add(GameplayTag.GetTagName(), TagNode); return(1); }