예제 #1
0
        public int Compare(InspectorItemRenderer a, InspectorItemRenderer b)
        {
            int aIndex = orderedGroupList.GetGroupIndex(a.inspectorAttribute.group);
            int bIndex = orderedGroupList.GetGroupIndex(b.inspectorAttribute.group);

            int result = 1;

            if (aIndex < bIndex)
            {
                result = -1;
            }
            if (aIndex == bIndex)
            {
                if (a.inspectorAttribute.order < b.inspectorAttribute.order)
                {
                    result = -1;
                }
                else if (a.inspectorAttribute.order == b.inspectorAttribute.order && Array.IndexOf(rendererArray, a) < Array.IndexOf(rendererArray, b))
                {
                    result = -1;
                }
            }

            return(result);
        }
예제 #2
0
        public override void Render(Action preRender = null)
        {
            base.Render(preRender);

            EditorGUILayout.BeginVertical();

            Group nextGroup    = groups[0];
            Group currentGroup = null;

            foreach (FullObjectDecoratedRenderer decoratedRenderer in decoratedRenderers)
            {
                if (nextGroup != null)
                {
                    if (decoratedRenderer.groupName == nextGroup.name)
                    {
                        currentGroup = nextGroup;

                        if (nextGroup.hidden == false)
                        {
                            DrawGroupHeader(nextGroup);
                        }

                        int currentGroupIndex = groups.GetGroupIndex(currentGroup.name);
                        nextGroup = groups[currentGroupIndex + 1];
                    }
                }

                if (currentGroup == null || !currentGroup.hidden)
                {
                    if (currentGroup == null || GroupIsFoldout(currentGroup) || !currentGroup.foldable)
                    {
                        if (currentGroup != null && currentGroup.foldable)
                        {
                            EditorGUI.indentLevel += 1 * Settings.indentation;
                        }

                        SetBeginLayout(decoratedRenderer);

                        decoratedRenderer.Render(currentLayoutIsHorizontal);

                        SetEndLayout(decoratedRenderer);

                        if (currentGroup != null && currentGroup.foldable)
                        {
                            EditorGUI.indentLevel -= 1 * Settings.indentation;
                        }
                    }
                }
            }

            EditorGUILayout.EndVertical();
        }
예제 #3
0
        public override void Render(Action preRender = null)
        {
            base.Render(preRender);

            if (groups == null)
            {
                RetrieveGroupList();

                if (groups == null)
                {
                    Debug.LogError("You should ensure your implementation of FullObjectRenderer set Groups groups in InitializeGroups() before to call Render on FullObjectRenderer. If there is not groups to set," +
                                   " initialize it with new Groups(string[]{''})");
                }
            }

            if (renderers == null)
            {
                InitializeRenderersList();
            }

            if (!groupInitialized)
            {
                InitializeGroups();
            }

            SetVisibility();

            EditorGUILayout.BeginVertical();

            Group nextGroup = groups[0];

            foreach (InspectorItemRenderer renderer in renderers)
            {
                if (nextGroup != null)
                {
                    if (renderer.inspectorAttribute.group == nextGroup.name)
                    {
                        if (nextGroup.hidden == false)
                        {
                            DrawGroupHeader(nextGroup);
                        }

                        int currentGroupIndex = groups.GetGroupIndex(nextGroup.name);
                        nextGroup = groups[currentGroupIndex + 1];
                    }
                }

                if (GroupDoesNotExist(renderer.inspectorAttribute.group, groups) || GroupExistsAndNotHidden(renderer.inspectorAttribute.group, groups))
                {
                    SetBeginLayout(renderer);

                    if (renderer.hidden == false)
                    {
                        renderer.serializedObject = serializedObject;

                        EditorGUILayout.BeginVertical();

                        Action preRenderOperations  = null;
                        Action postRenderOperations = null;


                        Action optimizeLabelWidth       = null;
                        Action cancelOptimizeLabelWidth = null;
                        float  oldLabelWidth            = EditorGUIUtility.labelWidth;

                        if (currentLayoutIsHorizontal)
                        {
                            if (!string.IsNullOrEmpty(renderer.GetLabel()))
                            {
                                optimizeLabelWidth = () =>
                                {
                                    var textDimensions = GUI.skin.label.CalcSize(new GUIContent(renderer.GetLabel()));
                                    EditorGUIUtility.labelWidth = textDimensions.x + 20f;
                                };

                                cancelOptimizeLabelWidth = () =>
                                {
                                    EditorGUIUtility.labelWidth = oldLabelWidth;
                                };
                            }
                        }

                        Action          drawMessage     = null;
                        MessageRenderer messageRenderer = GetMessageRenderer(renderer);
                        if (messageRenderer != null)
                        {
                            drawMessage += messageRenderer.Render;
                        }

                        preRenderOperations  += optimizeLabelWidth;
                        postRenderOperations += cancelOptimizeLabelWidth + drawMessage;

                        renderer.Render(preRenderOperations);
                        renderer.PostRender(postRenderOperations);


                        EditorGUILayout.EndVertical();
                    }

                    SetEndLayout(renderer);
                }

                GUILayout.Space(1f);
            }

            EditorGUILayout.EndVertical();
        }