static private void DrawConnector(Rect nodeRect, NodeValue nodeValue, int index) { Vector2 connectorPosition = GetConnectorPosition(nodeValue); DrawCircle(connectorPosition, nodeValue.variantValue.typeColor); EditorGUIUtility.AddCursorRect(GetConnectorRect(nodeValue), MouseCursor.ArrowPlus); string nodeValueLabel = NodeValueLabel(nodeValue); float width = nodeRect.width - s_connectorDiameter * 2; if (nodeValue.isOutput) { GUIStyle outputNameStyle = new GUIStyle(EditorStyles.label); outputNameStyle.alignment = TextAnchor.MiddleRight; Rect labelRect = new Rect(connectorPosition - new Vector2(width + 4 + s_connectorDiameter / 2, Node.connectorSpacing / 2), new Vector2(width, Node.connectorSpacing)); if (index >= 1) { EditorGUI.LabelField(labelRect, nodeValueLabel, outputNameStyle); } } else { GUIStyle inputNameStyle = new GUIStyle(EditorStyles.label); inputNameStyle.alignment = TextAnchor.MiddleLeft; float nameWidth = inputNameStyle.CalcSize(new GUIContent(nodeValueLabel)).x; Rect variantArea = new Rect(connectorPosition + new Vector2(Node.connectorSpacing / 2 + 2, -Node.connectorSpacing / 2), new Vector2(width - nameWidth, Node.connectorSpacing)); Rect labelRect; if (nodeValue.connection == null) { labelRect = variantArea; labelRect.x += width - nameWidth; } else { labelRect = new Rect(connectorPosition + new Vector2(Node.connectorSpacing / 2 + 2, -Node.connectorSpacing / 2), new Vector2(width, Node.connectorSpacing)); } EditorGUI.LabelField(labelRect, nodeValueLabel, inputNameStyle); if (nodeValue.connection == null) { GUILayout.BeginArea(variantArea); EditorGUI.BeginChangeCheck(); Variant tmp = new Variant(VariantView.VariantDataField(nodeValue.variantValue.variantData), nodeValue.variantValue.typeName); if (tmp != nodeValue.variantValue) { Undo.RecordObject(nodeValue, "Changed node value"); nodeValue.variantValue = tmp; TriggerEditorWindow.SetSceneDirty(); } GUILayout.EndArea(); } } }
static private void DeleteNodeCallback(object obj) { DeleteNodeCallbackObject deleteNodeCallbackObject = (DeleteNodeCallbackObject)obj; Undo.RegisterCompleteObjectUndo(deleteNodeCallbackObject.routine, "Deleted node"); deleteNodeCallbackObject.routine.RemoveNode(deleteNodeCallbackObject.nodeToDelete); TriggerEditorWindow.SetSceneDirty(); }
static public void OnLeftMouseButton(Routine routine, Event mouseEvent) { switch (mouseEvent.type) { case EventType.MouseDown: m_selectedConnector = GetConnectorAtPosition(routine, mouseEvent.mousePosition); if (m_selectedConnector != null) { m_selectedConnectorPosition = NodeView.GetConnectorPosition(m_selectedConnector); m_selectedNode = null; } else { m_selectedNode = GetNodeAtPosition(routine, mouseEvent.mousePosition); if (m_selectedNode != null) { Undo.RegisterCompleteObjectUndo(m_selectedNode, "Drag Node"); Undo.FlushUndoRecordObjects(); } } break; case EventType.MouseDrag: if (m_selectedNode != null) { m_selectedNode.MoveBy(mouseEvent.delta); TriggerEditorWindow.SetSceneDirty(); mouseEvent.Use(); } break; case EventType.MouseUp: if (m_selectedConnector != null) { NodeValue otherConnector = GetConnectorAtPosition(routine, mouseEvent.mousePosition); if (m_selectedConnector.FakeConnect(otherConnector)) { if (m_selectedConnector.isOutput) { Undo.RegisterCompleteObjectUndo(otherConnector, "Changed node connection"); } else { Undo.RegisterCompleteObjectUndo(m_selectedConnector, "Changed node connection"); } m_selectedConnector.TryConnectWith(otherConnector); TriggerEditorWindow.SetSceneDirty(); } mouseEvent.Use(); } m_selectedNode = null; m_selectedConnector = null; break; } }
static public void CreateWindow() { s_window = GetWindow <TriggerEditorWindow>("Triggers editor"); }