Esempio n. 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var offset = new Vector2(position.x, position.y);

            //GUI.BeginGroup(position);
            {
                var width  = 30f;
                var margin = 5f;

                //property.serializedObject.Update();

                EditorGUI.PropertyField(new Rect(offset.x, offset.y, position.width - width - margin, position.height), property, label, true);
                GUILayoutExt.DrawComponentChooser(new Rect(position.width - width + offset.x, offset.y, width, position.height), (property.serializedObject.targetObject as WindowComponent).gameObject, property.objectReferenceValue as WindowComponent, (component) => {
                    property.objectReferenceValue = component;
                    property.serializedObject.ApplyModifiedProperties();
                });

                //property.serializedObject.ApplyModifiedProperties();
            }
            //GUI.EndGroup();
        }
Esempio n. 2
0
        public static SerializedProperty OnItemDraw(LayoutWindowType window, List <SerializedProperty> items, List <UnityEngine.UI.Windows.Types.Layout.Component> components, bool draw, bool withParameters, Rect rect, SerializedProperty item, out float elementHeight)
        {
            if (LayoutSettingsEditor.componentParametersSearched == null ||
                LayoutSettingsEditor.componentParametersSearched.Count != components.Count)
            {
                LayoutSettingsEditor.componentParametersSearched = new List <bool>();
                for (int i = 0; i < components.Count; ++i)
                {
                    LayoutSettingsEditor.componentParametersSearched.Add(false);
                }
            }

            var startY       = rect.y + 2f;
            var offset       = 2f;
            var heightOffset = 20f;

            elementHeight = 0f;
            rect.y        = startY;

            var index = items.IndexOf(item);

            if (index < 0 || index >= items.Count)
            {
                return(item);
            }
            if (item == null)
            {
                return(null);
            }

            var descr        = item.FindPropertyRelative("description");
            var tag          = item.FindPropertyRelative("tag");
            var component    = item.FindPropertyRelative("component");
            var sortingOrder = item.FindPropertyRelative("sortingOrder");

            if (descr == null ||
                tag == null ||
                component == null ||
                sortingOrder == null)
            {
                return(item);
            }

            var parameters = item.FindPropertyRelative("componentParameters");
            var componentParametersEditor = components[index].componentParametersEditor;

            if (rect.Contains(Event.current.mousePosition) == true)
            {
                //WindowLayoutElement.waitForComponentConnectionElementTemp = window.GetCurrentLayout().layout.GetRootByTag((LayoutTag)tag.enumValueIndex);
                LayoutSettingsEditor.selectedTagIndex = tag.enumValueIndex;
            }

            if (LayoutSettingsEditor.selectedTagIndex == tag.enumValueIndex)
            {
                var _offset = 4f;
                var newRect = new Rect(rect.x - _offset, rect.y - _offset, rect.width + _offset * 2f, rect.height + _offset);

                LayoutSettingsEditor.selectedTagRect = newRect;

                var oldColor = GUI.color;
                GUI.color = new Color(0f, 1f, 0f, 0.2f);
                GUI.Box(newRect, string.Empty, EditorStyles.textArea);
                GUI.Box(newRect, string.Empty, EditorStyles.popup);
                GUI.color = oldColor;
            }

            /*if (active == true && focused == true) {
             *
             *      //var window = (property.serializedObject.targetObject as LayoutWindowType);
             *      WindowLayoutElement.waitForComponentConnectionElementTemp = window.layout.layout.GetRootByTag((LayoutTag)tag.enumValueIndex);
             *      WindowLayoutElement.waitForComponentConnectionTemp = true;
             *
             * } else {
             *
             *      if (active == true) {
             *
             *              WindowLayoutElement.waitForComponentConnectionElementTemp = null;
             *              WindowLayoutElement.waitForComponentConnectionTemp = false;
             *
             *      }
             *
             * }*/

            var title  = "Description";
            var height = EditorGUI.GetPropertyHeight(descr, new GUIContent(title)) + offset;

            rect.height = height - offset;
            if (draw == true)
            {
                EditorGUI.LabelField(rect, descr.stringValue, EditorStyles.boldLabel);
                EditorGUI.LabelField(rect, tag.enumNames[tag.enumValueIndex], ME.Utilities.CacheStyle("WindowLayoutProperty.Styles.tag", "tag", (name) => {
                    var style       = new GUIStyle(EditorStyles.boldLabel);
                    style.alignment = TextAnchor.MiddleRight;
                    return(style);
                }));
            }

            title       = "Component";
            rect.y     += height;
            height      = EditorGUI.GetPropertyHeight(component, new GUIContent(title)) + offset;
            rect.height = height - offset;

            {
                var oldComponent = component.objectReferenceValue;

                var nRect       = rect;
                var buttonWidth = 30f;
                nRect.width -= buttonWidth;
                if (draw == true)
                {
                    EditorGUI.PropertyField(nRect, component, new GUIContent(title), true);
                }

                //Debug.Log(oldComponent + " == " + component.objectReferenceValue + " :: " + (oldComponent == component.objectReferenceValue));
                var newComponent = component.objectReferenceValue;
                if (oldComponent != newComponent)
                {
                    //Debug.Log("NEW COMP: " + newComponent);
                    parameters.objectReferenceValue = components[index].OnComponentChanged(window, newComponent as WindowComponent);
                    //Debug.Log("NEW COMP: " + parameters.objectReferenceValue);
                    components[index].componentParametersEditor = null;
                    item.serializedObject.ApplyModifiedPropertiesWithoutUndo();

                    UnityEditor.EditorUtility.SetDirty(window);
                }

                if (newComponent == null && components[index].componentResource.id != 0)
                {
                    components[index].OnComponentChanged(window, null);
                    components[index].componentParametersEditor = null;
                    item.serializedObject.ApplyModifiedPropertiesWithoutUndo();

                    UnityEditor.EditorUtility.SetDirty(window);
                }

                nRect.x    += nRect.width;
                nRect.width = buttonWidth;
                if (draw == true)
                {
                    var i = index;
                    GUILayoutExt.DrawComponentChooser(nRect, window.gameObject, components[i].component, (elem) => {
                        if (component.objectReferenceValue != elem)
                        {
                            component.objectReferenceValue = elem;
                            var c = component.objectReferenceValue;
                            parameters.objectReferenceValue         = components[i].OnComponentChanged(window, c as WindowComponent);
                            components[i].componentParametersEditor = null;
                            item.serializedObject.ApplyModifiedPropertiesWithoutUndo();

                            UnityEditor.EditorUtility.SetDirty(window);
                        }
                    });
                }
            }

            title       = "Sorting Order";
            rect.y     += height;
            height      = EditorGUI.GetPropertyHeight(sortingOrder, new GUIContent(title)) + offset;
            rect.height = height - offset;
            if (draw == true)
            {
                var oldValue = sortingOrder.intValue;
                EditorGUI.PropertyField(rect, sortingOrder, new GUIContent(title), true);
                if (sortingOrder.intValue < 0)
                {
                    sortingOrder.intValue = 0;
                }
                if (oldValue != sortingOrder.intValue)
                {
                    item.serializedObject.ApplyModifiedPropertiesWithoutUndo();
                    UnityEditor.EditorUtility.SetDirty(window);
                }
            }

            if (parameters.objectReferenceValue == null && LayoutSettingsEditor.componentParametersSearched[index] == false)
            {
                components[index].OnComponentChanged(window, components[index].component);
                LayoutSettingsEditor.componentParametersSearched[index] = true;

                UnityEditor.EditorUtility.SetDirty(window);
            }

            if (withParameters == true)
            {
                var editor = componentParametersEditor;
                if (editor == null && parameters.objectReferenceValue != null)
                {
                    var e = Editor.CreateEditor(parameters.objectReferenceValue) as IParametersEditor;
                    components[index].componentParametersEditor = componentParametersEditor = e;
                }

                if (editor != null)
                {
                    title   = "Parameters";
                    rect.y += height;
                    var _height = height = 16f;
                    rect.height = height - offset;
                    var editorFoldout = item.FindPropertyRelative("editorParametersFoldout");
                    if (draw == true)
                    {
                        ++EditorGUI.indentLevel;
                        var newValue = EditorGUI.Foldout(rect, editorFoldout.boolValue, new GUIContent(title));
                        if (newValue != editorFoldout.boolValue)
                        {
                            editorFoldout.boolValue = newValue;
                            editorFoldout.serializedObject.ApplyModifiedProperties();
                        }
                        --EditorGUI.indentLevel;
                    }

                    if (editorFoldout.boolValue == true)
                    {
                        rect.y += height;
                        height  = 0f;

                        if (draw == true)
                        {
                            ++EditorGUI.indentLevel;
                            editor.OnParametersGUI(rect);
                            --EditorGUI.indentLevel;

                            //parameters.objectReferenceValue = editor.target;
                            //editor.serializedObject.ApplyModifiedPropertiesWithoutUndo();
                        }

                        height      = editor.GetHeight() + offset;
                        rect.y     += height - _height;
                        rect.height = height - offset;
                    }
                }
            }

            elementHeight = (rect.y - startY) + heightOffset;

            return(item);
        }
