Пример #1
0
        protected override float GetHeight(float width, GUIContent label)
        {
            var height = LudiqGUIUtility.GetHelpBoxHeight(message, MessageType.Warning, width);

            height += EditorGUIUtility.standardVerticalSpacing;
            return(height);
        }
        public static void ExportMessageIcon()
        {
            var size = 16;

            var type = MessageType.Warning;

            var restoreSize = EditorGUIUtility.GetIconSize();

            EditorGUIUtility.SetIconSize(new Vector2(size, size));

            var icon = LudiqGUIUtility.GetHelpIcon(type);

            icon.filterMode = FilterMode.Point;
            var rt = RenderTexture.GetTemporary(icon.width, icon.height);

            rt.filterMode        = FilterMode.Point;
            RenderTexture.active = rt;
            Graphics.Blit(icon, rt);
            var readableIcon = new Texture2D(icon.width, icon.height);

            readableIcon.ReadPixels(new Rect(0, 0, icon.width, icon.height), 0, 0);
            readableIcon.Apply();
            RenderTexture.active = null;
            icon = readableIcon;

            File.WriteAllBytes($"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), type.ToString())}@{size}x.png", icon.EncodeToPNG());

            EditorGUIUtility.SetIconSize(restoreSize);
        }
Пример #3
0
        public Rect GetLayoutPosition(GUIContent label = null, float scrollbarTrigger = 14, RectOffset offset = null)
        {
            var width = LudiqGUIUtility.GetLayoutWidth(offset);

            LudiqGUIUtility.currentInspectorHasScrollbar = width < LudiqGUIUtility.currentInspectorWidth - scrollbarTrigger;

            return(LudiqGUIUtility.GetLayoutRect(GetCachedHeight(width, label, null), offset));
        }
 private static void OnHierarchyChange()
 {
     if (PluginContainer.initialized)
     {
         LudiqGUIUtility.BeginNotActuallyOnGUI();
         onHierarchyChange?.Invoke();
         LudiqGUIUtility.EndNotActuallyOnGUI();
     }
 }
 private static void OnUndoRedo()
 {
     if (PluginContainer.initialized)
     {
         LudiqGUIUtility.BeginNotActuallyOnGUI();
         onUndoRedo?.Invoke();
         LudiqGUIUtility.EndNotActuallyOnGUI();
     }
 }
Пример #6
0
        private float GetBackgroundEmbedWarningHeight(float width)
        {
            var fixContent = new GUIContent("Fix");

            var fixButtonWidth = Styles.fixBackgroundEmbedButton.CalcSize(fixContent).x - (Styles.spaceBeforeButton / 2);
            var warningWidth   = width - fixButtonWidth - (Styles.spaceBeforeButton / 2);
            var warningHeight  = LudiqGUIUtility.GetHelpBoxHeight(BackgroundEmbedWarning, MessageType.Warning, warningWidth);

            return(warningHeight);
        }
Пример #7
0
        public void OnGUI(Rect position)
        {
            HandleResizing(position);

            if (Event.current.ShouldSkip(position))
            {
                return;
            }

            if (e.IsRepaint)
            {
                Styles.background.Draw(position, false, false, false, false);
            }

            if (anchor == SidebarAnchor.Left)
            {
                // leave space for scrolling after the potential scrollbar
                position.width -= Styles.resizeGrip;
            }

            LudiqGUIUtility.BeginScrollablePanel(position, width => GetHeight(position.height), out Rect sidebarScrolledPosition, ref scroll);

            var y = sidebarScrolledPosition.y;

            for (int i = 0; i < displayedPanels.Count; i++)
            {
                var panel  = displayedPanels[i];
                var isLast = i == displayedPanels.Count - 1;

                if (isLast)
                {
                    var remainingHeight = sidebarScrolledPosition.height - y - 1;
                    var minPanelHeight  = panel.content.minSize.y;
                    var heightOverride  = Mathf.Max(remainingHeight, minPanelHeight);
                    panel.OnGUI(sidebarScrolledPosition, ref y, heightOverride);
                }
                else
                {
                    panel.OnGUI(sidebarScrolledPosition, ref y);
                }

                if (e.IsRepaint)
                {
                    Styles.separator.Draw(sidebarScrolledPosition.VerticalSection(ref y, 1), false, false, false, false);
                }
            }

            LudiqGUIUtility.EndScrollablePanel();

            if (e.IsRepaint)
            {
                Styles.separator.Draw(new Rect(position.x, position.y, 1, position.height), false, false, false, false);
            }
        }
