public void DrawContextMenuButtons()
        {
            if (contextData.Count == 0)
            {
                return;
            }

            FoCsGUI.Layout.Space(4);
            FoCsGUI.Layout.LabelField("Context Menu:", FoCsGUI.Styles.Unity.BoldLabel);
            //TODO: Refine ContextMenuLayoutAttribute Logic
            var rectRows = new Dictionary <int, Rect>();

            foreach (var kv in contextData)
            {
                var enabledState = GUI.enabled;
                var isEnabled    = true;

                if (kv.Value.Validate != null)
                {
                    isEnabled = (bool)kv.Value.Validate.Invoke(target, null);
                }

                GUI.enabled = isEnabled;

                if (kv.Value.Function != null)
                {
                    if (kv.Value.Layout.HasValue)
                    {
                        var  layout = kv.Value.Layout.Value;
                        Rect rect;

                        if (rectRows.ContainsKey(layout.Column))
                        {
                            rect = rectRows[layout.Column];
                        }
                        else
                        {
                            FoCsGUI.Layout.Space();
                            rect = GUILayoutUtility.GetLastRect();
                            rectRows.Add(layout.Column, rect);
                        }

                        using (var scope = Disposables.RectHorizontalScope(layout.AmountPerLine, rect)) {
                            if (layout.Row != 0)
                            {
                                scope.GetNext(layout.Row);
                            }

                            if (FoCsGUI.Button(scope.GetNext(), kv.Key))
                            {
                                InvokeMethod(kv);
                            }
                        }
                    }
                    else
                    {
                        if (FoCsGUI.Layout.Button(kv.Key))
                        {
                            InvokeMethod(kv);
                        }
                    }
                }

                GUI.enabled = enabledState;
            }
        }
Ejemplo n.º 2
0
 public static GUIEvent HelpBox(string text) => FoCsGUI.HelpBox(GUILayoutUtility.GetRect(0, SingleLine * 2.5f, Styles.Unity.HelpBox, null), text);
 public float PropertyHeight(SerializedProperty property) => FoCsGUI.GetPropertyHeight(property);