Пример #1
0
        public override void CachePosition()
        {
            // Width

            var inputsWidth  = 0f;
            var outputsWidth = 0f;

            foreach (var input in inputs)
            {
                inputsWidth = Mathf.Max(inputsWidth, input.GetInnerWidth());
            }

            foreach (var output in outputs)
            {
                outputsWidth = Mathf.Max(outputsWidth, output.GetInnerWidth());
            }

            var portsWidth = 0f;

            portsWidth += inputsWidth;
            portsWidth += Styles.spaceBetweenInputsAndOutputs;
            portsWidth += outputsWidth;

            settingsPositions.Clear();

            var settingsWidth = 0f;

            if (showSettings)
            {
                foreach (var setting in settings)
                {
                    var settingWidth = 0f;

                    var settingLabelContent = settingLabelsContents[setting];

                    if (settingLabelContent != null)
                    {
                        settingWidth += Styles.settingLabel.CalcSize(settingLabelContent).x;
                    }

                    settingWidth += setting.Inspector().GetAdaptiveWidth();

                    settingWidth = Mathf.Min(settingWidth, Styles.maxSettingsWidth);

                    settingsPositions.Add(setting, new Rect(0, 0, settingWidth, 0));

                    settingsWidth = Mathf.Max(settingsWidth, settingWidth);
                }
            }

            var headerAddonWidth = 0f;

            if (showHeaderAddon)
            {
                headerAddonWidth = GetHeaderAddonWidth();
            }

            var titleWidth = Styles.title.CalcSize(titleContent).x;

            var headerTextWidth = titleWidth;

            var surtitleWidth = 0f;

            if (showSurtitle)
            {
                surtitleWidth   = Styles.surtitle.CalcSize(surtitleContent).x;
                headerTextWidth = Mathf.Max(headerTextWidth, surtitleWidth);
            }

            var subtitleWidth = 0f;

            if (showSubtitle)
            {
                subtitleWidth   = Styles.subtitle.CalcSize(subtitleContent).x;
                headerTextWidth = Mathf.Max(headerTextWidth, subtitleWidth);
            }

            var iconsWidth = 0f;

            if (showIcons)
            {
                var iconsColumns = Mathf.Ceil((float)description.icons.Length / Styles.iconsPerColumn);
                iconsWidth = iconsColumns * Styles.iconsSize + ((iconsColumns - 1) * Styles.iconsSpacing);
            }

            var headerWidth = Mathf.Max(headerTextWidth + iconsWidth, Mathf.Max(settingsWidth, headerAddonWidth)) + Styles.iconSize + Styles.spaceAfterIcon;

            var innerWidth = Mathf.Max(portsWidth, headerWidth);

            var edgeWidth = InnerToEdgePosition(new Rect(0, 0, innerWidth, 0)).width;

            // Height & Positioning

            var edgeOrigin  = unit.position;
            var edgeX       = edgeOrigin.x;
            var edgeY       = edgeOrigin.y;
            var innerOrigin = EdgeToInnerPosition(new Rect(edgeOrigin, Vector2.zero)).position;
            var innerX      = innerOrigin.x;
            var innerY      = innerOrigin.y;

            iconPosition = new Rect
                           (
                innerX,
                innerY,
                Styles.iconSize,
                Styles.iconSize
                           );

            var headerTextX = iconPosition.xMax + Styles.spaceAfterIcon;

            var y = innerY;

            var headerHeight = 0f;

            var surtitleHeight = 0f;

            if (showSurtitle)
            {
                surtitleHeight = Styles.surtitle.CalcHeight(surtitleContent, headerTextWidth);

                surtitlePosition = new Rect
                                   (
                    headerTextX,
                    y,
                    headerTextWidth,
                    surtitleHeight
                                   );

                headerHeight += surtitleHeight;
                y            += surtitleHeight;

                headerHeight += Styles.spaceAfterSurtitle;
                y            += Styles.spaceAfterSurtitle;
            }

            var titleHeight = 0f;

            if (showTitle)
            {
                titleHeight = Styles.title.CalcHeight(titleContent, headerTextWidth);

                titlePosition = new Rect
                                (
                    headerTextX,
                    y,
                    headerTextWidth,
                    titleHeight
                                );

                headerHeight += titleHeight;
                y            += titleHeight;
            }

            var subtitleHeight = 0f;

            if (showSubtitle)
            {
                headerHeight += Styles.spaceBeforeSubtitle;
                y            += Styles.spaceBeforeSubtitle;

                subtitleHeight = Styles.subtitle.CalcHeight(subtitleContent, headerTextWidth);

                subtitlePosition = new Rect
                                   (
                    headerTextX,
                    y,
                    headerTextWidth,
                    subtitleHeight
                                   );

                headerHeight += subtitleHeight;
                y            += subtitleHeight;
            }

            iconsPositions.Clear();

            if (showIcons)
            {
                var iconRow = 0;
                var iconCol = 0;

                for (int i = 0; i < description.icons.Length; i++)
                {
                    var iconPosition = new Rect
                                       (
                        innerX + innerWidth - ((iconCol + 1) * Styles.iconsSize) - ((iconCol) * Styles.iconsSpacing),
                        innerY + (iconRow * (Styles.iconsSize + Styles.iconsSpacing)),
                        Styles.iconsSize,
                        Styles.iconsSize
                                       );

                    iconsPositions.Add(iconPosition);

                    iconRow++;

                    if (iconRow % Styles.iconsPerColumn == 0)
                    {
                        iconCol++;
                        iconRow = 0;
                    }
                }
            }

            var settingsHeight = 0f;

            if (showSettings)
            {
                headerHeight += Styles.spaceBeforeSettings;

                foreach (var setting in settings)
                {
                    var settingWidth = settingsPositions[setting].width;

                    using (LudiqGUIUtility.currentInspectorWidth.Override(settingWidth))
                    {
                        var settingHeight = LudiqGUI.GetInspectorHeight(null, setting, settingWidth, settingLabelsContents[setting] ?? GUIContent.none);

                        var settingPosition = new Rect
                                              (
                            headerTextX,
                            y,
                            settingWidth,
                            settingHeight
                                              );

                        settingsPositions[setting] = settingPosition;

                        settingsHeight += settingHeight;
                        y += settingHeight;

                        settingsHeight += Styles.spaceBetweenSettings;
                        y += Styles.spaceBetweenSettings;
                    }
                }

                settingsHeight -= Styles.spaceBetweenSettings;
                y -= Styles.spaceBetweenSettings;

                headerHeight += settingsHeight;

                headerHeight += Styles.spaceAfterSettings;
                y            += Styles.spaceAfterSettings;
            }

            if (showHeaderAddon)
            {
                var headerAddonHeight = GetHeaderAddonHeight(headerAddonWidth);

                headerAddonPosition = new Rect
                                      (
                    headerTextX,
                    y,
                    headerAddonWidth,
                    headerAddonHeight
                                      );

                headerHeight += headerAddonHeight;
                y            += headerAddonHeight;
            }

            if (headerHeight < Styles.iconSize)
            {
                var difference      = Styles.iconSize - headerHeight;
                var centeringOffset = difference / 2;

                if (showTitle)
                {
                    var _titlePosition = titlePosition;
                    _titlePosition.y += centeringOffset;
                    titlePosition     = _titlePosition;
                }

                if (showSubtitle)
                {
                    var _subtitlePosition = subtitlePosition;
                    _subtitlePosition.y += centeringOffset;
                    subtitlePosition     = _subtitlePosition;
                }

                if (showSettings)
                {
                    foreach (var setting in settings)
                    {
                        var _settingPosition = settingsPositions[setting];
                        _settingPosition.y        += centeringOffset;
                        settingsPositions[setting] = _settingPosition;
                    }
                }

                if (showHeaderAddon)
                {
                    var _headerAddonPosition = headerAddonPosition;
                    _headerAddonPosition.y += centeringOffset;
                    headerAddonPosition     = _headerAddonPosition;
                }

                headerHeight = Styles.iconSize;
            }

            y = innerY + headerHeight;

            var innerHeight = 0f;

            innerHeight += headerHeight;

            if (showPorts)
            {
                innerHeight += Styles.spaceBeforePorts;
                y           += Styles.spaceBeforePorts;

                var portsBackgroundY      = y;
                var portsBackgroundHeight = 0f;

                portsBackgroundHeight += Styles.portsBackground.padding.top;
                innerHeight           += Styles.portsBackground.padding.top;
                y += Styles.portsBackground.padding.top;

                var portStartY = y;

                var inputsHeight  = 0f;
                var outputsHeight = 0f;

                foreach (var input in inputs)
                {
                    input.y = y;

                    var inputHeight = input.GetHeight();

                    inputsHeight += inputHeight;
                    y            += inputHeight;

                    inputsHeight += Styles.spaceBetweenPorts;
                    y            += Styles.spaceBetweenPorts;
                }

                if (inputs.Count > 0)
                {
                    inputsHeight -= Styles.spaceBetweenPorts;
                    y            -= Styles.spaceBetweenPorts;
                }

                y = portStartY;

                foreach (var output in outputs)
                {
                    output.y = y;

                    var outputHeight = output.GetHeight();

                    outputsHeight += outputHeight;
                    y             += outputHeight;

                    outputsHeight += Styles.spaceBetweenPorts;
                    y             += Styles.spaceBetweenPorts;
                }

                if (outputs.Count > 0)
                {
                    outputsHeight -= Styles.spaceBetweenPorts;
                    y             -= Styles.spaceBetweenPorts;
                }

                var portsHeight = Math.Max(inputsHeight, outputsHeight);

                portsBackgroundHeight += portsHeight;
                innerHeight           += portsHeight;
                y = portStartY + portsHeight;

                portsBackgroundHeight += Styles.portsBackground.padding.bottom;
                innerHeight           += Styles.portsBackground.padding.bottom;
                y += Styles.portsBackground.padding.bottom;

                portsBackgroundPosition = new Rect
                                          (
                    edgeX,
                    portsBackgroundY,
                    edgeWidth,
                    portsBackgroundHeight
                                          );
            }

            var edgeHeight = InnerToEdgePosition(new Rect(0, 0, 0, innerHeight)).height;

            _position = new Rect
                        (
                edgeX,
                edgeY,
                edgeWidth,
                edgeHeight
                        );
        }