Пример #8
0
        public static GUIStyle ProcessLabelStyle(Metadata metadata, GUIStyle labelStyle)
        {
            if (labelStyle == null)
            {
                labelStyle = defaultLabelStyle.value ?? EditorStyles.label;
            }

            if (metadata.isPrefabDiff)
            {
                labelStyle = LudiqGUIUtility.BoldedStyle(labelStyle);
            }

            return(labelStyle);
        }
Пример #9
0
        private static void OnHierarchyChange()
        {
            if (PluginContainer.initialized)
            {
                if (!BoltCore.Configuration.isVisualScriptingUsed)
                {
                    return;
                }

                LudiqGUIUtility.BeginNotActuallyOnGUI();
                onHierarchyChange?.Invoke();
                LudiqGUIUtility.EndNotActuallyOnGUI();
            }
        }
Пример #10
0
        private static void OnUndoRedo()
        {
            if (PluginContainer.initialized)
            {
                if (!VSUsageUtility.isVisualScriptingUsed)
                {
                    return;
                }

                LudiqGUIUtility.BeginNotActuallyOnGUI();
                onUndoRedo?.Invoke();
                LudiqGUIUtility.EndNotActuallyOnGUI();
            }
        }
Пример #11
0
        private void OnBackgroundEmbedWarningGUI(Rect position, ref float y)
        {
            var fixContent = new GUIContent("Fix");

            var fixButtonWidth = Styles.fixBackgroundEmbedButton.CalcSize(fixContent).x - (Styles.spaceBeforeButton / 2);
            var warningWidth   = position.width - fixButtonWidth - (Styles.spaceBeforeButton / 2);
            var warningHeight  = LudiqGUIUtility.GetHelpBoxHeight(BackgroundEmbedWarning, MessageType.Warning, warningWidth);

            var warningPosition = new Rect
                                  (
                position.x,
                y,
                warningWidth,
                warningHeight
                                  );

            var fixButtonPosition = new Rect
                                    (
                warningPosition.xMax + Styles.spaceBeforeButton,
                y,
                fixButtonWidth,
                warningHeight
                                    );

            EditorGUI.HelpBox(warningPosition, BackgroundEmbedWarning, MessageType.Warning);

            if (GUI.Button(fixButtonPosition, fixContent))
            {
                if (EditorUtility.DisplayDialog("Background Embed Graph", "A background embed graph has been detected on this nest. This may cause slowdowns on serialization operations and unfixable background warnings. Do you want to delete the embed graph?", "Delete", "Cancel"))
                {
                    metadata.RecordUndo();
                    embedGraphMetadata.value = null;
                }
            }

            y += warningPosition.height;
        }
