当前位置: 首页>>代码示例>>C#>>正文


C# ITask.FindTasks方法代码示例

本文整理汇总了C#中ITask.FindTasks方法的典型用法代码示例。如果您正苦于以下问题:C# ITask.FindTasks方法的具体用法?C# ITask.FindTasks怎么用?C# ITask.FindTasks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITask的用法示例。


在下文中一共展示了ITask.FindTasks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SolveReferences

        /// <summary>
        ///   Solves all sub tree reference tasks and replaces them by real references to the sub tree.
        /// </summary>
        /// <param name="tree"> Tree in which to solve references. </param>
        /// <returns> Task to use instead of the passed one. </returns>
        private ITask SolveReferences(ITask tree)
        {
            if (tree == null)
            {
                return tree;
            }

            // Check if root is reference.
            if (tree is SubTreeReference)
            {
                SubTreeReference subTreeReference = tree as SubTreeReference;

                // Resolve reference.
                ITask treeReference = this.SolveReference(subTreeReference);

                return treeReference;
            }

            // Find sub tree reference tasks in tree.
            ICollection<TaskNode> referenceNodes = new List<TaskNode>();
            TaskNode rootNode = new TaskNode { Task = tree };
            tree.FindTasks(rootNode, task => task is SubTreeReference, ref referenceNodes);

            // Replace tasks in found nodes by referenced tree.
            foreach (TaskNode referenceNode in referenceNodes)
            {
                SubTreeReference subTreeReference = referenceNode.Task as SubTreeReference;
                if (subTreeReference == null)
                {
                    throw new Exception(
                        "Searched for SubTreeReference nodes, but found a task which is no sub tree reference node.");
                }

                IComposite parentComposite = referenceNode.ParentTask as IComposite;
                if (parentComposite == null)
                {
                    throw new Exception("Found task which has no parent composite.");
                }

                // Resolve reference.
                ITask treeReference = this.SolveReference(subTreeReference);

                // Remove from parent.
                parentComposite.RemoveChild(referenceNode.Task);

                // Add tree reference to parent at same position.
                parentComposite.InsertChild(referenceNode.Index, treeReference);
            }

            return tree;
        }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:56,代码来源:BehaviorTreeLibrary.cs


注:本文中的ITask.FindTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。