public override void ShowContexMenu(InputSocket socket)
        {
            var menu = new GenericMenu();

            menu.AddItem(new GUIContent("Auto Hide Edges"),
                         false,
                         () =>
            {
                socket.EdgeList.ForEach(edge => edge.AutoHide = true);
            });

            menu.AddItem(new GUIContent("Always Show Edges"),
                         false,
                         () =>
            {
                socket.EdgeList.ForEach(edge => edge.AutoHide = false);
            });
            menu.AddSeparator("");

            menu.AddItem(new GUIContent("Move Up"),
                         false,
                         () => { socket.Node.Editor().MoveSocket(socket, -1); });

            menu.AddItem(new GUIContent("Move Down"),
                         false,
                         () => { socket.Node.Editor().MoveSocket(socket, 1); });

            menu.AddSeparator("");

            menu.AddItem(new GUIContent("Disconnect"),
                         false,
                         socket.Editor().Disconnect);

            menu.ShowAsContext();
        }
 public NumberDisplayNode(int id, Graph parent) : base(id, parent)
 {
     _textFieldArea = new Rect(10, 0, 80, Config.SocketSize);
     _inSocket      = new InputSocket(this, typeof(INumberConnection));
     Sockets.Add(_inSocket);
     Height = 20 + Config.SocketOffsetTop;
 }