Пример #12
0
        private string GetFooterPortLabel(IUnitPort port)
        {
            string type;

            if (port is ValueInput)
            {
                type = ((IUnitValuePort)port).type.DisplayName() + " Input";
            }
            else if (port is ValueOutput)
            {
                type = ((IUnitValuePort)port).type.DisplayName() + " Output";
            }
            else if (port is ControlInput)
            {
                type = "Trigger Input";
            }
            else if (port is ControlOutput)
            {
                type = "Trigger Output";
            }
            else
            {
                throw new NotSupportedException();
            }

            var portDescription = PortDescription(port);

            if (!StringUtility.IsNullOrWhiteSpace(portDescription.summary))
            {
                return($"<b>{portDescription.label}:</b> {portDescription.summary} {LudiqGUIUtility.DimString($"({type})")}");
            }
            else
            {
                return($"<b>{portDescription.label}:</b> {LudiqGUIUtility.DimString($"({type})")}");
            }
        }
        public override void CachePosition()
        {
            var innerWidth  = innerPosition.width;
            var innerHeight = innerPosition.height;
            var edgeWidth   = edgePosition.width;
            var edgeHeight  = edgePosition.height;
            var labelWidth  = Styles.label.CalcSize(label).x;
            var labelHeight = EditorGUIUtility.singleLineHeight;

            sourcePosition      = canvas.Widget(transition.source).position;
            destinationPosition = canvas.Widget(transition.destination).position;

            Vector2 sourceClosestPoint;
            Vector2 destinationClosestPoint;

            LudiqGUIUtility.ClosestPoints(sourcePosition, destinationPosition, out sourceClosestPoint, out destinationClosestPoint);

            if (transition.destination != transition.source)
            {
                GraphGUI.GetConnectionEdge
                (
                    sourceClosestPoint,
                    destinationClosestPoint,
                    out sourceEdge,
                    out destinationEdge
                );
            }
            else
            {
                sourceEdge      = Edge.Right;
                destinationEdge = Edge.Left;
            }

            sourceEdgeCenter      = sourcePosition.GetEdgeCenter(sourceEdge);
            destinationEdgeCenter = destinationPosition.GetEdgeCenter(destinationEdge);

            siblingStateTransitions.Clear();

            var siblingIndex = 0;

            // Assign one common axis for transition for all siblings,
            // regardless of their inversion. The axis is arbitrarily
            // chosen as the axis for the first transition.
            var assignedTransitionAxis = false;
            var transitionAxis         = Vector2.zero;

            foreach (var graphTransition in canvas.graph.transitions)
            {
                var current = transition == graphTransition;

                var analog =
                    transition.source == graphTransition.source &&
                    transition.destination == graphTransition.destination;

                var inverted =
                    transition.source == graphTransition.destination &&
                    transition.destination == graphTransition.source;

                if (current)
                {
                    siblingIndex = siblingStateTransitions.Count;
                }

                if (current || analog || inverted)
                {
                    if (!assignedTransitionAxis)
                    {
                        var siblingStateTransitionDrawer = canvas.Widget <IStateTransitionWidget>(graphTransition);

                        transitionAxis = siblingStateTransitionDrawer.sourceEdge.Normal();

                        assignedTransitionAxis = true;
                    }

                    siblingStateTransitions.Add(graphTransition);
                }
            }

            // Fix the edge case where the source and destination perfectly overlap

            if (transitionAxis == Vector2.zero)
            {
                transitionAxis = Vector2.right;
            }

            // Calculate the spread axis and origin for the set of siblings

            var spreadAxis   = transitionAxis.Perpendicular1().Abs();
            var spreadOrigin = (sourceEdgeCenter + destinationEdgeCenter) / 2;

            if (transition.source == transition.destination)
            {
                spreadAxis   = Vector2.up;
                spreadOrigin = sourcePosition.GetEdgeCenter(Edge.Bottom) - Vector2.down * 10;
            }

            if (BoltCore.Configuration.developerMode && BoltCore.Configuration.debug)
            {
                Handles.BeginGUI();
                Handles.color = Color.yellow;
                Handles.DrawLine(spreadOrigin + spreadAxis * -1000, spreadOrigin + spreadAxis * 1000);
                Handles.EndGUI();
            }

            // Calculate the offset of the current sibling by iterating over its predecessors

            var spreadOffset       = 0f;
            var previousSpreadSize = 0f;

            for (var i = 0; i <= siblingIndex; i++)
            {
                var siblingSize           = canvas.Widget <IStateTransitionWidget>(siblingStateTransitions[i]).outerPosition.size;
                var siblingSizeProjection = GraphGUI.SizeProjection(siblingSize, spreadOrigin, spreadAxis);
                spreadOffset      += previousSpreadSize / 2 + siblingSizeProjection / 2;
                previousSpreadSize = siblingSizeProjection;
            }

            if (transition.source != transition.destination)
            {
                // Calculate the total spread size to center the sibling set

                var totalSpreadSize = 0f;

                for (var i = 0; i < siblingStateTransitions.Count; i++)
                {
                    var siblingSize           = canvas.Widget <IStateTransitionWidget>(siblingStateTransitions[i]).outerPosition.size;
                    var siblingSizeProjection = GraphGUI.SizeProjection(siblingSize, spreadOrigin, spreadAxis);
                    totalSpreadSize += siblingSizeProjection;
                }

                spreadOffset -= totalSpreadSize / 2;
            }

            // Finally, calculate the positions

            middle = spreadOrigin + spreadOffset * spreadAxis;

            var edgeX = middle.x - edgeWidth / 2;
            var edgeY = middle.y - edgeHeight / 2;

            _position = new Rect
                        (
                edgeX,
                edgeY,
                edgeWidth,
                edgeHeight
                        ).PixelPerfect();

            var innerX = innerPosition.x;
            var innerY = innerPosition.y;

            _clippingPosition = _position.Encompass(sourceEdgeCenter).Encompass(destinationEdgeCenter);

            if (transition.source != transition.destination)
            {
                entryEdge = destinationEdge;
                exitEdge  = sourceEdge;
            }
            else
            {
                entryEdge = sourceEdge;
                exitEdge  = destinationEdge;
            }

            entryEdgeCenter = edgePosition.GetEdgeCenter(entryEdge);
            exitEdgeCenter  = edgePosition.GetEdgeCenter(exitEdge);

            var x = innerX;

            iconPosition = new Rect
                           (
                x,
                innerY,
                Styles.eventIcon.fixedWidth,
                Styles.eventIcon.fixedHeight
                           ).PixelPerfect();

            x += iconPosition.width;

            var clipWidth = innerWidth - (x - innerX);

            clipPosition = new Rect
                           (
                x,
                edgeY,
                clipWidth,
                edgeHeight
                           ).PixelPerfect();

            labelInnerPosition = new Rect
                                 (
                Styles.spaceAroundIcon,
                innerY - edgeY,
                labelWidth,
                labelHeight
                                 ).PixelPerfect();
        }
