public void Connect(Operator outOp, IOOutlet output, Operator inOp, IOOutlet input, bool serialize = true) { Connections.Add(new IOConnection() { From=outOp, Output=output, To=inOp, Input=input }); if (serialize) { TemplateSerializer.Serialize(this); } }
public void Connect(Operator outOp, IOOutlet output, Operator inOp, IOOutlet input) { Connections.Add(new IOConnection() { From = outOp, Output = output, To = inOp, Input = input }); CommitChanges(); }
public IOConnection[] ConnectionsTo(Operator toOp, IOOutlet input) { var conns = new List <IOConnection>(); foreach (IOConnection conn in Connections) { if (conn.To.GUID == toOp.GUID && conn.Input == input) { conns.Add(conn); } } return(conns.ToArray()); }
public static void Deserialize(this Template template) { template.Clear(); var tplJs = new JSONObject(template.JSON); // Discard templates without the Operators and Connections fields if (tplJs.HasField("Operators") && tplJs.HasField("Connections")) { var opsJs = tplJs.GetField("Operators"); var connsJs = tplJs.GetField("Connections"); // Operators foreach (var opJs in opsJs.list) { var type = System.Type.GetType(opJs["Type"].str); if (type != null) { var op = (Operator)System.Activator.CreateInstance(type); op.Deserialize(opJs); template.Operators.Add(op.GUID, op); } else { Debug.LogWarningFormat("Discarding unknown serialized operator `{0}`", opJs["Type"].str); } } // Connections foreach (var connJs in connsJs.list) { // Discard connections with invalid Operator GUIDs if (!template.Operators.ContainsKey(connJs["From"].str) || !template.Operators.ContainsKey(connJs["To"].str)) { Debug.LogWarning("Discarding connection in template due to an invalid Operator GUID"); continue; } Operator fromOp = template.Operators[connJs["From"].str]; IOOutlet output = fromOp.GetOutput(connJs["Output"].str); Operator toOp = template.Operators[connJs["To"].str]; IOOutlet input = toOp.GetInput(connJs["Input"].str); template.Connections.Add(new IOConnection() { From = fromOp, Output = output, To = toOp, Input = input }); } } }
public static bool CanConnect(IOOutlet output, IOOutlet input) { if (!output.IsOutput || !input.IsInput) { return false; } // Multiple inputs if (input.DataType.IsCollection()) { return output.DataType == input.DataType.GetGenericArguments()[0]; } // Single inputs else { return output.DataType == input.DataType; } }
public void SetValue <T>(IOOutlet outlet, T val) { if (outlet.Member is PropertyInfo) { ((PropertyInfo)outlet.Member).SetValue(this, (object)val, null); } else if (outlet.Member is FieldInfo) { ((FieldInfo)outlet.Member).SetValue(this, (object)val); } else if (outlet.Member is MethodInfo) { ((MethodInfo)outlet.Member).Invoke(this, new object[] { (object)val }); } else { throw new System.ArgumentException(System.String.Format("Operator {0} could not set the value of {1} to {2}", Metadata.Title, outlet.Name, val)); } }
public object GetValue(IOOutlet outlet) { if (outlet.Member is PropertyInfo) { return((object)((PropertyInfo)outlet.Member).GetValue(this, null)); } else if (outlet.Member is FieldInfo) { return((object)((FieldInfo)outlet.Member).GetValue(this)); } else if (outlet.Member is MethodInfo) { return((object)((MethodInfo)outlet.Member).Invoke(this, null)); } else { throw new System.ArgumentException(System.String.Format("Operator {0} could not retrieve the value of {1}", Metadata.Title, outlet.Name)); } }
public static bool CanConnect(IOOutlet output, IOOutlet input) { if (!output.IsOutput || !input.IsInput) { return(false); } // Multiple inputs if (input.DataType.IsCollection()) { return(output.DataType == input.DataType.GetGenericArguments()[0]); } // Single inputs else { return(output.DataType == input.DataType); } }
public void SetValue(IOOutlet outlet, object val) { // Properties if (outlet.Member is PropertyInfo) { ((PropertyInfo)outlet.Member).SetValue(this, val, null); } // Fields else if (outlet.Member is FieldInfo) { // Multi inputs if (outlet.DataType.IsCollection()) { var methodInfo = outlet.DataType.GetMethod("Add"); var list = GetValue(outlet); methodInfo.Invoke(list, new object[] { val }); } // Single inputs else { ((FieldInfo)outlet.Member).SetValue(this, val); } } // Methods else if (outlet.Member is MethodInfo) { ((MethodInfo)outlet.Member).Invoke(this, new object[] { val }); } else { throw new System.ArgumentException(System.String.Format("Operator {0} could not set the value of {1} to {2}", Metadata.Title, outlet.Name, val)); } }