Example #3
0
        public void DrawEdges(Rect canvasAreaInWindow)
        {
            if (_draggingPathPointIndex == -1)
            {
                _hoveringEdge = null;
            }

            for (var i = 0; i < Graph.GetNodeCount(); i++)
            {
                Node node = Graph.GetNodeAt(i);


                for (var iu = 0; iu < node.Sockets.Count; iu++)
                {
                    AbstractSocket socket = node.Sockets[iu];
                    if (socket.IsInput() && socket.IsConnected())                     // draw only input sockets to avoid double drawing of edges
                    {
                        InputSocket inputSocket = (InputSocket)socket;
                        if (CanvasOverlapsWindow(inputSocket.Edge.Bounds, canvasAreaInWindow))
                        {
                            bool highlight = _selectedNodes.Contains(node) ||
                                             _selectedNodes.Contains(inputSocket.Edge.Output.Parent);
                            int  segmentIndex = inputSocket.Edge.IntersectsPathSegment(Event.current.mousePosition);
                            bool hover        = segmentIndex > -1;
                            node.GUIDrawEdge(inputSocket, highlight, hover);
                            if (hover && _draggingPathPointIndex == -1)
                            {
                                HandleEdgeHover(inputSocket.Edge, segmentIndex);
                                _hoveringEdge = inputSocket.Edge;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
 public SaveTextureNode(int id, Graph parent) : base(id, parent)
 {
     _inputSocketColorMap = new InputSocket(this, typeof(IColorMapConnection));
     Sockets.Add(_inputSocketColorMap);
     Height = 70;
     Width  = 80;
 }
Example #5
0
        public SerializationContainer Serialize(List <Node> nodes)
        {
            if (nodes == null)
            {
                return(null);
            }
            bool wasTriggering = TriggerEvents;

            TriggerEvents = false;

            SerializationContainer container = new SerializationContainer();

            for (var index = 0; index < nodes.Count; index++)
            {
                var node = nodes[index];
                container.Nodes.Add(node.ToSerializedNode());
                for (var i = 0; i < node.Sockets.Count; i++)
                {
                    var socket = node.Sockets[i];
                    if (socket.IsInput() && socket.IsConnected())
                    // serialize only input socket edges to avoid double edge serialization
                    {
                        InputSocket inputSocket = (InputSocket)socket;
                        container.Edges.Add(inputSocket.Edge.ToSerializedEgde());
                    }
                }
            }
            TriggerEvents = wasTriggering;
            return(container);
        }
Example #6
0
 public AbsNode(int id, Graph parent) : base(id, parent)
 {
     _inputSocket = new InputSocket(this, typeof(AbstractNumberNode));
     Sockets.Add(_inputSocket);
     Width  = 40;
     Height = 40;
 }
Example #7
0
        public FunctionGate(Func <T, R> function)
        {
            this.inputSocket  = new InputSocket <T>();
            this.outputSocket = new OutputSocket <R>();

            this.SetFunction(function);
        }
Example #8
0
        public EntitiesNode(int id, Graph parent) : base(id, parent)
        {
            _inputSocketGameObject = new InputSocket(this, typeof(IGameObjectsConnection));
            _inputSocketPositions  = new InputSocket(this, typeof(IVectorConnection));

            _inputSocketRotationZ = new InputSocket(this, typeof(INumberConnection));
            _inputSocketRotationX = new InputSocket(this, typeof(INumberConnection));
            _inputSocketRotationY = new InputSocket(this, typeof(INumberConnection));

            _inputSocketScaleZ = new InputSocket(this, typeof(INumberConnection));
            _inputSocketScaleZ.SetDirectInputNumber(1, false);
            _inputSocketScaleX = new InputSocket(this, typeof(INumberConnection));
            _inputSocketScaleX.SetDirectInputNumber(1, false);
            _inputSocketScaleY = new InputSocket(this, typeof(INumberConnection));
            _inputSocketScaleY.SetDirectInputNumber(1, false);


            Sockets.Add(_inputSocketGameObject);
            Sockets.Add(_inputSocketPositions);

            Sockets.Add(_inputSocketRotationX);
            Sockets.Add(_inputSocketRotationY);
            Sockets.Add(_inputSocketRotationZ);

            Sockets.Add(_inputSocketScaleX);
            Sockets.Add(_inputSocketScaleY);
            Sockets.Add(_inputSocketScaleZ);

            Sockets.Add(new OutputSocket(this, typeof(IEntitiesConnection)));
            Height = 180;
        }
Example #9
0
        /// <summary>Unity serialization callback.</summary>
        public void OnBeforeSerialize()
        {
            if (_nodes.Count == 0)
            {
                return;                                // nothing to serialize
            }
            bool wasTriggering = TriggerEvents;

            TriggerEvents = false;

            _serializedEdges.Clear();
            _serializedNodes.Clear();
            // serialize data
            foreach (var node in _nodes)
            {
                _serializedNodes.Add(node.ToSerializedNode());
                foreach (var socket in node.Sockets)
                {
                    if (socket.IsInput() && socket.IsConnected())                     // serialize only input socket edges to avoid double edge serialization
                    {
                        InputSocket inputSocket = (InputSocket)socket;
                        _serializedEdges.Add(inputSocket.Edge.ToSerializedEgde());
                    }
                }
            }
            TriggerEvents = wasTriggering;
        }
Example #10
0
        public bool Link(InputSocket inputSocket, OutputSocket outputSocket)
        {
            if (!CanBeLinked(inputSocket, outputSocket))
            {
                Debug.LogWarning("Sockets can not be linked.");
                return(false);
            }
            _needsUpdate = true;

            if (inputSocket.Type == outputSocket.Type)
            {
                Edge edge    = new Edge(outputSocket, inputSocket);
                Edge oldEdge = inputSocket.Edge;
                inputSocket.Edge = edge;
                outputSocket.Edges.Add(edge);

                if (!AllowCicles && HasCycle())
                {
                    // revert
                    inputSocket.Edge = oldEdge;
                    outputSocket.Edges.Remove(edge);
                    Log.Info("Can not link sockets. Circles are not allowed.");
                    return(false);
                }

                if (TriggerEvents)
                {
                    EventManager.TriggerOnLinkEdge(this, edge);
                }
            }
            return(true);
        }
Example #11
0
 public void GUIDrawEdge(InputSocket socket, bool highlight, bool hover)
 {
     if (socket.IsConnected())
     {
         socket.Edge.Draw(highlight, hover);
     }
 }
Example #12
0
 public RangeNode(int id, Graph parent) : base(id, parent)
 {
     _inputSocket01 = new InputSocket(this, typeof(AbstractNumberNode));
     Sockets.Add(_inputSocket01);
     Height = 60;
     Width  = 100;
 }
Example #13
0
        private void AddGameObjectsSocket()
        {
            var gameObjectsSocket = new InputSocket(this, typeof(IEntitiesConnection));

            Sockets.Insert(GetNextGameObjectsSocketIndex(), gameObjectsSocket);
            _entitiesCount++;
        }
Example #14
0
        public void UnLink(AbstractSocket socket)
        {
            if (socket == null || !socket.IsConnected())
            {
                return;
            }


            if (socket.IsInput())
            {
                InputSocket inputSocket = (InputSocket)socket;
                if (inputSocket.Edge != null)
                {
                    UnLink(inputSocket, inputSocket.Edge.Output);
                }
            }

            if (socket.IsOutput())
            {
                OutputSocket outputSocket = (OutputSocket)socket;
                Edge[]       edgeCopy     = new Edge[outputSocket.Edges.Count];
                outputSocket.Edges.CopyTo(edgeCopy);
                foreach (var edge in edgeCopy)
                {
                    UnLink(edge.Input, outputSocket);
                }
            }
        }
Example #15
0
        private void AddLandscapeSocket()
        {
            var landscapeSocket = new InputSocket(this, typeof(ILandscapeConnection));

            Sockets.Insert(GetNextLandscapeSocketIndex(), landscapeSocket);
            _landscapeCount++;
        }
Example #16
0
        /// <summary> Converts this node to a SerializableNode </summary>
        public SerializableNode ToSerializedNode()
        {
            SerializableNode n = new SerializableNode();

            n.type              = GetType().FullName;
            n.id                = Id;
            n.X                 = WindowRect.xMin;
            n.Y                 = WindowRect.yMin;
            n.Collapsed         = Collapsed;
            n.directInputValues = new float[Sockets.Count];

            for (var i = 0; i < n.directInputValues.Length; i++)
            {
                if (Sockets[i].IsInput())
                {
                    InputSocket inputSocket = (InputSocket)Sockets[i];
                    if (inputSocket.IsInDirectInputMode())
                    {
                        n.directInputValues[i] = inputSocket.GetDirectInputNumber();
                    }
                }
            }

            n.data = JsonUtility.ToJson(this);             // custom node data can be used
            OnSerialization(n);
            return(n);
        }
Example #17
0
        private void Attach(OutputSocket start, InputSocket end)
        {
            if (!IsValidAttach(start, end))
            {
                return;
            }

            string[] paths          = end.SocketPath.Split('.');
            var      obj            = SerializedObjectPool.Grab(end.ParentNode);
            var      socketProperty = obj.FindProperty(paths[0]);

            UnityEngine.Debug.Log(socketProperty.displayName);

            for (int i = 1; i < paths.Length; i++)
            {
                socketProperty = socketProperty.FindPropertyRelative(paths[i]);
            }

            var sourceNodeProperty = socketProperty.FindPropertyRelative("SourceNode");
            var sourcePathProperty = socketProperty.FindPropertyRelative("SourcePath");

            sourceNodeProperty.objectReferenceValue = start.ParentNode;
            sourcePathProperty.stringValue          = start.SocketPath;

            obj.ApplyModifiedProperties();

            Repaint();
        }
Example #18
0
        public void UnLink(AbstractSocket socket)
        {
            if (socket == null || !socket.IsConnected())
            {
                return;
            }


            if (socket.IsInput())
            {
                InputSocket inputSocket = (InputSocket)socket;
                if (inputSocket.Edge != null)
                {
                    UnLink(inputSocket, inputSocket.Edge.Output);
                }
            }

            if (socket.IsOutput())
            {
                OutputSocket outputSocket = (OutputSocket)socket;
                Edge[]       edgeCopy     = new Edge[outputSocket.Edges.Count];
                outputSocket.Edges.CopyTo(edgeCopy);
                for (int index = 0; index < edgeCopy.Length; index++)
                {
                    var edge = edgeCopy[index];
                    UnLink(edge.Input, outputSocket);
                }
            }
        }
Example #19
0
 public ExponentialGate()
 {
     this.baseSocket     = new InputSocket <double>();
     this.exponentSocket = new InputSocket <double>();
     this.defaultSocket  = new InputSocket <double>();
     this.resultSocket   = new OutputSocket <double>();
 }
Example #20
0
 public UnfoldGate(double trueValue, double falseValue)
 {
     this.valueSocket      = new InputSocket <bool>();
     this.trueValueSocket  = new InputSocket <double>(trueValue);
     this.falseValueSocket = new InputSocket <double>(falseValue);
     this.resultSocket     = new OutputSocket <double>();
 }
Example #21
0
 public InvertColorNode(int id, Graph parent) : base(id, parent)
 {
     _inputSocketColor = new InputSocket(this, typeof(IColorConnection));
     Sockets.Add(_inputSocketColor);
     Sockets.Add(new OutputSocket(this, typeof(IColorConnection)));
     Width  = 70;
     Height = 40;
 }
Example #22
0
 public RepeatColorNode(int id, Graph parent) : base(id, parent)
 {
     _inputSocket = new InputSocket(this, typeof(IColorConnection));
     Sockets.Add(_inputSocket);
     Sockets.Add(new OutputSocket(this, typeof(IColorConnection)));
     Name   = "";
     Height = 40;
 }
Example #23
0
 public RangeNode(int id, Graph parent) : base(id, parent)
 {
     _inputSocket01 = new InputSocket(this, typeof(INumberConnection));
     Sockets.Add(_inputSocket01);
     Sockets.Add(new OutputSocket(this, typeof(INumberConnection)));
     Height = 80;
     Width  = 100;
 }
Example #24
0
 public AbsNode(int id, Graph parent) : base(id, parent)
 {
     _inputSocket = new InputSocket(this, typeof(INumberConnection));
     Sockets.Add(_inputSocket);
     Sockets.Add(new OutputSocket(this, typeof(INumberConnection)));
     Width  = 40;
     Height = 40;
 }
Example #25
0
 public DisplayColorMapNode(int id, Graph parent) : base(id, parent)
 {
     _texture     = new GUIThreadedTexture();
     _inputSocket = new InputSocket(this, typeof(IColorMapConnection));
     Sockets.Add(_inputSocket);
     Width  = MinWidth;
     Height = MinHeight;
 }
        public AbstracStateConditionNode(int id, Graph parent) : base(id, parent)
        {
            inputSocket01 = new InputSocket(this, typeof(AbstracMonsterAINode));
            outSocket     = new OutputSocket(this, typeof(AbstracStateConditionNode));

            Sockets.Add(outSocket);
            Sockets.Add(inputSocket01);
        }
Example #27
0
 public DivisionGate()
 {
     this.dividendSocket  = new InputSocket <double>();
     this.divisorSocket   = new InputSocket <double>();
     this.defaultSocket   = new InputSocket <double>();
     this.resultSocket    = new OutputSocket <double>();
     this.remainderSocket = new OutputSocket <double>();
 }
Example #28
0
        public InputSocketView GetInputSocketControl(InputSocket soc)
        {
            var a = from b in InputSocketControls
                    where b.sock == soc
                    select b;

            return(a.First());
        }
Example #29
0
 public bool AreConected(InputSocket inputSocket, OutputSocket outputSocket)
 {
     if (inputSocket == null || outputSocket == null || inputSocket.Edge == null || outputSocket.Edges.Count == 0)
     {
         return(false);
     }
     return(outputSocket.Edges.Contains(inputSocket.Edge));
 }
Example #30
0
 public PowNode(int id, Graph parent) : base(id, parent)
 {
     _valueSocket01 = new InputSocket(this, typeof(AbstractNumberNode));
     _valueSocket02 = new InputSocket(this, typeof(AbstractNumberNode));
     Sockets.Add(_valueSocket01);
     Sockets.Add(_valueSocket02);
     Width  = 50;
     Height = 60;
 }