Пример #1
0
        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);
        }
Пример #2
0
        /**
         * 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);
        }
Пример #3
0
        /// <summary>
        /// 在node树中查找传入tag对应的container, 此container仅包含传入的tag
        /// </summary>
        public CGameplayTagContainer GetSingleTagContainer(CGameplayTag GameplayTag)
        {
            CGameplayTagNode node = FindTagNode(GameplayTag);

            if (node.IsValid())
            {
                return(node.GetSingleTagContainer());
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// 获取传入tag所有的子tag组成的container, 不包含传入tag
        /// 例如传入a.b, 则返回的conatiner包含a.b.c, a.b.d, a.b.c.e
        /// </summary>
        public CGameplayTagContainer RequestGameplayTagChildren(CGameplayTag GameplayTag)
        {
            CGameplayTagContainer TagContainer = new CGameplayTagContainer();

            CGameplayTagNode GameplayTagNode = FindTagNode(GameplayTag);

            if (GameplayTagNode.IsValid())
            {
                AddChildrenTags(TagContainer, GameplayTagNode, true, true);
            }
            return(TagContainer);
        }
Пример #5
0
        /**
         * 返回直系的父亲
         * calling on x.y will return x
         */
        public CGameplayTag RequestGameplayTagDirectParent(CGameplayTag GameplayTag)
        {
            CGameplayTagNode GameplayTagNode = FindTagNode(GameplayTag);

            if (!GameplayTagNode.IsValid())
            {
                return(null);
            }

            var parent = GameplayTagNode.GetParentTagNode();

            if (parent.IsValid())
            {
                return(parent.GetCompleteTag());
            }
            return(null);
        }
Пример #6
0
        /** 构建整个 tag 树*/
        public void ConstructGameplayTagTree()
        {
            if (!GameplayRootTag.IsValid())
            {
                return;
            }

            CGameplayTagNode currNode = GameplayRootTag;

            foreach (var item in GameplayTagTables)
            {
                var subTags = item.SubTags;
                for (int i = 0; i < subTags.Count; i++)
                {
                    List <CGameplayTagNode> childTags = currNode.GetChildTagNodes();
                    int insertIndex = InsertTagIntoNodeArray(subTags[i], currNode, childTags);
                    currNode = childTags[insertIndex];
                }
            }
        }
Пример #7
0
        /// <summary>
        /// 将GameplayTagNode的children node对应的tag添加到TagContainer中去
        /// RecurseAll表示在树状节点中, 就添加一层child还是循环一直往下找
        /// </summary>
        private void AddChildrenTags(CGameplayTagContainer TagContainer, CGameplayTagNode GameplayTagNode,
                                     bool RecurseAll = true, bool OnlyIncludeDictionaryTags = false)
        {
            if (!GameplayTagNode.IsValid())
            {
                return;
            }

            var ChildrenNodes = GameplayTagNode.GetChildTagNodes();

            foreach (CGameplayTagNode ChildNode in ChildrenNodes)
            {
                if (!ChildNode.IsValid())
                {
                    continue;
                }

                TagContainer.AddTag(ChildNode.GetCompleteTag());
                if (RecurseAll)
                {
                    AddChildrenTags(TagContainer, ChildNode, true, OnlyIncludeDictionaryTags);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// 找到tag对应的node
        /// </summary>
        public CGameplayTagNode FindTagNode(CGameplayTag GameplayTag)
        {
            CGameplayTagNode Node = GameplayTagNodeMap[GameplayTag.GetTagName()];

            return(Node);
        }