Example #1
0
        public BehaviourNodeGUI AddChild(PaintElement parent, BehaviourMeta meta, Vector2 localPos)
        {
            if (parent != null && parent.Parent != TreeCanvas)
            {
                return(null);
            }
            BehaviourNodeGUI node = new BehaviourNodeGUI(this);

            node.Self = new BehaviourNodeGUI.Decorator(GenerateId, meta);
            node.Self.UpdatePropertiesInfo();
            Rect r = new Rect();

            r.size         = node.CalculateLocalSize();
            r.position     = localPos - Vector2.right * r.size.x * 0.5f;
            node.LocalRect = r;
            TreeCanvas.AddElement(node);
            TreeGraph.AddNode(node);
            if (parent != null)
            {
                TreeGraph.AddPath(0, parent, node);
            }
            RebuildExecutionOrder();

            return(node);
        }
Example #2
0
        BehaviourNodeGUI NewNode(BTData data)
        {
            BehaviourMeta meta = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(data.m_Type, data.m_Name);

            if (meta == null || (meta.NodeType != EBTNodeType.task && meta.NodeType != EBTNodeType.controller))
            {
                return(null);
            }
            BehaviourNodeGUI bnode = new BehaviourNodeGUI(this);

            bnode.Self = new BehaviourNodeGUI.Decorator(data.m_Id, meta);
            bnode.Self.ParseData(data.m_JsonData);
            if (data.m_Services != null)
            {
                for (int i = 0; i < data.m_Services.Length; i++)
                {
                    BTData serv = BehaviourAsset.GetDataById(data.m_Services[i]);
                    if (serv == null)
                    {
                        continue;
                    }
                    BehaviourMeta bm = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(EBTNodeType.service, serv.m_Name);
                    if (bm != null)
                    {
                        BehaviourNodeGUI.Decorator decor = new BehaviourNodeGUI.Decorator(serv.m_Id, bm);
                        decor.ParseData(serv.m_JsonData);
                        bnode.services.Add(decor);
                    }
                }
            }
            if (data.m_Conditions != null)
            {
                for (int i = 0; i < data.m_Conditions.Length; i++)
                {
                    BTData cond = BehaviourAsset.GetDataById(data.m_Conditions[i]);
                    if (cond == null)
                    {
                        continue;
                    }
                    BehaviourMeta bm = BehaviourModuleManager.GetOrNewInstance().FindBTMeta(EBTNodeType.condition, cond.m_Name);
                    if (bm != null)
                    {
                        BehaviourNodeGUI.Decorator decor = new BehaviourNodeGUI.Decorator(cond.m_Id, bm);
                        decor.NotFlag = cond.m_NotFlag;
                        decor.ParseData(cond.m_JsonData);
                        bnode.conditions.Add(decor);
                    }
                }
            }
            Rect r = new Rect();

            r.size          = bnode.CalculateLocalSize();
            r.position      = data.m_Pos - Vector2.right * r.size.x * 0.5f;
            bnode.LocalRect = r;
            return(bnode);
        }