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(); }
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); }
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(); } }