示例#1
0
            public C GetEntry(IBehaviourContext context)
            {
                C foundEntry;

                if (SourceNode == null)
                {
                    if (defaultEntry == null)
                    {
                        defaultEntry = new C
                        {
                            Value = defaultValue
                        };
                    }

                    foundEntry = defaultEntry;

                    return(foundEntry);
                }

                if (contextCahce == null)
                {
                    contextCahce = new Dictionary <IBehaviourContext, C> ();
                }

                bool result = contextCahce.TryGetValue(context, out foundEntry);

                if (!result)
                {
                    foundEntry = new C();

                    contextCahce.Add(context, foundEntry);

                    Socket sourceOutput = (Socket)SourceSocket;

                    ConnectionEntry connectionEntry = sourceOutput.GetBaseEntry(context);

                    if (!typeof(ISocketConvertable <T>).IsAssignableFrom(connectionEntry.GetType()))
                    {
                        Debug.Log(SourceSocket.GetType().Name + " is not convertable to "
                                  + GetType().Name);
                    }

                    ISocketConvertable <T> socket = (ISocketConvertable <T>)connectionEntry;

                    connectionEntry.OnAfterChanged += () =>
                    {
                        foundEntry.Value = socket.Convert;
                    };
                }

                return(foundEntry);
            }
示例#2
0
            public C GetEntry(IBehaviourContext context)
            {
                if (SourceSocket == null)
                {
                    if (defaultEntry == null)
                    {
                        defaultEntry = new C
                        {
                            Value = defaultValue
                        };
                    }

                    return(defaultEntry);
                }

                if (contextCahce == null)
                {
                    contextCahce = new Dictionary <IBehaviourContext, C> ();
                }

                C foundEntry;

                bool result = contextCahce.TryGetValue(context, out foundEntry);

                if (!result || ContextUtility.currentIndex != -1)
                {
                    foundEntry = new C();

                    if (ContextUtility.currentIndex == -1)
                    {
                        contextCahce.Add(context, foundEntry);
                    }

                    if (typeof(ListOutput).IsAssignableFrom(SourceSocket.GetType()))
                    {
                        ListOutput list = (ListOutput)SourceSocket;

                        EntryCollection entries = list.GetEntry(context);

                        // If this is a root thing
                        if (ContextUtility.currentIndex == -1)
                        {
                            for (int i = 0; i < entries.Count; i++)
                            {
                                C   entry = entries[i];
                                int index = i;
                                ContextUtility.currentIndex = index;

                                ParentNode.SetupContext(context);
                            }
                            ContextUtility.currentIndex = -1;

                            entries.OnAddEntry += (C entry) =>
                            {
                                ContextUtility.currentIndex = entries.Count - 1;
                                ParentNode.SetupContext(context);
                                ContextUtility.currentIndex = -1;
                            };

                            entries.OnRemoveEntry += (C entry) =>
                            {
                                entry.Value = default(T);

                                //ContextUtility.currentIndex = entries.Count - 1;
                                //ParentNode.Remove (context);
                                //ContextUtility.currentIndex = -1;
                            };
                        }
                        else
                        {
                            ConnectionEntry connectionEntry = entries[ContextUtility.currentIndex];

                            if (!typeof(ISocketConvertable <T>).IsAssignableFrom(connectionEntry.GetType()))
                            {
                                Debug.Log(SourceSocket.GetType().Name + " is not convertable to "
                                          + GetType().Name);
                            }

                            ISocketConvertable <T> socket = (ISocketConvertable <T>)connectionEntry;

                            connectionEntry.OnAfterChanged += () =>
                            {
                                foundEntry.Value = socket.Convert;
                            };

                            foundEntry.Value = socket.Convert;
                        }
                    }
                    else
                    {
                        Socket sourceOutput = (Socket)SourceSocket;

                        ConnectionEntry connectionEntry = sourceOutput.GetBaseEntry(context);

                        if (!typeof(ISocketConvertable <T>).IsAssignableFrom(connectionEntry.GetType()))
                        {
                            Debug.Log(SourceSocket.GetType().Name + " is not convertable to "
                                      + GetType().Name);
                        }

                        ISocketConvertable <T> socket = (ISocketConvertable <T>)connectionEntry;

                        connectionEntry.OnAfterChanged += () =>
                        {
                            foundEntry.Value = socket.Convert;
                        };

                        foundEntry.Value = socket.Convert;
                    }
                }

                return(foundEntry);
            }