コード例 #1
0
        /**
         * 添加TagToAdd到container, 但会删除gameplaytags列表中TagToAdd相关的parent tag
         * 如果TagToAdd已经在gameplaytags列表中, 就不会被添加
         */
        public bool AddLeafTag(CGameplayTag TagToAdd)
        {
            // Check tag is not already explicitly in container
            if (HasTagExact(TagToAdd))
            {
                return(true);
            }

            // If this tag is parent of explicitly added tag, fail
            if (HasTag(TagToAdd))
            {
                return(false);
            }

            CGameplayTagContainer tagToAddContainer = CGameplayTagsManager.Instance.GetSingleTagContainer(TagToAdd);

            if (tagToAddContainer == null)
            {
                return(false);
            }

            // Remove any tags in the container that are a parent to TagToAdd
            foreach (CGameplayTag ParentTag in tagToAddContainer.ParentTags)
            {
                if (HasTagExact(ParentTag))
                {
                    RemoveTag(ParentTag);
                }
            }

            // Add the tag
            AddTag(TagToAdd);
            return(true);
        }
コード例 #2
0
ファイル: CGameplayTagNode.cs プロジェクト: yimogod/DarkRoom
        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);
        }
コード例 #3
0
 /**
  * 不做唯一性判断, 直接添加tag
  */
 public void AddTagFast(CGameplayTag TagToAdd)
 {
     if (!TagToAdd.IsValid())
     {
         return;
     }
     GameplayTags.Add(TagToAdd);
     AddParentsForTag(TagToAdd);
 }
コード例 #4
0
        /**
         * 精确包含. 只判断GameplayTags列表
         *{"A.1"}.HasTagExact("A") will return False
         */
        public bool HasTagExact(CGameplayTag TagToCheck)
        {
            if (!TagToCheck.IsValid())
            {
                return(false);
            }

            // Only check check explicit tag list
            return(GameplayTags.Contains(TagToCheck));
        }
コード例 #5
0
        /// <summary>
        /// 返回包含本tag以及所有父亲tag的container
        /// 比如传入的a.b.c 那么 此container会包含a, a.b, a.b.c
        /// </summary>
        public CGameplayTagContainer RequestGameplayTagParents(CGameplayTag GameplayTag)
        {
            CGameplayTagContainer container = GetSingleTagContainer(GameplayTag);

            if (container != null)
            {
                return(container.GetGameplayTagParents());
            }
            return(null);
        }
コード例 #6
0
        /// <summary>
        /// TagToCheck是否在本container中. 也会检查ParentTags
        /// {"A.1"}.HasTag("A") will return True, {"A"}.HasTag("A.1") will return False
        /// </summary>
        public bool HasTag(CGameplayTag TagToCheck)
        {
            if (!TagToCheck.IsValid())
            {
                return(false);
            }

            // 自己或者父亲有就可以
            return(GameplayTags.Contains(TagToCheck) || ParentTags.Contains(TagToCheck));
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
0
        /**
         * Tag to remove from the container
         */
        public bool RemoveTag(CGameplayTag TagToRemove)
        {
            bool succ = GameplayTags.Remove(TagToRemove);

            if (!succ)
            {
                return(false);
            }

            // Have to recompute parent table from scratch because there could be duplicates providing the same parent tag
            FillParentTags();
            return(true);
        }
コード例 #11
0
        /** 添加InTag所在的container的parent tags 到 本ParentTags中*/
        protected void AddParentsForTag(CGameplayTag InTag)
        {
            CGameplayTagContainer inContainer = CGameplayTagsManager.Instance.GetSingleTagContainer(InTag);

            if (inContainer == null)
            {
                return;
            }

            // Add Parent tags from this tag to our own
            foreach (CGameplayTag ParentTag in inContainer.ParentTags)
            {
                ParentTags.AddUnique(ParentTag);
            }
        }
コード例 #12
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);
        }
