Example #1
0
        public static NodePanel CreateDefaultNodePanel(Node node, CanvasState canvasState)
        {
            // create the nodePanel rect
            Rect nodePanelRect = new Rect(new Vector2(0, 0), new Vector2(BehaviourEditorStyles.NODE_DEFAULT_WIDTH, BehaviourEditorStyles.NODE_DEFAULT_HEIGHT));

            int handleSize    = 16;
            int handlePadding = 2;

            Rect inHandleRect = new Rect(Vector2.zero, new Vector2(handleSize, handleSize));

            inHandleRect.center = new Vector2(nodePanelRect.width / 2,
                                              0 - handleSize / 2 - handlePadding);

            Rect outHandleRect = new Rect(Vector2.zero, new Vector2(handleSize, handleSize));

            outHandleRect.center = new Vector2(nodePanelRect.width / 2,
                                               (nodePanelRect.size.y) + (handleSize / 2) + handlePadding);

            //NodePanel nodePanel = new NodePanel(node, nodePanelRect, inHandleRect, outHandleRect);
            NodePanel nodePanel = node.CanHaveChildren ?
                                  new NodePanel(node, nodePanelRect, inHandleRect, outHandleRect, canvasState) :
                                  new NodePanel(node, nodePanelRect, inHandleRect, canvasState);

            nodePanel.SetIcon(CanvasUtility.GetIcon(node.GetType()));
            nodePanel.SetColours(Color.white, BehaviourEditorStyles.nodeNormalColour, 1);

            return(nodePanel);
        }
Example #2
0
        //public static void CreateNodePannelAsset(BehaviourTree treeAsset, NodePanel nodePanel)
        //{
        //	string treePath = AssetDatabase.GetAssetPath(treeAsset);
        //	AssetDatabase.AddObjectToAsset(nodePanel, treeAsset);
        //	AssetDatabase.ImportAsset(treePath);
        //}

        public static NodePanel CreateNodePanel(Node node, CanvasState canvasState)
        {
            if (customNodePanelPrototypes.ContainsKey(node.GetType()))
            {
                return(customNodePanelPrototypes[node.GetType()].Create(node, canvasState));
            }
            else
            {
                return(CreateDefaultNodePanel(node, canvasState));
            }
        }
Example #3
0
        public NodeHandle(int nodePanelGuid, string id, HandleType type, Rect rect, CanvasState canvasState)
        {
            this.canvasState   = canvasState;
            transform          = new CanvasTransform(id + " NodeHandle " + type.ToString(), rect, canvasState);
            this.nodePanelGuid = nodePanelGuid;

            this.type    = type;
            _connections = new List <NodeConnection>();

            this.canvasState.AddInputReceiver(this);
        }
Example #4
0
        public PreviewConnection(NodeHandle source, Vector2 end, CanvasState canvasState)
        {
            this.canvasState = canvasState;

            _start        = new CanvasTransform(source.NodePanel.label + " Start Connection", source.transform.rect.center, Vector2.zero, canvasState);
            _start.Parent = source.transform;

            _end = new CanvasTransform(source.NodePanel.label + " End Connection", end, Vector2.zero, canvasState);

            _points = new Vector2[4];
        }
Example #5
0
        public NodeHandle Clone(CanvasState state)
        {
            NodeHandle clone = new NodeHandle(nodePanelGuid, NodePanel.label, type, transform.rect, state)
            {
                _connections = new List <NodeConnection>()
            };

            for (int i = 0; i < _connections.Count; i++)
            {
                clone._connections.Add(_connections[i].Clone(state));
            }
            return(clone);
        }
Example #6
0
        public NodeConnection Clone(CanvasState state)
        {
            NodeConnection clone = new NodeConnection()
            {
                canvasState     = state,
                _startPanelGuid = _startPanelGuid,
                _endPanelGuid   = _endPanelGuid,
                _start          = _start.Clone(state),
                _end            = _end.Clone(state),
                _points         = _points,
            };

            return(clone);
        }