Пример #2
0
 private float GetValueHeight(float width)
 {
     return(LudiqGUI.GetInspectorHeight(this, valueMetadata, width));
 }
Пример #3
0
 protected override float GetHeaderAddonHeight(float width)
 {
     return(LudiqGUI.GetInspectorHeight(null, metadata, width, GUIContent.none));
 }
Пример #4
0
        internal static void OnSceneGUI(SceneView sceneView)
        {
            if (!PeekPlugin.Configuration.enableProbe)
            {
                return;
            }

            Profiler.BeginSample("Peek." + nameof(Probe));

            try
            {
                ProgramHighlight(sceneView);

#if PROBUILDER_4_OR_NEWER
                PeekProBuilderIntegration.DrawHighlight(proBuilderHighlight);
#endif

                var shortcut = PeekPlugin.Configuration.probeShortcut;

                // Make sure not to conflict with right-click pan
                shortcut.mouseShortcut.checkRelease         = true;
                shortcut.mouseShortcut.requireStaticRelease = true;

                if (shortcut.Check(e) && !SceneViewIntegration.used)
                {
                    var hits = ListPool <ProbeHit> .New();

                    try
                    {
                        PickAllNonAlloc(hits, ProbeFilter.@default, sceneView, e.mousePosition, PeekPlugin.Configuration.probeLimit);

                        if (hits.Count > 0)
                        {
                            var add = e.shift;

                            var activatorPosition = new Rect(e.mousePosition, Vector2.zero);
                            activatorPosition.width = 220;
                            activatorPosition       = LudiqGUIUtility.GUIToScreenRect(activatorPosition);

                            // Note: Had to make FuzzyWindow use OnMouseUp for select here instead
                            // of OnMouseDown because otherwise escaping the default RectSelection
                            // behaviour with the event order and DefaultControl ID's was... hell.

                            LudiqGUI.FuzzyDropdown
                            (
                                activatorPosition,
                                new ProbeOptionTree(hits),
                                null,
                                (_hit) =>
                            {
                                add    |= e?.shift ?? false;
                                var hit = (ProbeHit)_hit;
                                hit.Select(add);
                            }
                            );

                            FuzzyWindow.instance.Focus();
                            GUIUtility.hotControl = 0;                             // Escape the default RectSelection control
                            e.Use();
                        }
                    }
                    finally
                    {
                        hits.Free();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }

            Profiler.EndSample();
        }
Пример #5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (PeekPlugin.Configuration.enableReferenceInspector && !property.hasMultipleDifferentValues && property.objectReferenceValue != null)
            {
                Rect buttonPosition, fieldPosition;

                if (label != GUIContent.none)
                {
                    buttonPosition = new Rect
                                     (
                        position.x + EditorGUIUtility.labelWidth - IconSize.Small - 1,
                        position.y,
                        IconSize.Small,
                        IconSize.Small
                                     );

                    fieldPosition = position;
                }
                else
                {
                    buttonPosition = new Rect
                                     (
                        position.xMax - IconSize.Small,
                        position.y + 1,
                        IconSize.Small,
                        IconSize.Small
                                     );

                    fieldPosition = new Rect
                                    (
                        position.x,
                        position.y,
                        position.width - buttonPosition.width - 2,
                        position.height
                                    );
                }

                DefaultField(property, label, fieldPosition);

                var isActive = PopupWatcher.IsOpenOrJustClosed(lastPopup);

                var activatedButton = LudiqGUI.DropdownToggle(buttonPosition, isActive, LudiqGUIUtility.TempContent(PeekPlugin.Icons.propertyDrawer?[IconSize.Small]), GUIStyle.none);

                if (activatedButton && !isActive)
                {
                    PopupWatcher.Release(lastPopup);
                    lastPopup = null;

                    var targets = new[] { property.objectReferenceValue };
                    var activatorGuiPosition    = buttonPosition;
                    var activatorScreenPosition = LudiqGUIUtility.GUIToScreenRect(activatorGuiPosition);

                    if (e.IsContextMouseButton())
                    {
                        if (property.objectReferenceValue is GameObject go)
                        {
                            GameObjectContextMenu.Open(new[] { go }, activatorScreenPosition);
                        }
                        else
                        {
                            UnityObjectContextMenu.Open(targets, activatorGuiPosition);
                        }
                    }
                    else
                    {
                        lastPopup = EditorPopup.Open(targets, activatorScreenPosition);
                        PopupWatcher.Watch(lastPopup);
                    }
                }
            }
            else
            {
                DefaultField(property, label, position);
            }
        }
 private float GetObjectFieldHeight(float width)
 {
     return(LudiqGUI.GetFuzzyObjectFieldHeight(visualType, width));
 }
Пример #7
0
 protected virtual void OnInspectorGUI(Rect position)
 {
     LudiqGUI.Inspector(metadata, position, GUIContent.none);
 }
Пример #8
0
 private static void Header(string text)
 {
     GUILayout.Label(text, Styles.header);
     LudiqGUI.Space(4);
 }
Пример #9
0
        private void OnGUI()
        {
            EditorGUI.BeginDisabledGroup(EditorApplication.isCompiling);

            scroll = GUILayout.BeginScrollView(scroll);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.BeginVertical();

            foreach (var configuration in configurations)
            {
                if (configuration.Any(i => i.visible))
                {
                    if (configurations.Count > 1)
                    {
                        Header(configuration.header.Replace(label + " ", ""));
                    }

                    EditorGUI.BeginChangeCheck();

                    using (Inspector.expandTooltip.Override(true))
                    {
                        foreach (var item in configuration.Where(i => i.visible))
                        {
                            LudiqGUI.Space(2);

                            LudiqGUI.BeginHorizontal();

                            LudiqGUI.Space(4);

                            var iconPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(Styles.iconSize), GUILayout.Height(Styles.iconSize), GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false));

                            EditorTexture icon    = null;
                            string        tooltip = null;

                            if (item is ProjectSettingMetadata)
                            {
                                icon    = BoltCore.Icons.projectSetting;
                                tooltip = "Project Setting: Shared across users, local to this project. Included in version control.";
                            }
                            else if (item is EditorPrefMetadata)
                            {
                                icon    = BoltCore.Icons.editorPref;
                                tooltip = "Editor Pref: Local to this user, shared across projects. Excluded from version control.";
                            }

                            if (icon != null)
                            {
                                using (LudiqGUI.color.Override(GUI.color.WithAlpha(0.6f)))
                                {
                                    GUI.Label(iconPosition, new GUIContent(icon[Styles.iconSize], tooltip), GUIStyle.none);
                                }
                            }

                            LudiqGUI.Space(6);

                            LudiqGUI.BeginVertical();

                            LudiqGUI.Space(-3);

                            LudiqGUI.InspectorLayout(item);

                            LudiqGUI.EndVertical();

                            LudiqGUI.EndHorizontal();
                        }
                    }

                    if (EditorGUI.EndChangeCheck())
                    {
                        configuration.Save();
                        InternalEditorUtility.RepaintAllViews();
                    }
                }
            }

            LudiqGUI.Space(8);

            if (GUILayout.Button("Reset to Defaults"))
            {
                if (EditorUtility.DisplayDialog("Reset to Defaults", "Are you sure you want to reset your preferences and project settings to default?", "Reset"))
                {
                    foreach (var configuration in configurations)
                    {
                        configuration.Reset();
                        configuration.Save();
                    }

                    InternalEditorUtility.RepaintAllViews();
                }
            }

            LudiqGUI.Space(8);
            LudiqGUI.EndVertical();
            LudiqGUI.Space(8);
            LudiqGUI.EndHorizontal();
            GUILayout.EndScrollView();
            EditorGUI.EndDisabledGroup();
        }
        protected override void OnGUI(Rect position, GUIContent label)
        {
            // Super hacky hotfix:
            // If the value changes in between OnGUI calls,
            // the OnValueChange event will not be called, because
            // we don't even look at the value until showField is true.
            // For example, an object that was null and becomes non-null
            // will be reset to null by the inspector unless this line is here,
            // because type will be null and showField will thus be false.
            var haxHotfix = metadata.value;
            // TL;DR: storing a local private type field that does not
            // take the actual, current variable type into consideration is a
            // very bad idea and will inevitably cause inspector v. codebase fighting
            // or inspector v. inspector fighting.

            var showLabels = !adaptiveWidth && position.width >= 120;

            BeginBlock(metadata, position, GUIContent.none);

            if (chooseType)
            {
                var x = position.x;
                var remainingWidth = position.width;

                if (showLabels)
                {
                    var typeLabel = label == GUIContent.none ? new GUIContent("Type") : new GUIContent(label.text + " Type");

                    var typeLabelPosition = new Rect
                                            (
                        x,
                        y,
                        Styles.labelWidth,
                        EditorGUIUtility.singleLineHeight
                                            );

                    GUI.Label(typeLabelPosition, typeLabel, ProcessLabelStyle(metadata, null));

                    x += typeLabelPosition.width;
                    remainingWidth -= typeLabelPosition.width;
                }

                var typePosition = new Rect
                                   (
                    x,
                    y,
                    remainingWidth,
                    EditorGUIUtility.singleLineHeight
                                   );

                EditorGUI.BeginChangeCheck();

                var newType = LudiqGUI.TypeField(typePosition, GUIContent.none, type, GetTypeOptions, new GUIContent("(Null)"));

                if (EditorGUI.EndChangeCheck())
                {
                    metadata.RecordUndo();
                    type = newType;
                    EnforceType();
                    SetHeightDirty();
                }

                y += typePosition.height;
            }

            if (chooseType && showValue)
            {
                y += Styles.spaceBetweenTypeAndValue;
            }

            if (showValue)
            {
                Rect valuePosition;

                if (chooseType)
                {
                    var x = position.x;
                    var remainingWidth = position.width;

                    if (showLabels)
                    {
                        var valueLabel = label == GUIContent.none ? new GUIContent("Value") : new GUIContent(label.text + " Value");

                        var valueLabelPosition = new Rect
                                                 (
                            x,
                            y,
                            Styles.labelWidth,
                            EditorGUIUtility.singleLineHeight
                                                 );

                        GUI.Label(valueLabelPosition, valueLabel, ProcessLabelStyle(metadata, null));

                        x += valueLabelPosition.width;
                        remainingWidth -= valueLabelPosition.width;
                    }

                    valuePosition = new Rect
                                    (
                        x,
                        y,
                        remainingWidth,
                        EditorGUIUtility.singleLineHeight
                                    );

                    LudiqGUI.Inspector(metadata.Cast(type), valuePosition, GUIContent.none);
                }
                else
                {
                    valuePosition = new Rect
                                    (
                        position.x,
                        y,
                        position.width,
                        LudiqGUI.GetInspectorHeight(this, metadata.Cast(type), position.width, label)
                                    );

                    LudiqGUI.Inspector(metadata.Cast(type), valuePosition, label);
                }

                y += valuePosition.height;
            }
            else
            {
                metadata.value = null;
            }

            EndBlock(metadata);
        }
        protected override void OnContentGUI()
        {
            if (!migrations.SelectMany(m => m.requiredActions).Any())
            {
                Complete();
            }

            scroll = GUILayout.BeginScrollView(scroll, Styles.background, GUILayout.ExpandHeight(true));
            LudiqGUI.BeginVertical();

            LudiqGUI.Space(Styles.space);
            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();
            GUILayout.Label("The following required update actions could not be completed automatically. Please complete them before continuing to use the plugin.", LudiqStyles.centeredLabel, GUILayout.MaxWidth(340));
            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();
            LudiqGUI.Space(Styles.space);

            foreach (var migration in migrations)
            {
                if (!migration.requiredActions.Any())
                {
                    continue;
                }

                LudiqGUI.BeginHorizontal();
                LudiqGUI.FlexibleSpace();
                GUILayout.BeginVertical(GUILayout.MaxWidth(300));

                LudiqGUI.BeginHorizontal();
                GUILayout.Box(LudiqCore.Icons.warningMessage?[IconSize.Small], Styles.migrationIcon);
                GUILayout.Label($"{migration.plugin.manifest.name}, v.{migration.@from} to v.{migration.to}: ", Styles.migration);
                LudiqGUI.EndHorizontal();

                foreach (var requiredAction in migration.requiredActions)
                {
                    LudiqGUI.Space(5);
                    LudiqGUI.BeginHorizontal();
                    GUILayout.Box(GUIContent.none, Styles.requiredActionBullet);
                    GUILayout.Label(requiredAction, Styles.requiredAction);
                    LudiqGUI.EndHorizontal();
                }

                LudiqGUI.EndVertical();
                LudiqGUI.FlexibleSpace();
                LudiqGUI.EndHorizontal();

                LudiqGUI.Space(Styles.space);
            }

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            if (GUILayout.Button(completeLabel, Styles.completeButton))
            {
                Complete();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.Space(Styles.space);
            LudiqGUI.EndVertical();
            GUILayout.EndScrollView();
        }
Пример #12
0
 public void OnKeyGUI(Rect keyPosition)
 {
     LudiqGUI.Inspector(metadata["Key"], keyPosition, GUIContent.none);
 }
Пример #13
0
 private float GetValueHeight(float width)
 {
     return(LudiqGUI.GetInspectorHeight(this, metadata["Value"], width, GUIContent.none));
 }
Пример #14
0
 protected virtual void OnHeaderGUI()
 {
     LudiqGUI.WindowHeader(title, icon);
 }
Пример #15
0
        protected override void OnGUI()
        {
            base.OnGUI();

            // Reloaded from serialization
            if (treeView == null)
            {
                Close();
                GUIUtility.ExitGUI();
            }

            // Close on Escape
            if (e.type == EventType.KeyDown && e.modifiers == EventModifiers.None && e.keyCode == KeyCode.Escape)
            {
                Close();
                GUIUtility.ExitGUI();
            }

            var innerPosition = new Rect(0, 0, position.width, position.height);

            // Draw Background
            EditorGUI.DrawRect(innerPosition, ColorPalette.unityBackgroundMid);

            GUILayout.BeginVertical();

            // Draw Search
            GUILayout.BeginHorizontal(LudiqStyles.searchFieldBackground, GUILayout.Height(LudiqStyles.searchFieldOuterHeight), GUILayout.ExpandWidth(true));

            EditorGUI.BeginChangeCheck();

            GUI.SetNextControlName(searchFieldName);

            // Special keyboard controls  while search field is selected
            if (GUI.GetNameOfFocusedControl() == searchFieldName && e.type == EventType.KeyDown)
            {
                // Pass arrow events to tree view
                if (e.keyCode == KeyCode.DownArrow || e.keyCode == KeyCode.UpArrow || !treeView.hasSearch && (e.keyCode == KeyCode.LeftArrow || e.keyCode == KeyCode.RightArrow))
                {
                    var selection = treeView.GetSelection();
                    treeView.SetFocus();
                    treeView.SetSelection(selection);
                }
                // Confirm search with enter
                else if (e.keyCode == KeyCode.Return)
                {
                    if (treeView.SelectActive())
                    {
                        Close();
                        GUIUtility.ExitGUI();
                    }
                    else
                    {
                        e.Use();
                    }
                }
                // Close if pressing space again without search
                else if (e.keyCode == KeyCode.Space && !treeView.hasSearch)
                {
                    Close();
                    GUIUtility.ExitGUI();
                }
            }

            treeView.searchString = EditorGUILayout.TextField(treeView.searchString, LudiqStyles.searchField);

            // Focus on Search
            if (focusSearch && e.type == EventType.Repaint)
            {
                GUI.FocusControl(searchFieldName);
                focusSearch = false;
            }

            // Reload Tree View on Search
            if (EditorGUI.EndChangeCheck())
            {
                treeView.Reload();
            }

            // Search Cancel Button
            if (GUILayout.Button(GUIContent.none, treeView.hasSearch ? LudiqStyles.searchFieldCancelButton : LudiqStyles.searchFieldCancelButtonEmpty) && treeView.hasSearch)
            {
                treeView.searchString = string.Empty;
                treeView.Reload();
                GUIUtility.keyboardControl = 0;
            }

            GUILayout.EndHorizontal();

            // Horizontal Separator
            GUILayout.Box(GUIContent.none, LudiqStyles.horizontalSeparator);

            // Handle special keyboard strokes in tree view
            if (treeView.HasFocus() && e.type == EventType.KeyDown)
            {
                // Select current item
                if (e.keyCode == KeyCode.Space)
                {
                    if (treeView.SelectActive())
                    {
                        Close();
                        GUIUtility.ExitGUI();
                    }
                    else
                    {
                        e.Use();
                    }
                }
                // Move back up to search field
                else if (e.keyCode == KeyCode.UpArrow)
                {
                    if (treeView.GetSelection().FirstOrDefault() == treeView.GetRows().FirstOrDefault()?.id)
                    {
                        focusSearch = true;
                        e.Use();
                    }
                }
                // Delete character from search
                else if (e.keyCode == KeyCode.Backspace)
                {
                    treeView.searchString = treeView.searchString.Substring(0, Mathf.Max(0, treeView.searchString.Length - 1));

                    e.Use();
                }
                // Append characters to search
                else if (e.modifiers == EventModifiers.None && !char.IsWhiteSpace(e.character) && !char.IsControl(e.character))
                {
                    treeView.searchString += e.character;

                    e.Use();
                }
                // Focus search
                else if (e.keyCode == KeyCode.F && e.CtrlOrCmd())
                {
                    focusSearch = true;
                    e.Use();
                }
            }

            // Draw Tree View
            var treeViewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));

            treeView.OnGUI(treeViewPosition);

            // Draw Preview
            previewEditorTargets.Clear();
            previewEditorTargets.AddRange(treeView.GetActiveGameObjects());

            if ((previewEditor == null && previewEditorTargets.Count > 0) ||
                (previewEditor != null && !previewEditorTargets.SequenceEqual(previewEditor.targets)))
            {
                if (previewEditor != null)
                {
                    DestroyImmediate(previewEditor);
                    previewEditor = null;
                }

                previewEditor = UEditor.CreateEditor(previewEditorTargets.ToArray(), null);
            }

            if (previewEditor != null && (previewEditor.HasPreviewGUI() || previewEditorTargets.Any(PreviewUtility.HasPreview)))
            {
                GUILayout.Box(GUIContent.none, LudiqStyles.horizontalSeparator);
                var previewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(Styles.previewHeight), GUILayout.ExpandWidth(true));
                previewEditor.DrawPreview(previewPosition);
            }

            GUILayout.EndVertical();

            // Draw Border
            if (e.type == EventType.Repaint)
            {
                LudiqGUI.DrawEmptyRect(new Rect(Vector2.zero, position.size), ColorPalette.unityBackgroundVeryDark);
            }

            // Repaint on hover
            if (innerPosition.Contains(e.mousePosition))
            {
                Repaint();
            }
        }
 private float GetKeyHeight(Metadata keyMetadata, float keyWidth)
 {
     return(LudiqGUI.GetInspectorHeight(parentInspector, keyMetadata, keyWidth, GUIContent.none));
 }
 private float GetObjectFieldWidth()
 {
     return(LudiqGUI.GetFuzzyObjectFieldWidth(value, visualType));
 }
 private float GetValueHeight(Metadata valueMetadata, float valueWidth)
 {
     return(LudiqGUI.GetInspectorHeight(parentInspector, valueMetadata, valueWidth, GUIContent.none));
 }
        protected override void OnControlGUI(Rect position)
        {
            EditorGUI.BeginChangeCheck();

            var oldValue = (UnityObject)accessor.value;

            var fieldPosition = new Rect
                                (
                position.x,
                position.y,
                position.width,
                GetObjectFieldHeight(position.width)
                                );

            UnityObject newValue;

            if (fuzzy)
            {
                newValue = LudiqGUI.ObjectField
                           (
                    fieldPosition,
                    oldValue,
                    accessor.definedType,
                    scene,
                    allowAssetObjects,
                    typeLabel,
                    typeIcon,
                    Filter,
                    GetOptions,
                    visualType,
                    hidableFrame
                           );
            }
            else
            {
                newValue = EditorGUI.ObjectField
                           (
                    fieldPosition,
                    oldValue,
                    accessor.definedType,
                    scene != null
                           );
            }

            y += EditorGUIUtility.singleLineHeight;

            var isValid = Filter(newValue);

            if (!isValid)
            {
                y += EditorGUIUtility.standardVerticalSpacing;

                var message = InvalidValueMessage(newValue);

                var invalidValueMessagePosition = position.VerticalSection(ref y, LudiqGUIUtility.GetHelpBoxHeight(message, MessageType.Error, position.width));

                EditorGUI.HelpBox(invalidValueMessagePosition, message, MessageType.Error);

                if (newValue != null && GUI.Button(invalidValueMessagePosition, GUIContent.none, GUIStyle.none))
                {
                    EditorGUIUtility.PingObject(newValue);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (isValid)
                {
                    accessor.RecordUndo();
                    accessor.value = newValue;
                }
                else
                {
                    Debug.LogWarning(InvalidValueMessage(newValue));
                }
            }
        }
 private void OnKeyGUI(Metadata keyMetadata, Rect keyPosition)
 {
     LudiqGUI.Inspector(keyMetadata, keyPosition, GUIContent.none);
 }
Пример #21
0
 protected virtual float GetInspectorHeight(float width)
 {
     return(LudiqGUI.GetInspectorHeight(this, metadata, width, GUIContent.none));
 }
 private void OnValueGUI(Metadata valueMetadata, Rect valuePosition)
 {
     LudiqGUI.Inspector(valueMetadata, valuePosition, GUIContent.none);
 }
Пример #23
0
        private void OnGUI()
        {
            view?.Update();

            if (!cached)
            {
                if (!isInstance && !isDefinition)
                {
                    isInstance = true;
                }
                cached = true;
            }

            if (!locked && (!focused && FuzzyWindow.instance == null || !focused && focusedWindow != FuzzyWindow.instance))
            {
                Close();
            }

            HUMEditor.Draw(new Rect(new Vector2(0, 0), position.size)).Box(HUMEditorColor.DefaultEditorBackground, Color.black, BorderDrawPlacement.Inside, 1);

            HUMEditor.Horizontal(() =>
            {
                var instance = isInstance;
                isInstance   = EditorGUILayout.Toggle(isInstance, new GUIStyle(GUI.skin.button), GUILayout.Height(24));
                var lastRect = GUILayoutUtility.GetLastRect();
                GUI.Label(lastRect, new GUIContent("Instance"), new GUIStyle(GUI.skin.label)
                {
                    alignment = TextAnchor.MiddleCenter
                });
                if (isInstance != instance)
                {
                    isDefinition = false;
                }

                var definition = isDefinition;
                isDefinition   = EditorGUILayout.Toggle(isDefinition, new GUIStyle(GUI.skin.button), GUILayout.Height(24));
                lastRect       = GUILayoutUtility.GetLastRect();
                GUI.Label(lastRect, new GUIContent("Definition"), new GUIStyle(GUI.skin.label)
                {
                    alignment = TextAnchor.MiddleCenter
                });
                if (isDefinition != definition)
                {
                    isInstance = false;
                }

                locked   = EditorGUILayout.Toggle(locked, new GUIStyle(GUI.skin.button), GUILayout.Width(48), GUILayout.Height(24));
                lastRect = GUILayoutUtility.GetLastRect();
                GUI.Label(lastRect, new GUIContent("Locked"), new GUIStyle(GUI.skin.label)
                {
                    alignment = TextAnchor.MiddleCenter
                });
            });

            scrollPosition = HUMEditor.Draw().ScrollView(scrollPosition, () =>
            {
                if (isInstance)
                {
                    LudiqGUI.InspectorLayout(windowVariablesMetadata);
                }
                if (isDefinition)
                {
                    LudiqGUI.InspectorLayout(variablesMetadata);
                }
            });

            view?.ApplyModifiedProperties();

            if (locked)
            {
                Repaint();
            }
        }
Пример #24
0
        public void OnGUI(Rect position, GUIContent label, bool showLabels, ref float y)
        {
            if (parent.chooseType)
            {
                var x = position.x;
                var remainingWidth = position.width;

                if (showLabels)
                {
                    var typeLabel = label == GUIContent.none ? new GUIContent("Type") : new GUIContent(label.text + " Type");

                    var typeLabelPosition = new Rect
                                            (
                        x,
                        y,
                        SystemObjectInspector.Styles.labelWidth,
                        EditorGUIUtility.singleLineHeight
                                            );

                    GUI.Label(typeLabelPosition, typeLabel, Inspector.ProcessLabelStyle(parent.metadata, null));

                    x += typeLabelPosition.width;
                    remainingWidth -= typeLabelPosition.width;
                }

                var typePosition = new Rect
                                   (
                    x,
                    y,
                    remainingWidth,
                    EditorGUIUtility.singleLineHeight
                                   );

                EditorGUI.BeginChangeCheck();

                var newType = LudiqGUI.TypeField(typePosition, GUIContent.none, parent.type, GetTypeOptions, new GUIContent("(Null)"));

                if (EditorGUI.EndChangeCheck())
                {
                    parent.metadata.RecordUndo();
                    parent.type = newType;
                    parent.SetValue();
                    parent.SetHeightDirty();
                }

                y += typePosition.height;
            }

            if (parent.chooseType && parent.showValue)
            {
                y += SystemObjectInspector.Styles.spaceBetweenTypeAndValue;
            }

            if (parent.showValue)
            {
                Rect valuePosition;

                if (parent.chooseType)
                {
                    var x = position.x;
                    var remainingWidth = position.width;

                    if (showLabels)
                    {
                        var valueLabel = label == GUIContent.none ? new GUIContent("Value") : new GUIContent(label.text + " Value");

                        var valueLabelPosition = new Rect
                                                 (
                            x,
                            y,
                            SystemObjectInspector.Styles.labelWidth,
                            EditorGUIUtility.singleLineHeight
                                                 );

                        GUI.Label(valueLabelPosition, valueLabel, Inspector.ProcessLabelStyle(parent.metadata, null));

                        x += valueLabelPosition.width;
                        remainingWidth -= valueLabelPosition.width;
                    }

                    valuePosition = new Rect
                                    (
                        x,
                        y,
                        remainingWidth,
                        EditorGUIUtility.singleLineHeight
                                    );

                    LudiqGUI.Inspector(parent.metadata.Cast(parent.type), valuePosition, GUIContent.none);
                }
                else
                {
                    valuePosition = new Rect
                                    (
                        position.x,
                        y,
                        position.width,
                        LudiqGUI.GetInspectorHeight(parent, parent.metadata.Cast(parent.type), position.width, label)
                                    );

                    LudiqGUI.Inspector(parent.metadata.Cast(parent.type), valuePosition, label);
                }

                y += valuePosition.height;
            }
            else
            {
                parent.metadata.value = null;
            }
        }
        protected override void OnContentGUI()
        {
            GUILayout.BeginVertical(Styles.background, GUILayout.ExpandHeight(true));

            LudiqGUI.FlexibleSpace();

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            var text = "Choose the assemblies in which you want to look for units.\n"
                       + "By default, all project and Unity assemblies are included.\n"
                       + "Unless you use a third-party plugin distributed as a DLL, you shouldn't need to change this.";

            GUILayout.Label(text, LudiqStyles.centeredLabel, GUILayout.MaxWidth(370));
            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.Space(10);

            var height = LudiqGUI.GetInspectorHeight(null, assemblyOptionsMetadata, Styles.optionsWidth, GUIContent.none);

            LudiqGUI.BeginHorizontal();

            LudiqGUI.FlexibleSpace();

            EditorGUI.BeginChangeCheck();

            var position = GUILayoutUtility.GetRect(Styles.optionsWidth, height);

            LudiqGUI.Inspector(assemblyOptionsMetadata, position, GUIContent.none);

            if (EditorGUI.EndChangeCheck())
            {
                assemblyOptionsMetadata.Save();
                Codebase.UpdateSettings();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.Space(10);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            if (GUILayout.Button("Reset to Defaults", Styles.defaultsButton))
            {
                assemblyOptionsMetadata.Reset(true);
                assemblyOptionsMetadata.Save();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.FlexibleSpace();

            LudiqGUI.Space(10);

            LudiqGUI.BeginHorizontal();
            LudiqGUI.FlexibleSpace();

            if (GUILayout.Button(completeLabel, Styles.completeButton))
            {
                Complete();
            }

            LudiqGUI.FlexibleSpace();
            LudiqGUI.EndHorizontal();

            LudiqGUI.FlexibleSpace();

            LudiqGUI.EndVertical();
        }
 protected virtual float GetMemberHeight(Metadata member, float width)
 {
     return(LudiqGUI.GetInspectorHeight(this, member, width));
 }
Пример #27
0
 public void OnValueGUI(Rect valuePosition)
 {
     LudiqGUI.Inspector(valueMetadata, valuePosition, GUIContent.none);
 }
 protected virtual void OnMemberGUI(Metadata member, Rect memberPosition)
 {
     LudiqGUI.Inspector(member, memberPosition);
 }
 private void OnImplementationGUI(Rect implementationPosition)
 {
     LudiqGUI.Inspector(implementationMetadata, implementationPosition, GUIContent.none);
 }
Пример #30
0
        private void OnOptionsGUI(FuzzyOptionNode parent, float scrollViewHeight)
        {
            if (parent.isLoading || (tree.showBackgroundWorkerProgress && BackgroundWorker.hasProgress))
            {
                LudiqGUI.BeginVertical();
                LudiqGUI.FlexibleSpace();
                LudiqGUI.BeginHorizontal();
                LudiqGUI.FlexibleSpace();
                LudiqGUI.LoaderLayout();
                LudiqGUI.FlexibleSpace();
                LudiqGUI.EndHorizontal();

                LudiqGUI.Space(16);
                LudiqGUI.BeginHorizontal();
                LudiqGUI.Space(10);
                var progressBarPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(19), GUILayout.ExpandWidth(true));

                if (progressBarPosition.width > 0 && progress > 0)
                {
                    if (tree.showBackgroundWorkerProgress && BackgroundWorker.hasProgress)
                    {
                        EditorGUI.ProgressBar(progressBarPosition, BackgroundWorker.progressProportion, BackgroundWorker.progressLabel);
                    }
                    else if (showProgress)
                    {
                        EditorGUI.ProgressBar(progressBarPosition, progress, progressText);
                    }
                }

                LudiqGUI.Space(10);
                LudiqGUI.EndHorizontal();

                LudiqGUI.FlexibleSpace();
                LudiqGUI.EndVertical();

                return;
            }

            parent.scroll = GUILayout.BeginScrollView(parent.scroll);

            EditorGUIUtility.SetIconSize(new Vector2(IconSize.Small, IconSize.Small));

            var selectedOptionPosition = default(Rect);

            if (e.type == EventType.Repaint)
            {
                minOptionWidth = 0;
            }

            foreach (var node in parent.children)
            {
                node.EnsureDrawable();

                minOptionWidth = Mathf.Max(minOptionWidth, Mathf.Min(node.width, Styles.maxOptionWidth));
            }

            for (var i = 0; i < parent.children.Count; i++)
            {
                var node = parent.children[i];

                var optionPosition = GUILayoutUtility.GetRect(IconSize.Small, Styles.optionHeight, GUILayout.ExpandWidth(true));

                if (!isAnimating)
                {
                    if (((e.type == EventType.MouseMove && GUIUtility.GUIToScreenPoint(e.mousePosition) != lastMouseMovePosition) || e.type == EventType.MouseDown) &&
                        parent.selectedIndex != i && optionPosition.Contains(e.mousePosition))
                    {
                        parent.selectedIndex = i;

                        requireRepaint = true;

                        lastMouseMovePosition = GUIUtility.GUIToScreenPoint(e.mousePosition);

                        GUIUtility.ExitGUI();
                    }
                }

                var optionIsSelected = false;

                if (i == parent.selectedIndex)
                {
                    optionIsSelected       = true;
                    selectedOptionPosition = optionPosition;
                }

                // Clipping
                if (optionPosition.yMax < parent.scroll.y || optionPosition.yMin > parent.scroll.y + scrollViewHeight)
                {
                    continue;
                }

                if (e.type == EventType.Repaint)
                {
                    node.style.Draw(optionPosition, node.label, false, false, optionIsSelected, optionIsSelected);
                }

                var right = optionPosition.xMax;

                if (node.hasChildren)
                {
                    right -= 13;
                    var rightArrowPosition = new Rect(right, optionPosition.y + 4, 13, 13);

                    if (e.type == EventType.Repaint)
                    {
                        Styles.rightArrow.Draw(rightArrowPosition, false, false, false, false);
                    }
                }

                if (!node.hasChildren && tree.selected.Contains(node.option.value))
                {
                    right -= 16;
                    var checkPosition = new Rect(right, optionPosition.y + 4, 12, 12);

                    if (e.type == EventType.Repaint)
                    {
                        Styles.check.Draw(checkPosition, false, false, false, false);
                    }
                }

                if (tree.favorites != null && tree.CanFavorite(node.option.value) && (optionIsSelected || tree.favorites.Contains(node.option.value)))
                {
                    right -= 19;
                    var starPosition = new Rect(right, optionPosition.y + 2, IconSize.Small, IconSize.Small);

                    EditorGUI.BeginChangeCheck();

                    var isFavorite = tree.favorites.Contains(node.option.value);

                    isFavorite = GUI.Toggle(starPosition, isFavorite, GUIContent.none, Styles.star);

                    if (EditorGUI.EndChangeCheck())
                    {
                        if (isFavorite)
                        {
                            tree.favorites.Add(node.option.value);
                        }
                        else
                        {
                            tree.favorites.Remove(node.option.value);
                        }

                        tree.OnFavoritesChange();

                        UpdateFavorites();
                    }
                }

                if (!isAnimating)
                {
                    if (e.type == EventType.MouseDown && e.button == (int)MouseButton.Left && optionPosition.Contains(e.mousePosition))
                    {
                        e.Use();
                        parent.selectedIndex = i;
                        SelectChild(node);

                        GUIUtility.ExitGUI();
                    }
                }
            }

            EditorGUIUtility.SetIconSize(default(Vector2));

            GUILayout.EndScrollView();

            if (scrollToSelected && e.type == EventType.Repaint)
            {
                scrollToSelected = false;

                var lastRect = GUILayoutUtility.GetLastRect();


                if (selectedOptionPosition.yMax - lastRect.height > parent.scroll.y)
                {
                    var scroll = parent.scroll;
                    scroll.y      = selectedOptionPosition.yMax - lastRect.height;
                    parent.scroll = scroll;

                    requireRepaint = true;
                }

                if (selectedOptionPosition.y < parent.scroll.y)
                {
                    var scroll = parent.scroll;
                    scroll.y      = selectedOptionPosition.y;
                    parent.scroll = scroll;

                    requireRepaint = true;
                }
            }
        }