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


C# Node.AddChild方法代码示例

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


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

示例1: CloneChildNodes

        /// <summary>
        /// Internally used by CloneBranch.
        /// </summary>
        /// <param name="newparent">The parent the clone children will be added to.</param>
        private void CloneChildNodes(Node newparent) {
            // we may not clone children of a referenced behavior
            if (newparent is ReferencedBehaviorNode)
            { return; }

            // for each connector
            foreach(Connector connector in _children.Connectors) {
                // find the one from the new node...
                Connector localconn = newparent.GetConnector(connector.Identifier);
                Debug.Check(localconn != null);

                // and duplicate its children into the new node's connector
                for (int i = 0; i < connector.ChildCount; ++i) {
                    Node child = (Node)connector.GetChild(i);

                    Node newchild = (Node)child.Clone();
                    newparent.AddChild(localconn, newchild);

                    // do this for the children as well
                    child.CloneChildNodes(newchild);
                }
            }

            // for each FSM node
            foreach(Node child in this.FSMNodes) {
                Node newchild = (Node)child.Clone();
                newparent.AddFSMNode(newchild);

                // do this for the children as well
                child.CloneChildNodes(newchild);
            }
        }
开发者ID:haolly,项目名称:behaviac,代码行数:36,代码来源:Node.cs

示例2: replaceNode

        private bool replaceNode(Node node, Node newnode) {
            if (node == null || !node.IsFSM && node.ParentConnector == null || newnode == null) {
                return false;
            }

            bool replaced = (node.Children.Count == 0);

            if (!replaced && newnode.CanAdoptChildren(node)) {
                foreach(Node.Connector connector in node.Connectors) {
                    Node.Connector newConnector = newnode.GetConnector(connector.Identifier);

                    if (newConnector != null) {
                        for (int i = 0; i < connector.ChildCount; ++i) {
                            replaced |= newnode.AddChild(newConnector, (Node)connector.GetChild(i));
                        }

                        connector.ClearChildrenInternal();
                    }
                }
            }

            if (replaced)
            {
                Node parentNode = (Node)node.Parent;

                if (node.IsFSM)
                {
                    Debug.Check(newnode.IsFSM);

                    parentNode.RemoveFSMNode(node);
                    parentNode.AddFSMNode(newnode);

                    newnode.ScreenLocation = node.ScreenLocation;
                }
                else
                {
                    Node.Connector parentConnector = node.ParentConnector;
                    Debug.Check(parentConnector != null);

                    int index = parentConnector.GetChildIndex(node);
                    Debug.Check(index >= 0);

                    parentNode.RemoveChild(parentConnector, node);
                    parentNode.AddChild(parentConnector, newnode, index);
                }

                foreach (Attachments.Attachment attach in node.Attachments)
                {
                    if (attach != null && newnode.AcceptsAttachment(attach))
                        newnode.AddAttachment(attach);
                }
            }

            return replaced;
        }
开发者ID:Just4F,项目名称:behaviac,代码行数:55,代码来源:BehaviorTreeView.cs

