Ejemplo n.º 1
0
        private void DrawConnector(NodeGUIConnector connectorData, int outputId, Color connectorColor, bool displayTitle = true, bool right = true)
        {
            GUILayout.BeginHorizontal();
            {
                if (right)
                {
                    GUI.backgroundColor = connectorColor;
                    if (GUILayout.Button("", NodeConnectorStyle()))
                    {
                        if (connectorData != null)
                        {
                            connectorData?.OnClick?.Invoke(outputId);
                        }
                    }
                    GUI.backgroundColor = Color.white;

                    if (displayTitle)
                    {
                        GUILayout.Label(connectorData?.Name, GUILayout.Width(50));
                    }
                }
                else
                {
                    if (displayTitle)
                    {
                        GUILayout.Label(connectorData?.Name, GUILayout.Width(50));
                    }

                    GUI.backgroundColor = connectorColor;
                    if (GUILayout.Button("", NodeConnectorStyle()))
                    {
                        if (connectorData != null)
                        {
                            connectorData?.OnClick?.Invoke(outputId);
                        }
                    }
                    GUI.backgroundColor = Color.white;
                }
            }
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 2
0
        public NodeGUI(PTreeBehaviourNodeEditor.EditorData editorData, NodeType node, string title, Action onClick = null)
        {
            Node  = node;
            Title = title;

            OnClick = onClick;

            _editorData = editorData;

            ParentConnectorPosition = new Vector2(0, node.InEditorWindow.NodeSize.y / 2);

            _texture2D_header = new Texture2D(1, 1);
            _texture2D_connectorParentColor = new Texture2D(1, 1);

            _texture2D_connectorParentColor.SetPixel(0, 0, new Color(91f / 255f, 215f / 255f, 217f / 255f));
            _texture2D_connectorParentColor.Apply();

            OutputsConnectors = new List <NodeGUIConnector>();

            switch (Node.BehaviourNodeType)
            {
            case BehaviourNodeType.Root:
            {
                NodeGUIConnector output = new NodeGUIConnector("Begin", (id) => { OnConnectorClicked(id); });
                OutputsConnectors.Add(output);
            }
            break;

            case BehaviourNodeType.Condition:
            {
                _texture2D_header.SetPixel(0, 0, new Color(252f / 255f, 192f / 255f, 88 / 255f));
                _texture2D_header.Apply();

                NodeGUIConnector falseConnector = new NodeGUIConnector("False", (id) => { OnConnectorClicked(id); });
                NodeGUIConnector trueConnector  = new NodeGUIConnector("True", (id) => { OnConnectorClicked(id); });

                OutputsConnectors.Add(falseConnector);
                OutputsConnectors.Add(trueConnector);
            }
            break;

            case BehaviourNodeType.Action:
            {
                _texture2D_header.SetPixel(0, 0, new Color(43f / 255f, 214f / 255f, 252f / 255f));
                _texture2D_header.Apply();

                NodeGUIConnector output = new NodeGUIConnector("Output", (id) => { OnConnectorClicked(id); });
            }
            break;

            case BehaviourNodeType.Sequence:
            {
                _texture2D_header.SetPixel(0, 0, new Color(0f / 255f, 155f / 255f, 0f / 255f));
                _texture2D_header.Apply();

                SequenceBehaviourNode sequence = Node as SequenceBehaviourNode;

                int i = 0;

                foreach (var connector in sequence.Outputs)
                {
                    OutputsConnectors.Add(new NodeGUIConnector($"#{i}", (id) => { OnConnectorClicked(id); }));
                    i++;
                }
            }
            break;
            }
        }