Example #7
0
        public NodePanel(Node node, Rect rect, Rect inHandle, CanvasState canvasState)
        {
            this.nodeGuid    = node.guid;
            this.guid        = node.guid;
            this.canvasState = canvasState;

            this.transform = new CanvasTransform(node.Id + " NodePanel", rect, canvasState);

            this.inHandle = new NodeHandle(this, NodeHandle.HandleType.In, inHandle, canvasState);
            this.inHandle.transform.Parent = this.transform;
            this.hasOuthandle = false;

            childrenGuids = new List <int>();
            this.canvasState.AddInputReceiver(this);
        }
Example #8
0
        public CanvasState CloneWithSubstituteTree(BehaviourTree treeAsset)
        {
            CanvasState canvasState = ScriptableObject.CreateInstance <CanvasState>();

            canvasState.tree          = treeAsset;
            canvasState.RootNodePanel = this.RootNodePanel;

            canvasState.nodePanels = new List <NodePanel>();

            for (int i = 0; i < nodePanels.Count; i++)
            {
                canvasState.nodePanels.Add(nodePanels[i].Clone(treeAsset, canvasState));
            }


            canvasState.canvasRect = canvasRect;
            canvasState.zoom       = zoom;
            canvasState.panOffset  = panOffset;
            canvasState.OnEnable();

            for (int i = 0; i < nodePanels.Count; i++)
            {
                NodePanel clonedPanel = canvasState.GetNodePanel(nodePanels[i].guid);
                NodePanel oldPanel    = nodePanels[i];

                clonedPanel.inHandle.transform.rect = oldPanel.inHandle.transform.rect;
                if (clonedPanel.hasOuthandle)
                {
                    clonedPanel.outHandle.transform.rect = oldPanel.outHandle.transform.rect;
                }
            }

            for (int i = 0; i < nodePanels.Count; i++)
            {
                NodePanel nodePanel = nodePanels[i];

                for (int j = 0; j < nodePanel.Children.Count; j++)
                {
                    NodePanel child = nodePanel.Children[j];
                    nodePanel.outHandle.Connect(child.inHandle);
                }
            }

            return(canvasState);
        }
Example #9
0
        public NodeConnection(NodePanel startPanel, NodePanel endPanel, CanvasState canvasState)
        {
            this.canvasState = canvasState;

            // CanvasTransform startParent = canvasState.GetCanvasTransform(startParentGuid);
            // CanvasTransform endParent = canvasState.GetCanvasTransform(endParentGuid);

            // startParent.childrenGuids.Add(_start.guid);
            // endParent.childrenGuids.Add(_end.guid);

            _start = new CanvasTransform("Start Connection", startPanel.outHandle.transform.rect, canvasState);
            _end   = new CanvasTransform("End Connection", endPanel.inHandle.transform.rect, canvasState);

            _start.Parent = startPanel.outHandle.transform;
            _end.Parent   = endPanel.inHandle.transform;


            _startPanelGuid = startPanel.guid;
            _endPanelGuid   = endPanel.guid;

            _points = new Vector2[4];
        }
Example #10
0
        public NodePanel Clone(BehaviourTree tree, CanvasState state)

        {
            NodePanel clone = hasOuthandle ?
                              new NodePanel(tree.GetNode(nodeGuid), transform.rect, inHandle.transform.rect, outHandle.transform.rect, state) :
                              new NodePanel(tree.GetNode(nodeGuid), transform.rect, inHandle.transform.rect, state);

            clone.guid          = guid;
            clone.childrenGuids = childrenGuids;
            clone.parentGuid    = parentGuid;
            clone.transform     = transform.Clone(state);
            clone.icon          = icon;

            clone.inHandle     = inHandle.Clone(state);
            clone.hasOuthandle = hasOuthandle;
            if (hasOuthandle)
            {
                clone.outHandle = outHandle.Clone(state);
            }

            return(clone);
        }
Example #11
0
 public override NodePanel Create(Node node, CanvasState canvasState)
 {
     return(NodePanelFactory.CreateDefaultNodePanel(node, canvasState));
 }
Example #12
0
 public NodeHandle(NodePanel nodePanel, HandleType type, Rect rect, CanvasState canvasState) :
     this(nodePanel.guid, nodePanel.label, type, rect, canvasState)
 {
 }
Example #13
0
 public abstract NodePanel Create(Node node, CanvasState canvasState);