Пример #14
0
 private static Rect ToWindowRect(Rect rect)
 {
     return(LudiqGUIUtility.Unclip(new Rect(0, 0, rect.width, rect.height)));
 }
Пример #15
0
 protected float GetExceptionHeight(float width)
 {
     return(LudiqGUIUtility.GetHelpBoxHeight(exceptionMessage, MessageType.Error, width));
 }
Пример #16
0
        private GUIContent GetLabelContent(IUnitPort port)
        {
            string type;

            if (port is IUnitControlPort)
            {
                type = "Flow";
            }
            else if (port is IUnitValuePort)
            {
                type = ((IUnitValuePort)port).type.DisplayName();
            }
            else if (port is IUnitInvalidPort)
            {
                type = "Invalid";
            }
            else
            {
                throw new NotSupportedException();
            }

            return(new GUIContent(string.Format($"<b>{port.Description<UnitPortDescription>().label}</b> <color=#{ColorPalette.unityForegroundDim.ToHexString()}>: {LudiqGUIUtility.EscapeRichText(type)}</color>")));
        }
Пример #17
0
 public float GetHeight(float width)
 {
     return(LudiqGUIUtility.GetHelpBoxHeight(message, messageType, width));
 }
Пример #18
0
 private float GetNoMultiEditHeight(float width)
 {
     return(LudiqGUIUtility.GetHelpBoxHeight(NoMultiEditMessage, MessageType.Info, width));
 }
Пример #19
0
 private float GetComponentPrefabWarningHeight(float width)
 {
     return(LudiqGUIUtility.GetHelpBoxHeight(ComponentPrefabWarning, MessageType.Warning, width));
 }
Пример #20
0
 private float GetNoGraphSelectedHeight(float width)
 {
     return(LudiqGUIUtility.GetHelpBoxHeight(NoGraphSelectedMessage, MessageType.Info, width));
 }
 private string DimmedKind()
 {
     return(LudiqGUIUtility.DimString($" ({kind})"));
 }