Пример #1
0
 public void Delete()
 {
     ConnectionGUIUtility.ConnectionEventHandler(new ConnectionEvent(ConnectionEvent.EventType.EVENT_CONNECTION_DELETED, this));
 }
Пример #2
0
        public void DrawConnection(List <NodeGUI> nodes, Dictionary <string, List <AssetReference> > 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 = m_outputPoint.GetGlobalPosition(startNode);
            var startV3    = new Vector3(startPoint.x, startPoint.y, 0f);

            var endPoint = m_inputPoint.GetGlobalPosition(endNode);
            var endV3    = new Vector3(endPoint.x, endPoint.y, 0f);

            var centerPoint   = startPoint + ((endPoint - startPoint) / 2);
            var centerPointV3 = new Vector3(centerPoint.x, centerPoint.y, 0f);

            var pointDistanceX = Model.Settings.GUI.CONNECTION_CURVE_LENGTH;

            var startTan = new Vector3(startPoint.x + pointDistanceX, centerPoint.y, 0f);
            var endTan   = new Vector3(endPoint.x - pointDistanceX, centerPoint.y, 0f);

            var totalAssets = 0;
            var totalGroups = 0;

            if (assetGroups != null)
            {
                totalAssets = assetGroups.Sum(v => v.Value == null ? 0 : v.Value.Count);
                totalGroups = assetGroups.Keys.Count;
            }

            Color lineColor;
            var   lineWidth = (totalAssets > 0) ? 3f : 2f;

            if (IsSelected)
            {
                lineColor = Model.Settings.GUI.COLOR_ENABLED;
            }
            else
            {
                lineColor = (totalAssets > 0) ? Model.Settings.GUI.COLOR_CONNECTED : Model.Settings.GUI.COLOR_NOT_CONNECTED;
            }

            ConnectionGUIUtility.HandleMaterial.SetPass(0);
            Handles.DrawBezier(startV3, endV3, startTan, endTan, lineColor, null, lineWidth);

            // draw connection label if connection's label is not normal.
            GUIStyle labelStyle = new GUIStyle("WhiteMiniLabel");

            labelStyle.alignment = TextAnchor.MiddleLeft;

            switch (Label)
            {
            case Model.Settings.DEFAULT_OUTPUTPOINT_LABEL: {
                // show nothing
                break;
            }

            case Model.Settings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL: {
                var labelWidth   = labelStyle.CalcSize(new GUIContent(Model.Settings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL));
                var labelPointV3 = new Vector3(centerPointV3.x - (labelWidth.x / 2), centerPointV3.y - 24f, 0f);
                Handles.Label(labelPointV3, Model.Settings.BUNDLECONFIG_BUNDLE_OUTPUTPOINT_LABEL, labelStyle);
                break;
            }

            default: {
                var labelWidth   = labelStyle.CalcSize(new GUIContent(Label));
                var labelPointV3 = new Vector3(centerPointV3.x - (labelWidth.x / 2), centerPointV3.y - 24f, 0f);
                Handles.Label(labelPointV3, Label, labelStyle);
                break;
            }
            }

            string connectionLabel;

            if (totalGroups > 1)
            {
                connectionLabel = $"{totalAssets}:{totalGroups}";
            }
            else
            {
                connectionLabel = $"{totalAssets}";
            }

            var style = new GUIStyle(m_connectionButtonStyle);

            var labelSize = style.CalcSize(new GUIContent(connectionLabel));

            m_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 (m_buttonRect.Contains(rightClickPos))
                {
                    var menu = new GenericMenu();
                    menu.AddItem(
                        new GUIContent("Delete"),
                        false,
                        () => {
                        Delete();
                    }
                        );
                    menu.ShowAsContext();
                    Event.current.Use();
                }
            }

            if (GUI.Button(m_buttonRect, connectionLabel, style))
            {
                this.m_assetGroups = assetGroups;
                ConnectionGUIUtility.ConnectionEventHandler(new ConnectionEvent(ConnectionEvent.EventType.EVENT_CONNECTION_TAPPED, this));
            }
        }