Exemplo n.º 1
0
        public void Connect(Node node, NodeLink link)
        {
            object value = FieldInfo.GetValue(node);

            if (IsList)
            {
                if (value == null)
                {
                    Type listType            = typeof(List <>);
                    Type constructedListType = listType.MakeGenericType(LinkType);
                    value = Activator.CreateInstance(constructedListType);
                    FieldInfo.SetValue(node, value);
                }
                FieldType.GetMethod("Remove").Invoke(value, new object[] { null });
                FieldType.GetMethod("Add").Invoke(value, new [] { link });
            }
            else
            {
                FieldInfo.SetValue(node, link);
            }

            if (IsInput)
            {
                link.to      = node;
                link.toField = FieldName;
            }
            else
            {
                link.from      = node;
                link.fromField = FieldName;
            }

            link.UpdateName();
        }
Exemplo n.º 2
0
        public NodeLink GetEmptyLink()
        {
            var existing = GetConnections().Find(x => IsInput ? x.from == null : x.to == null);

            if (existing)
            {
                return(existing);
            }

            var linkType = Link.LinkType;

            NodeLink link;

            if (IsOutput)
            {
                link = NodeLink.Create(linkType, Node, null, Link.FieldName, null);
            }
            else
            {
                link = NodeLink.Create(linkType, null, Node, null, Link.FieldName);
            }

            Link.Connect(Node, link);

            return(link);
        }
Exemplo n.º 3
0
        public NodeLink Connect(NodeLinkPort other)
        {
            NodeLink link = GetEmptyLink();

            other.Link.Connect(other.Node, link);
            return(link);
        }
Exemplo n.º 4
0
        static public NodeLink Create(Type type, Node start, Node end, string startFieldName, string endFieldName)
        {
            NodeLink link = CreateInstance(type) as NodeLink;

            link.from      = start;
            link.to        = end;
            link.fromField = startFieldName;
            link.toField   = endFieldName;
            link.UpdateName();

#if UNITY_EDITOR
            UnityEditor.AssetDatabase.AddObjectToAsset(link, start);
#endif

            return(link);
        }
Exemplo n.º 5
0
        public void Disconnect(Node node, NodeLink link)
        {
            Predicate <NodeLink> removePredicate = (x) => (!link && !x) || Equals(x, link);

            bool   result;
            object value = FieldInfo.GetValue(node);

            if (IsList)
            {
                result = ((int)FieldType.GetMethod("RemoveAll").Invoke(value, new [] { removePredicate })) > 0;
            }
            else
            {
                result = removePredicate(value as NodeLink);
                if (result)
                {
                    FieldInfo.SetValue(node, null);
                }
            }

            if (result && link)
            {
                if (IsInput && link.to == node)
                {
                    link.to      = null;
                    link.toField = null;
                }

                if (IsOutput && link.from == node)
                {
                    link.from      = null;
                    link.fromField = null;
                }

                link.UpdateName();
            }
        }