Esempio n. 1
0
        public bool Link(InputSocket inputSocket, OutputSocket outputSocket)
        {
            if (!this.CanBeLinked(inputSocket, outputSocket))
            {
                Debug.LogWarning("Sockets can not be linked.");
                return(false);
            }

            if (inputSocket.Type == outputSocket.Type)
            {
                Connection connection = new Connection(outputSocket, inputSocket);
                inputSocket.Connection = connection;
                outputSocket.Connections.Add(connection);

                var outEnc = outputSocket.Parent as EncounterNodeBase;
                var inEnc  = inputSocket.Parent as EncounterNodeBase;
                outEnc.Encounter.Outputs.Add(inEnc.Encounter.Id);

                if (this.TriggerEvents)
                {
                    EventManager.TriggerOnLinkEdge(this, connection);
                }
            }

            return(true);
        }
Esempio n. 2
0
        public void UnLink(AbstractSocket socket)
        {
            if ((socket == null) || !socket.IsConnected())
            {
                return;
            }


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

            if (socket.IsOutput())
            {
                OutputSocket outputSocket   = (OutputSocket)socket;
                Connection[] connectionCopy = new Connection[outputSocket.Connections.Count];
                outputSocket.Connections.CopyTo(connectionCopy);
                foreach (Connection edge in connectionCopy)
                {
                    this.UnLink(edge.Input, outputSocket);
                }
            }
        }
Esempio n. 3
0
        public bool AreConected(InputSocket inputSocket, OutputSocket outputSocket)
        {
            if ((inputSocket == null) || (outputSocket == null) || (inputSocket.Connection == null) ||
                (outputSocket.Connections.Count == 0))
            {
                return(false);
            }

            return(outputSocket.Connections.Contains(inputSocket.Connection));
        }
Esempio n. 4
0
 public void GUIDrawEdges()
 {
     foreach (AbstractSocket socket in this.Sockets)
     {
         if (socket.IsInput()) // draw only input sockets to avoid double drawing of edges
         {
             InputSocket inputSocket = (InputSocket)socket;
             if (inputSocket.IsConnected())
             {
                 inputSocket.Connection.Draw();
             }
         }
     }
 }
Esempio n. 5
0
        /// <summary>Unlinkes the assigned sockets. Triggeres 'Unlink' events.</summary>
        public void UnLink(InputSocket inputSocket, OutputSocket outputSocket)
        {
            if ((inputSocket == null) || (outputSocket == null) || !inputSocket.IsConnected() ||
                !outputSocket.IsConnected())
            {
                return;
            }
            if (!this.AreConected(inputSocket, outputSocket))
            {
                return;
            }

            if (this.TriggerEvents)
            {
                EventManager.TriggerOnUnLinkSockets(this, inputSocket, outputSocket);
            }

            var outEnc = outputSocket.Parent as EncounterNodeBase;
            var inEnc  = inputSocket.Parent as EncounterNodeBase;

            outEnc.Encounter.Outputs.Remove(inEnc.Encounter.Id);

            int index = outputSocket.Connections.IndexOf(inputSocket.Connection);

            if (index > -1)
            {
                outputSocket.Connections[index].Input  = null;
                outputSocket.Connections[index].Output = null;
                outputSocket.Connections.RemoveAt(index);
            }

            inputSocket.Connection.Input  = null;
            inputSocket.Connection.Output = null;
            inputSocket.Connection        = null;

            if (this.TriggerEvents)
            {
                EventManager.TriggerOnUnLinkedSockets(this, inputSocket, outputSocket);
            }
        }
Esempio n. 6
0
 /// <summary> Returns true if the sockets can be linked.</summary>
 /// <param name="inSocket"> The input socket</param>
 /// <param name="outSocket"> The output socket</param>
 /// <returns>True if the sockets can be linked.</returns>
 public bool CanBeLinked(InputSocket inSocket, OutputSocket outSocket)
 {
     return((inSocket != null) && (outSocket != null) && (outSocket.Type == inSocket.Type));
 }
Esempio n. 7
0
 public Connection(OutputSocket outputSocket, InputSocket inputSocket)
 {
     this.Input  = inputSocket;
     this.Output = outputSocket;
 }