public void Delete() { ConnectionGUIUtility.ConnectionEventHandler(new ConnectionEvent(ConnectionEvent.EventType.EVENT_CONNECTION_DELETED, this)); }
public void DrawConnection(List <NodeGUI> nodes, Dictionary <string, List <Asset> > assetGroups) { var startNode = nodes.Find(node => node.Id == OutputNodeId); if (startNode == null) { return; } var endNode = nodes.Find(node => node.Id == InputNodeId); if (endNode == null) { return; } var startPoint = NodeGUI.ScaleEffect(outputPoint.GetGlobalPosition(startNode)); var startV3 = new Vector3(startPoint.x, startPoint.y, 0f); var endPoint = NodeGUI.ScaleEffect(inputPoint.GetGlobalPosition(endNode)); var endV3 = new Vector3(endPoint.x, endPoint.y + 1f, 0f); var centerPoint = startPoint + ((endPoint - startPoint) / 2); var centerPointV3 = new Vector3(centerPoint.x, centerPoint.y, 0f); var pointDistance = (endPoint.x - startPoint.x) / 3f; if (pointDistance < AssetBundleGraphSettings.GUI.CONNECTION_CURVE_LENGTH) { pointDistance = AssetBundleGraphSettings.GUI.CONNECTION_CURVE_LENGTH; } var startTan = new Vector3(startPoint.x + pointDistance, startPoint.y, 0f); var endTan = new Vector3(endPoint.x - pointDistance, endPoint.y, 0f); var totalAssets = 0; var totalGroups = 0; if (assetGroups != null) { totalAssets = assetGroups.Select(v => v.Value.Count).Sum(); totalGroups = assetGroups.Keys.Count; } if (conInsp != null && Selection.activeObject == conInsp && conInsp.connectionGUI == this) { Handles.DrawBezier(startV3, endV3, startTan, endTan, new Color(0.43f, 0.65f, 0.90f, 1.0f), null, 2f); } else { Handles.DrawBezier(startV3, endV3, startTan, endTan, ((totalAssets > 0) ? Color.white : Color.gray), null, 2f); } // draw connection label if connection's label is not normal. if (NodeGUI.scaleFactor == NodeGUI.SCALE_MAX) { switch (label) { case AssetBundleGraphSettings.DEFAULT_OUTPUTPOINT_LABEL: { // show nothing break; } case AssetBundleGraphSettings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL: { var labelPointV3 = new Vector3(centerPointV3.x - ((AssetBundleGraphSettings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL.Length * 6f) / 2), centerPointV3.y - 24f, 0f); Handles.Label(labelPointV3, AssetBundleGraphSettings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL, "WhiteMiniLabel"); break; } default: { var labelPointV3 = new Vector3(centerPointV3.x - ((label.Length * 7f) / 2), centerPointV3.y - 24f, 0f); Handles.Label(labelPointV3, label, "WhiteMiniLabel"); break; } } } string connectionLabel; if (totalGroups > 1) { connectionLabel = string.Format("{0}:{1}", totalAssets, totalGroups); } else { connectionLabel = string.Format("{0}", totalAssets); } var style = new GUIStyle(connectionButtonStyle); var labelSize = style.CalcSize(new GUIContent(connectionLabel)); buttonRect = new Rect(centerPointV3.x - labelSize.x / 2f, centerPointV3.y - labelSize.y / 2f, labelSize.x, 30f); if ( Event.current.type == EventType.ContextClick || (Event.current.type == EventType.MouseUp && Event.current.button == 1) ) { var rightClickPos = Event.current.mousePosition; if (buttonRect.Contains(rightClickPos)) { var menu = new GenericMenu(); menu.AddItem( new GUIContent("Delete"), false, () => { Delete(); } ); menu.ShowAsContext(); Event.current.Use(); } } if (GUI.Button(buttonRect, connectionLabel, style)) { conInsp.UpdateInspector(this, assetGroups); ConnectionGUIUtility.ConnectionEventHandler(new ConnectionEvent(ConnectionEvent.EventType.EVENT_CONNECTION_TAPPED, this)); } }