Esempio n. 3
0
        public override void OnGUI()
        {
            if (Layout.styles == null)
            {
                Layout.styles = new Styles();
            }

            if (this.opened == true)
            {
                const float settingsWidth = 320f;
                const float listHeight    = 200f;
                const float padding       = 5f;
                const float closeSize     = 30f;
                const float scrollWidth   = 16f;

                var rect            = new Rect(0f, -OFFSET, Screen.width, Screen.height - OFFSET).PixelPerfect();
                var rectContent     = new Rect(rect.x + MARGIN + settingsWidth + padding, rect.y + MARGIN, rect.width - MARGIN * 2f - padding - settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT).PixelPerfect();
                var rectList        = new Rect(MARGIN, rect.y + MARGIN, settingsWidth, listHeight - padding).PixelPerfect();
                var rectSettings    = new Rect(MARGIN, rect.y + MARGIN + listHeight, settingsWidth, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT - listHeight).PixelPerfect();
                var rectCloseButton = new Rect(rectContent.x + rectContent.width, rectContent.y - closeSize * 0.5f, closeSize, closeSize).PixelPerfect();

                GUI.Box(new Rect(rect.x + MARGIN, rect.y + MARGIN, rect.width - MARGIN * 2f, rect.height - MARGIN * 2f - FlowSystemEditorWindow.TOOLBAR_HEIGHT).PixelPerfect(), string.Empty, Layout.styles.layoutBack);
                GUI.Box(rect, string.Empty, Layout.styles.backLock);
                GUI.Box(new Rect(0f, 0f, Screen.width, Screen.height).PixelPerfect(), string.Empty, Layout.styles.dropShadow);
                GUI.Box(rectList, string.Empty, Layout.styles.content);
                GUI.Box(rectSettings, string.Empty, Layout.styles.content);
                GUI.Box(rectContent, string.Empty, Layout.styles.contentScreen);

                GUI.BeginGroup(rectSettings);
                {
                    if (this.component != null)
                    {
                        const float offsetTop = 50f;

                        var viewRect   = new Rect(0f, 0f, rectSettings.width, 0f).PixelPerfect();
                        var scrollView = new Rect(0f, 0f + offsetTop, rectSettings.width, rectSettings.height - offsetTop).PixelPerfect();

                        System.Action <WindowComponent> onChange = (WindowComponent component) => {
                            //Debug.Log(component + "!=" + this.component.component);
                            if (component != this.component.component)
                            {
                                this.component.componentParametersEditor = null;
                                this.component.componentParameters       = this.component.OnComponentChanged(this.screen, component);

                                if (this.component.componentParameters != null)
                                {
                                    var e = Editor.CreateEditor(this.component.componentParameters) as IParametersEditor;
                                    this.component.componentParametersEditor = e;
                                }

                                UnityEditor.EditorUtility.SetDirty(this.screen);
                            }
                        };

                        var c = EditorGUI.ObjectField(new Rect(5f, 5f, viewRect.width - 40f - 5f * 2f, 16f).PixelPerfect(), this.component.component, typeof(WindowComponent), allowSceneObjects: false) as WindowComponent;
                        if (c != this.component.component)
                        {
                            onChange(c);
                        }

                        var nRect = new Rect(viewRect.width - 40f, 5f, 40f - 5f, 16f).PixelPerfect();
                        GUILayoutExt.DrawComponentChooser(nRect, this.screen.gameObject, this.component.component, (component) => {
                            onChange(component);
                        });

                        if (this.component.component != null)
                        {
                            var editor = this.component.componentParametersEditor;

                            nRect.x     = 5f;
                            nRect.width = viewRect.width - 5f * 2f;
                            nRect.y    += nRect.height + 5f;
                            this.component.sortingOrder = EditorGUI.IntField(nRect, new GUIContent("Sorting Order"), this.component.sortingOrder);

                            if (editor != null)
                            {
                                var h = Mathf.Max(scrollView.height, (editor == null) ? 0f : editor.GetHeight());
                                viewRect = new Rect(scrollView.x, scrollView.y, viewRect.width - scrollWidth, h).PixelPerfect();

                                var oldSkin = GUI.skin;
                                GUI.skin = FlowSystemEditorWindow.defaultSkin;
                                this.settingsScrollPosition = GUI.BeginScrollView(scrollView, this.settingsScrollPosition, viewRect, false, true);
                                GUI.skin = oldSkin;
                                {
                                    if (editor != null)
                                    {
                                        EditorGUIUtility.labelWidth = 100f;
                                        //++EditorGUI.indentLevel;
                                        editor.OnParametersGUI(viewRect);
                                        //--EditorGUI.indentLevel;
                                        EditorGUIUtilityExt.LookLikeControls();
                                    }
                                }
                                GUI.EndScrollView();
                            }
                            else
                            {
                                GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height).PixelPerfect(), "Selected component have no parameters", EditorStyles.centeredGreyMiniLabel);
                            }
                        }
                    }
                    else
                    {
                        GUI.Label(new Rect(0f, 0f, rectSettings.width - scrollWidth, rectSettings.height).PixelPerfect(), "Select an Element", EditorStyles.centeredGreyMiniLabel);
                    }
                }
                GUI.EndGroup();

                GUI.BeginGroup(rectList);
                {
                    const float itemHeight = 30f;

                    this.highlighted.Clear();

                    var viewRect = new Rect(0f, 0f, rectList.width - scrollWidth, 0f).PixelPerfect();
                    this.allListHeight = 0f;
                    for (int i = 0; i < this.props.Count; ++i)
                    {
                        var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag);
                        if (root.showInComponentsList == false)
                        {
                            continue;
                        }

                        if (this.screen.layout.components[i].component == null)
                        {
                            this.highlighted.Add(root);
                        }

                        this.allListHeight += itemHeight;
                    }

                    viewRect.height = Mathf.Max(rectList.height, this.allListHeight);

                    var oldSkin = GUI.skin;
                    GUI.skin = FlowSystemEditorWindow.defaultSkin;
                    this.listScrollPosition = GUI.BeginScrollView(new Rect(0f, 0f, rectList.width, rectList.height).PixelPerfect(), this.listScrollPosition, viewRect, false, true);
                    GUI.skin = oldSkin;
                    {
                        GUI.BeginGroup(viewRect);
                        {
                            var h = 0f;
                            this.hovered = null;
                            for (int i = 0; i < this.props.Count; ++i)
                            {
                                var root = this.screen.layout.layout.GetRootByTag(this.screen.layout.components[i].tag);
                                if (root.showInComponentsList == false)
                                {
                                    continue;
                                }

                                var r = new Rect(0f, h, viewRect.width, itemHeight).PixelPerfect();
                                h += r.height;

                                var isSelected = (this.element == root);
                                if (isSelected == true)
                                {
                                    GUI.Label(r, this.screen.layout.components[i].description, Layout.styles.listButtonSelected);
                                }
                                else
                                {
                                    //r.width -= scrollWidth;
                                    if (GUI.Button(r, this.screen.layout.components[i].description, Layout.styles.listButton) == true)
                                    {
                                        this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == root.tag);
                                        this.element   = root;
                                    }

                                    var inRect = rectList.Contains(Event.current.mousePosition - this.listScrollPosition + Vector2.up * 40f);
                                    if (GUI.enabled == true)
                                    {
                                        EditorGUIUtility.AddCursorRect(r, MouseCursor.Link);
                                    }
                                    if (r.Contains(Event.current.mousePosition) == true && inRect == true)
                                    {
                                        this.hovered = this.screen.layout.components[i];
                                    }
                                    //r.width += scrollWidth;
                                }

                                //r.width -= scrollWidth;
                                GUI.Label(r, this.screen.layout.components[i].tag.ToString(), Layout.styles.listTag);
                            }
                        }
                        GUI.EndGroup();
                    }
                    GUI.EndScrollView();
                }
                GUI.EndGroup();

                var selected = (this.hovered != null) ? this.screen.layout.layout.GetRootByTag(this.hovered.tag) : this.element;
                this.editor.OnPreviewGUI(Color.white, rectContent, Layout.styles.content, selected: selected, onSelection: (element) => {
                    this.component = this.screen.layout.components.FirstOrDefault(c => c.tag == element.tag);
                    this.element   = element;
                }, highlighted: this.highlighted);

                if (GUI.Button(rectCloseButton, string.Empty, Layout.styles.closeButton) == true)
                {
                    this.flowEditor.SetEnabled();
                    this.opened = false;
                }
            }
        }