コード例 #13
0
ファイル: CGameplayTagQuery.cs プロジェクト: yimogod/DarkRoom
        private void ReadExpr(CGameplayTagQueryExpression E)
        {
            E.ExprType = (CGameplayTagQueryExprType)GetToken();
            if (bReadError)
            {
                return;
            }

            if (E.UsesTagSet())
            {
                // parse tag set
                byte NumTags = GetToken();
                if (bReadError)
                {
                    return;
                }

                for (byte Idx = 0; Idx < NumTags; ++Idx)
                {
                    byte TagIdx = GetToken();
                    if (bReadError)
                    {
                        return;
                    }

                    CGameplayTag Tag = Query.GetTagFromIndex(TagIdx);
                    E.AddTag(Tag);
                }
            }
            else
            {
                // parse expr set
                byte NumExprs = GetToken();
                if (bReadError)
                {
                    return;
                }

                for (byte Idx = 0; Idx < NumExprs; ++Idx)
                {
                    CGameplayTagQueryExpression Exp = new CGameplayTagQueryExpression();
                    ReadExpr(Exp);
                    Exp.AddExpr(Exp);
                }
            }
        }
コード例 #14
0
ファイル: CGameplayTagQuery.cs プロジェクト: yimogod/DarkRoom
        private bool EvalNoTagsMatch(CGameplayTagContainer Tags, bool bSkip)
        {
            // parse tagset
            byte NumTags = GetToken();

            if (bReadError)
            {
                return(false);
            }

            if (bSkip)
            {
                GetTokenNext(NumTags);
                if (bReadError)
                {
                    return(false);
                }
            }
            else
            {
                //交叉比较, 如果有一个就结果失败
                for (byte Idx = 0; Idx < NumTags; ++Idx)
                {
                    byte TagIdx = GetToken();
                    if (bReadError)
                    {
                        return(false);
                    }

                    CGameplayTag Tag     = Query.GetTagFromIndex(TagIdx);
                    bool         bHasTag = Tags.HasTag(Tag);
                    if (bHasTag)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #15
0
ファイル: CGameplayTagQuery.cs プロジェクト: yimogod/DarkRoom
 /**
  * 清理现有tag, 用传入的tag填充
  * Replaces existing tags with passed in tag. Does not modify the tag query expression logic.
  * Useful when you need to cache off and update often used query.
  */
 public void ReplaceTagFast(CGameplayTag Tag)
 {
     TagDictionary.Clear();
     TagDictionary.Add(Tag);
 }
コード例 #16
0
ファイル: CGameplayTagQuery.cs プロジェクト: yimogod/DarkRoom
 public CGameplayTagQueryExpression AddTag(CGameplayTag Tag)
 {
     TagSet.Add(Tag);
     return(this);
 }
コード例 #17
0
 /**
  * 检测 两个tag有多相近, 返回值越好说明越相近
  * 比如A.b.c 和A.b.d 就比 A.b.c和A.c更相近
  */
 public int GameplayTagsMatchDepth(CGameplayTag GameplayTagOne, CGameplayTag GameplayTagTwo)
 {
     return(1);
 }
コード例 #18
0
        /// <summary>
        /// 将tag a.b.c 变成数组[a, b, c]
        /// </summary>
        public void SplitGameplayTagFName(CGameplayTag Tag, List <string> OutNames)
        {
            var list = Tag.GetTagName().Split('.');

            OutNames.AddRange(list);
        }
コード例 #19
0
        /// <summary>
        /// 找到tag对应的node
        /// </summary>
        public CGameplayTagNode FindTagNode(string TagName)
        {
            CGameplayTag PossibleTag = new CGameplayTag(TagName);

            return(FindTagNode(PossibleTag));
        }
コード例 #20
0
        /// <summary>
        /// 找到tag对应的node
        /// </summary>
        public CGameplayTagNode FindTagNode(CGameplayTag GameplayTag)
        {
            CGameplayTagNode Node = GameplayTagNodeMap[GameplayTag.GetTagName()];

            return(Node);
        }