Ejemplo n.º 1
0
 public LogicSlot(AbstractLogicNodeEditor owner, string memberName, string displayName, SlotDirection direction)
 {
     Owner        = owner;
     _memberName  = memberName;
     _displayName = displayName;
     _direction   = direction;
 }
Ejemplo n.º 2
0
        public SerializedNode AddNode(AbstractLogicNodeEditor logicNodeEditor)
        {
            _logicGraphEditorObject.RegisterCompleteObjectUndo("Add Node " + logicNodeEditor.NodeType());

            SerializedNode serializedNode = new SerializedNode
            {
                NodeType = logicNodeEditor.NodeType(),
                JSON     = JsonUtility.ToJson(logicNodeEditor)
            };

            logicNodeEditor.SerializedNode = serializedNode;
            if (logicNodeEditor is IInputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Add(serializedNode);
            }
            else if (logicNodeEditor is IOutputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Add(serializedNode);
            }
            else
            {
                _logicGraphEditorObject.LogicGraphData.SerializedNodes.Add(serializedNode);
            }

            logicNodeEditor.Owner = _graphView;
            var nodeView = new LogicNodeView {
                userData = logicNodeEditor
            };

            _graphView.AddElement(nodeView);
            nodeView.Initialize(logicNodeEditor, _edgeConnectorListener);
            nodeView.MarkDirtyRepaint();
            return(serializedNode);
        }
Ejemplo n.º 3
0
        public VectorControlView(string label, string subLabel1, string subLabel2, string subLabel3, string subLabel4, AbstractLogicNodeEditor logicNodeEditor, PropertyInfo propertyInfo)
        {
            var components = Array.IndexOf(validTypes, propertyInfo.PropertyType) + 1;

            if (components == -1)
            {
                throw new ArgumentException("Property must be of type float, Vector2, Vector3 or Vector4.", "propertyInfo");
            }

            this.LoadAndAddStyleSheet("Styles/VectorControlView");
            _mLogicNodeEditor = logicNodeEditor;
            m_PropertyInfo    = propertyInfo;

            label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);
            if (!string.IsNullOrEmpty(label))
            {
                Add(new Label(label));
            }

            m_Value = GetValue();
            AddField(0, subLabel1);
            if (components > 1)
            {
                AddField(1, subLabel2);
            }
            if (components > 2)
            {
                AddField(2, subLabel3);
            }
            if (components > 3)
            {
                AddField(3, subLabel4);
            }
        }
Ejemplo n.º 4
0
        public ToggleControlView(string label, AbstractLogicNodeEditor logicNodeEditor, PropertyInfo propertyInfo)
        {
            _logicNodeEditor = logicNodeEditor;
            _propertyInfo    = propertyInfo;
            AddStyleSheetPath("Styles/Controls/ToggleControlView");

            if (propertyInfo.PropertyType != typeof(bool))
            {
                throw new ArgumentException("Property must be a Toggle.", "propertyInfo");
            }

            label = label ?? ObjectNames.NicifyVariableName(propertyInfo.Name);

            var value = (bool)_propertyInfo.GetValue(_logicNodeEditor, null);
            var panel = new VisualElement {
                name = "togglePanel"
            };

            if (!string.IsNullOrEmpty(label))
            {
                panel.Add(new Label(label));
            }
            Action changedToggle = () => { OnChangeToggle(); };

            _toggle = new Toggle(changedToggle);

            _toggle.value = value;
            panel.Add(_toggle);
            Add(panel);
        }
Ejemplo n.º 5
0
 public VisualElement InstantiateControl(AbstractLogicNodeEditor logicNodeEditor, PropertyInfo propertyInfo)
 {
     if (!VectorControlView.validTypes.Contains(propertyInfo.PropertyType))
     {
         return(null);
     }
     return(new VectorControlView(m_Label, m_SubLabel1, m_SubLabel2, m_SubLabel3, m_SubLabel4, logicNodeEditor, propertyInfo));
 }