示例3: AutoRestruct

        //if there is a 'Predicate' attachment, convert it to a Condition node and attach it to the '_custom_condition' connector.
        private void AutoRestruct(List<Node.ErrorCheck> result, int version, Behaviac.Design.Attachments.Attachment a, Node node)
        {
            if (version <= 1)
            {
                string attachClass = a.GetType().FullName;
                if (attachClass.IndexOf("PluginBehaviac.Events.Predicate") >= 0)
                {
                    DesignerPropertyInfo propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opl");
                    RightValueDef opl = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Opr");
                    RightValueDef opr = propInfo.GetValue(a) as RightValueDef;
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "Operator");
                    OperatorType oprr = (OperatorType)propInfo.GetValue(a);
                    OperatorTypes oprType = (OperatorTypes)((int)OperatorTypes.Equal - (int)OperatorType.Equal + (int)oprr);
                    propInfo = DesignerProperty.GetDesignerProperty(a.GetType(), "BinaryOperator");
                    Behaviac.Design.Attachments.BinaryOperator binaryOpr = (Behaviac.Design.Attachments.BinaryOperator)propInfo.GetValue(a);

                    string clss = node.GetType().FullName;
                    bool bIsSeqSel = (node.GetType().IsSubclassOf(typeof(Sequence)) ||
                        node.GetType().IsSubclassOf(typeof(Selector)));

                    bool bCare = (bIsSeqSel ||
                        node.GetType().IsSubclassOf(typeof(Impulse))
                       );

                    if (bCare ||
                        clss == "PluginBehaviac.Nodes.Query" ||
                        clss == "PluginBehaviac.Nodes.DecoratorCountLimit")
                    {
                        node.RemoveAttachment(a);
                        node.Behavior.TriggerWasModified(node);

                        Type newType = Plugin.GetType("PluginBehaviac.Nodes.Condition");

                        Behaviac.Design.Nodes.Node newNode = Behaviac.Design.Nodes.Node.Create(newType);
                        Behaviac.Design.Nodes.Node.Connector connector = node.GetConnector(Node.Connector.kInterupt);

                        if (connector != null && connector.Identifier == Node.Connector.kInterupt && connector.ChildCount > 0)
                        {
                            //it has multiple Predicates, so insert all of them to a newly created Sequence
                            Node oldOne = (Node)connector.GetChild(0);
                            if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                            {
                                AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                            }
                            else
                            {
                                if (bIsSeqSel)
                                {
                                    Debug.Check(oldOne.GetType().IsSubclassOf(typeof(Decorator)));
                                    Decorator d = oldOne as Decorator;
                                    node = oldOne;
                                    connector = node.GetConnector(BaseNode.Connector.kGeneric);
                                    oldOne = (Node)d.Children[0];
                                }

                                if (oldOne.GetType()== typeof(PluginBehaviac.Nodes.And))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.Or)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.Or");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType() == typeof(PluginBehaviac.Nodes.Or))
                                {
                                    if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.And)
                                    {
                                        node.RemoveChild(connector, oldOne);
                                        Type selType1 = Plugin.GetType("PluginBehaviac.Nodes.And");

                                        Behaviac.Design.Nodes.Node sel = Behaviac.Design.Nodes.Node.Create(selType1);
                                        sel.AddChild(BaseNode.Connector.kGeneric, oldOne);
                                        sel.AddChild(BaseNode.Connector.kGeneric, newNode);

                                        node.AddChild(BaseNode.Connector.kInterupt, sel);
                                    }
                                    else
                                    {
                                        oldOne.AddChild(BaseNode.Connector.kGeneric, newNode);
                                    }
                                }
                                else if (oldOne.GetType().IsSubclassOf(typeof(Condition)))
                                {
                                    AddAfterConditions(node, binaryOpr, newNode, connector, oldOne);
                                }
                                else
                                {
                                    Debug.Check(false);
//.........这里部分代码省略.........
开发者ID:675492062,项目名称:behaviac,代码行数:101,代码来源:Predicate.cs

示例4: AddAfterConditions

        private static void AddAfterConditions(Node node, Behaviac.Design.Attachments.BinaryOperator binaryOpr, Behaviac.Design.Nodes.Node newNode, Behaviac.Design.Nodes.Node.Connector connector, Node oldOne)
        {
            node.RemoveChild(connector, oldOne);

            Type seqType = Plugin.GetType("PluginBehaviac.Nodes.And");
            if (binaryOpr == Behaviac.Design.Attachments.BinaryOperator.Or)
            {
                seqType = Plugin.GetType("PluginBehaviac.Nodes.Or");
            }

            Behaviac.Design.Nodes.Node seq = Behaviac.Design.Nodes.Node.Create(seqType);
            seq.AddChild(BaseNode.Connector.kGeneric, newNode);
            seq.AddChild(BaseNode.Connector.kGeneric, oldOne);

            node.AddChild(BaseNode.Connector.kInterupt, seq);
        }
开发者ID:675492062,项目名称:behaviac,代码行数:16,代码来源:Predicate.cs

示例5: replaceNode

        private bool replaceNode(Node node, Node newnode)
        {
            if (node == null || node.ParentConnector == null || newnode == null)
                return false;

            bool replaced = (node.Children.Count == 0);

            if (!replaced && newnode.CanAdoptChildren(node))
            {
                foreach (Node.Connector connector in node.Connectors)
                {
                    Node.Connector newConnector = newnode.GetConnector(connector.Identifier);
                    if (newConnector != null)
                    {
                        for (int i = 0; i < connector.ChildCount; ++i)
                        {
                            replaced |= newnode.AddChild(newConnector, (Node)connector.GetChild(i));
                        }

                        connector.ClearChildrenInternal();
                    }
                }
            }

            if (replaced)
            {
                Node.Connector parentConnector = node.ParentConnector;
                Debug.Check(parentConnector != null);

                int index = parentConnector.GetChildIndex(node);
                Debug.Check(index >= 0);

                Node parentNode = (Node)node.Parent;
                parentNode.RemoveChild(parentConnector, node);
                parentNode.AddChild(parentConnector, newnode, index);
            }

            return replaced;
        }
开发者ID:KeyleXiao,项目名称:behaviac,代码行数:39,代码来源:BehaviorTreeView.cs


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