public static ByteBuffer Write(VisualNode node) { ByteBuffer bfs = new ByteBuffer(); bfs.WriteString(node.Title); bfs.WriteFloat(node.rect.x); bfs.WriteFloat(node.rect.y); bfs.WriteFloat(node.rect.width); bfs.WriteFloat(node.rect.height); bfs.WriteByte((byte)node.fields.Count); for (int i = 0; i < node.fields.Count; ++i) { bfs.WriteBytes(FieldNode.Write(node.fields[i])); } bfs.WriteBytes(FlowNode.Write(node.currentFlow)); return(bfs); }
public static void Read(ByteBuffer bfs, VisualNode node) { node.Title = bfs.ReadString(); node.rect.x = bfs.ReadFloat(); node.rect.y = bfs.ReadFloat(); node.rect.width = bfs.ReadFloat(); node.rect.height = bfs.ReadFloat(); int count = bfs.ReadByte(); for (int i = 0; i < count; ++i) { var field = FieldNode.Read(bfs.ReadBytes()); field.Target = node; node.fields.Add(field); } node.currentFlow = FlowNode.Read(bfs.ReadBytes()); node.currentFlow.Target = node; }
private void ProcessEvent(Event current) { WindowDrag = Vector2.zero; Vector2 vectorPos = current.mousePosition; if (RectDesc.Contains(vectorPos)) { return; } if (current.type == EventType.MouseDown) { if (current.button == 1)//right mouse { var menu = new GenericMenu(); var n = OnFocusOnNode(vectorPos); if (n != null) { menu.AddItem(new GUIContent("Delete"), false, OnDeleteNodeHandler, n); menu.ShowAsContext(); Event.current.Use(); } else { menu.AddItem(new GUIContent("Variable/Set"), false, OnCreateNewVarNodeHandler, vectorPos); menu.AddItem(new GUIContent("Variable/Get"), false, OnCreateGetVarNodeHandler, vectorPos); menu.AddItem(new GUIContent("Function"), false, OnCreateFunctionNodeHandler, vectorPos); menu.AddItem(new GUIContent("Calculation/Add"), false, OnCreateAddHandler, vectorPos); menu.AddItem(new GUIContent("Calculation/Minus"), false, OnCreateMinusHandler, vectorPos); menu.AddItem(new GUIContent("Calculation/Multiply"), false, OnCreateMultiplyHandler, vectorPos); menu.AddItem(new GUIContent("Calculation/Division"), false, OnCreateDivisionHandler, vectorPos); menu.AddItem(new GUIContent("Process"), false, OnCreateProcessNodeHandler, vectorPos); menu.ShowAsContext(); Event.current.Use(); } } else//left mouse { Nodes.ForEach((nod) => nod.UpdateAccessRectReadyState(vectorPos)); SelectedNode = OnFocusOnNode(vectorPos); } } else if (current.type == EventType.MouseDrag) { if (current.button == 2) { var n = OnFocusOnNode(vectorPos); if (n == null) { WindowDrag = current.delta; Nodes.ForEach((item) => { item.rect.position += current.delta; }); Repaint(); } } } else if (current.type == EventType.MouseUp) { AccessNode.AccessRect rect = null; Nodes.ForEach((node) => { var rst = node.FindReadyStateAccessRect(); if (rst != null) { rect = rst; } }); if (rect != null) { foreach (var node in Nodes) { var mouseUpRect = node.GetMouseUpAccessRect(vectorPos); if (mouseUpRect != null && mouseUpRect.Target.Target != rect.Target.Target) { if (rect.Type == AccessNode.AccessRect.RectType.FieldOut && mouseUpRect.Type == AccessNode.AccessRect.RectType.FieldIn || rect.Type == AccessNode.AccessRect.RectType.FlowOut && mouseUpRect.Type == AccessNode.AccessRect.RectType.FlowIn) { rect.Target.AddNext(mouseUpRect.Target); } else if (rect.Type == AccessNode.AccessRect.RectType.FieldIn && mouseUpRect.Type == AccessNode.AccessRect.RectType.FieldOut || rect.Type == AccessNode.AccessRect.RectType.FlowIn && mouseUpRect.Type == AccessNode.AccessRect.RectType.FlowOut) { rect.Target.AddPrev(mouseUpRect.Target); } break; } } } Nodes.ForEach((nod) => nod.ResetAllReadyState2Zero()); } }
public static byte[] Write(GetVarNode node) { ByteBuffer bfs = VisualNode.Write(node); return(bfs.Getbuffer()); }
public FieldNode(int index, VisualNode target) : base(target) { OutRect.Type = AccessRect.RectType.FieldOut; InRect.Type = AccessRect.RectType.FieldIn; Index = index; }
public FlowNode(VisualNode target) : base(target) { OutRect.Type = AccessRect.RectType.FlowOut; InRect.Type = AccessRect.RectType.FlowIn; }
public void AddNode(VisualNode node) { Nodes.Add(node); node.OnAccessNodeModify = OnAccessNodeModifyHandler; node.OnFieldGetInfo = OnGetAccessNodeInfoHandler; }