Ejemplo n.º 6
0
 public BooleanSlot(AbstractLogicNodeEditor owner,
                    string memberName,
                    string displayName,
                    SlotDirection direction,
                    string[] labels,
                    Func <Bool4> get,
                    Action <Bool4> set) : base(owner, memberName, displayName, direction)
 {
     _labels = labels;
     _get    = get;
     _set    = set;
 }
Ejemplo n.º 7
0
        void AddEntries(AbstractLogicNodeEditor logicNodeEditor, string[] title, List <NodeEntry> nodeEntries)
        {
            if (ConnectedLogicPort == null)
            {
                nodeEntries.Add(new NodeEntry
                {
                    LogicNodeEditor  = logicNodeEditor,
                    title            = title,
                    compatibleSlotId = ""
                });
                return;
            }

            var connectedSlot = ConnectedLogicPort.Slot;

            m_Slots.Clear();
            logicNodeEditor.GetSlots(m_Slots);
            var hasSingleSlot = m_Slots.Count(s => s.isOutputSlot != connectedSlot.isOutputSlot) == 1;

            m_Slots.RemoveAll(slot =>
            {
                var logicSlot = (LogicSlot)slot;
                return(!logicSlot.IsCompatibleWith(connectedSlot));
            });

            if (hasSingleSlot && m_Slots.Count == 1)
            {
                nodeEntries.Add(new NodeEntry
                {
                    LogicNodeEditor  = logicNodeEditor,
                    title            = title,
                    compatibleSlotId = m_Slots.First().MemberName
                });
                return;
            }

            foreach (var slot in m_Slots)
            {
                var entryTitle = new string[title.Length];
                title.CopyTo(entryTitle, 0);
                entryTitle[entryTitle.Length - 1] += ": " + slot.DisplayName;
                nodeEntries.Add(new NodeEntry
                {
                    title            = entryTitle,
                    LogicNodeEditor  = logicNodeEditor,
                    compatibleSlotId = slot.MemberName
                });
            }
        }
Ejemplo n.º 8
0
        public EnumControlView(string label, AbstractLogicNodeEditor logicNodeEditor, PropertyInfo propertyInfo)
        {
            AddStyleSheetPath("Styles/Controls/EnumControlView");
            _logicNodeEditor = logicNodeEditor;
            _propertyInfo    = propertyInfo;
            if (!propertyInfo.PropertyType.IsEnum)
            {
                throw new ArgumentException("Property must be an enum.", nameof(propertyInfo));
            }
            Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
            var enumField = new EnumField((Enum)_propertyInfo.GetValue(_logicNodeEditor, null));

            enumField.OnValueChanged(OnValueChanged);
            Add(enumField);
        }
Ejemplo n.º 9
0
        private GraphViewChange GraphViewChanged(GraphViewChange graphViewChange)
        {
            Debug.Log($"GraphViewChanged {graphViewChange}");

            if (graphViewChange.edgesToCreate != null)
            {
                Debug.Log("EDGES TO CREATE " + graphViewChange.edgesToCreate.Count);
            }

            if (graphViewChange.movedElements != null)
            {
                Debug.Log("Moved elements " + graphViewChange.movedElements.Count);
                _logicGraphEditorObject.RegisterCompleteObjectUndo("Graph Element Moved.");
                foreach (var element in graphViewChange.movedElements)
                {
                    AbstractLogicNodeEditor logicNodeEditor = element.userData as AbstractLogicNodeEditor;
                    logicNodeEditor.Position            = element.GetPosition().position;
                    logicNodeEditor.SerializedNode.JSON = JsonUtility.ToJson(logicNodeEditor);
                }
            }

            if (graphViewChange.elementsToRemove != null)
            {
                Debug.Log("Elements to remove" + graphViewChange.elementsToRemove.Count);
                _logicGraphEditorObject.RegisterCompleteObjectUndo("Deleted Graph Elements.");

                foreach (var nodeView in graphViewChange.elementsToRemove.OfType <LogicNodeView>())
                {
                    _logicGraphEditorObject.LogicGraphData.SerializedNodes.Remove(nodeView.LogicNodeEditor.SerializedNode);
                    _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Remove(nodeView.LogicNodeEditor
                                                                                       .SerializedNode);
                    _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Remove(nodeView.LogicNodeEditor
                                                                                        .SerializedNode);
                }

                foreach (var edge in graphViewChange.elementsToRemove.OfType <Edge>())
                {
                    _logicGraphEditorObject.LogicGraphData.SerializedEdges.Remove(edge.userData as SerializedEdge);
                }
            }

            return(graphViewChange);
        }
