ScaleEffect() публичный статический Метод

public static ScaleEffect ( Rect nonScaledRect ) : Rect
nonScaledRect UnityEngine.Rect
Результат UnityEngine.Rect
        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));
            }
        }
Пример #2
0
        /**
         *      throughputListDict contains:
         *              group/
         *                      throughput assets
         */
        public void DrawConnection(List <NodeGUI> nodes, Dictionary <string, List <DepreacatedThroughputAsset> > throughputListDict)
        {
            var startNodes = nodes.Where(node => node.nodeId == outputNodeId).ToList();

            if (!startNodes.Any())
            {
                return;
            }

            var startPoint = startNodes[0].GlobalConnectionPointPosition(outputPoint.pointId);

            startPoint = NodeGUI.ScaleEffect(startPoint);
            var startV3 = new Vector3(startPoint.x, startPoint.y, 0f);

            var endNodes = nodes.Where(node => node.nodeId == inputNodeId).ToList();

            if (!endNodes.Any())
            {
                return;
            }

            var endPoint = endNodes[0].GlobalConnectionPointPosition(inputPoint.pointId);

            endPoint = NodeGUI.ScaleEffect(endPoint);
            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 < AssetBundleGraphGUISettings.CONNECTION_CURVE_LENGTH)
            {
                pointDistance = AssetBundleGraphGUISettings.CONNECTION_CURVE_LENGTH;
            }

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

            Handles.DrawBezier(startV3, endV3, startTan, endTan, Color.gray, null, 4f);

            // 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.BUNDLIZER_BUNDLE_OUTPUTPOINT_LABEL: {
                    var labelPointV3 = new Vector3(centerPointV3.x - ((AssetBundleGraphSettings.BUNDLIZER_BUNDLE_OUTPUTPOINT_LABEL.Length * 6f) / 2), centerPointV3.y - 24f, 0f);
                    Handles.Label(labelPointV3, AssetBundleGraphSettings.BUNDLIZER_BUNDLE_OUTPUTPOINT_LABEL);
                    break;
                }

                default: {
                    var labelPointV3 = new Vector3(centerPointV3.x - ((label.Length * 7f) / 2), centerPointV3.y - 24f, 0f);
                    Handles.Label(labelPointV3, label);
                    break;
                }
                }
            }

            // draw connection arrow.
            if (NodeGUI.scaleFactor == NodeGUI.SCALE_MAX)
            {
                GUI.DrawTexture(
                    new Rect(
                        endV3.x - AssetBundleGraphGUISettings.CONNECTION_ARROW_WIDTH + 4f,
                        endV3.y - (AssetBundleGraphGUISettings.CONNECTION_ARROW_HEIGHT / 2f) - 1f,
                        AssetBundleGraphGUISettings.CONNECTION_ARROW_WIDTH,
                        AssetBundleGraphGUISettings.CONNECTION_ARROW_HEIGHT
                        ),
                    ConnectionGUIUtility.connectionArrowTex
                    );
            }

            /*
             *      draw throughtput badge.
             */
            var throughputCount = 0;

            foreach (var list in throughputListDict.Values)
            {
                throughputCount += list.Count;
            }

            var offsetSize = throughputCount.ToString().Length * 20f;

            buttonRect = new Rect(centerPointV3.x - offsetSize / 2f, centerPointV3.y - 7f, offsetSize, 20f);

            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, throughputCount.ToString(), connectionButtonStyle))
            {
                conInsp.UpdateCon(this, throughputListDict);
                ConnectionGUIUtility.FireNodeEvent(new OnConnectionEvent(OnConnectionEvent.EventType.EVENT_CONNECTION_TAPPED, this));
            }
        }