Ejemplo n.º 10
0
        private void AddNode(SerializedNode serializedNode)
        {
            AbstractLogicNodeEditor logicNodeEditor = null;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(AbstractLogicNodeEditor)))
                    {
                        var attrs = type.GetCustomAttributes(typeof(NodeEditorType), false) as NodeEditorType[];
                        if (attrs != null && attrs.Length > 0)
                        {
                            if (attrs[0].NodeType.Name == serializedNode.NodeType)
                            {
                                logicNodeEditor = (AbstractLogicNodeEditor)Activator.CreateInstance(type);
                            }
                        }
                    }
                }
            }

            if (logicNodeEditor != null)
            {
                JsonUtility.FromJsonOverwrite(serializedNode.JSON, logicNodeEditor);
                logicNodeEditor.SerializedNode = serializedNode;
                logicNodeEditor.Owner          = _graphView;
                var nodeView = new LogicNodeView {
                    userData = logicNodeEditor
                };
                _graphView.AddElement(nodeView);
                nodeView.Initialize(logicNodeEditor, _edgeConnectorListener);
                nodeView.MarkDirtyRepaint();
            }
            else
            {
                Debug.LogWarning("No NodeEditor found for " + serializedNode);
            }
        }
Ejemplo n.º 11
0
        public void Initialize(AbstractLogicNodeEditor logicNodeEditor, IEdgeConnectorListener connectorListener)
        {
            this.LoadAndAddStyleSheet("Styles/LogicNodeView");

            if (logicNodeEditor is IInputNode)
            {
                AddToClassList("input");
            }
            else if (logicNodeEditor is IOutputNode)
            {
                AddToClassList("output");
            }

            _connectorListener = connectorListener;
            LogicNodeEditor    = logicNodeEditor;
            title = LogicNodeEditor.NodeType();

            var contents = this.Q("contents");

            var controlsContainer = new VisualElement {
                name = "controls"
            };

            {
                _controlsDivider = new VisualElement {
                    name = "divider"
                };
                _controlsDivider.AddToClassList("horizontal");
                controlsContainer.Add(_controlsDivider);
                _controlItems = new VisualElement {
                    name = "items"
                };
                controlsContainer.Add(_controlItems);

                foreach (var propertyInfo in
                         logicNodeEditor.GetType().GetProperties(BindingFlags.Instance |
                                                                 BindingFlags.Public |
                                                                 BindingFlags.NonPublic))
                {
                    foreach (INodeControlAttribute attribute in
                             propertyInfo.GetCustomAttributes(typeof(INodeControlAttribute), false))
                    {
                        _controlItems.Add(attribute.InstantiateControl(logicNodeEditor, propertyInfo));
                    }
                }
            }
            contents.Add(controlsContainer);

            // Add port input container, which acts as a pixel cache for all port inputs
            _portInputContainer = new VisualElement
            {
                name = "portInputContainer",
//                clippingOptions = ClippingOptions.ClipAndCacheContents,
                pickingMode = PickingMode.Ignore
            };
            Add(_portInputContainer);

            List <LogicSlot> foundSlots = new List <LogicSlot>();

            logicNodeEditor.GetSlots(foundSlots);
            AddPorts(foundSlots);

            SetPosition(new Rect(logicNodeEditor.Position.x, logicNodeEditor.Position.y, 0, 0));
            UpdatePortInputs();
            base.expanded = logicNodeEditor.Expanded;
            RefreshExpandedState();
            UpdatePortInputVisibilities();
        }
Ejemplo n.º 12
0
 public VisualElement InstantiateControl(AbstractLogicNodeEditor logicNodeEditor, PropertyInfo propertyInfo)
 {
     return(new ToggleControlView(_label, logicNodeEditor, propertyInfo));
 }