DrawPreview() публичный Метод

The first entry point for Preview Drawing.

public DrawPreview ( Rect previewArea ) : void
previewArea UnityEngine.Rect
Результат void
        public override void OnFooterGUI(FuzzyOptionNode node, Rect position)
        {
            if (editorTarget != prefab)
            {
                editorTarget = prefab;
                UEditor.CreateCachedEditor(editorTarget, null, ref editor);
            }

            if (editor != null)
            {
                editor.DrawPreview(position);
            }
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            serializedObject.DrawScript();

            m_sourceMeshPreview.DrawPreview(GUILayoutUtility.GetRect(200, 200));

            GUI.enabled = false;

            if (m_asset.IsTessellated)
            {
                EditorGUILayout.PropertyField(m_properties.TessellationLevel, Labels.TessellationLevel);
            }

            EditorGUILayout.Toggle(Labels.HasUVs, m_asset.HasUVs);
            EditorGUILayout.PropertyField(m_properties.Size, Labels.Size);
            EditorGUILayout.PropertyField(m_properties.Padding, Labels.Padding);
            EditorGUILayout.PropertyField(m_properties.MinBounds, Labels.MinBounds);
            EditorGUILayout.PropertyField(m_properties.MaxBounds, Labels.MaxBounds);

            GUI.enabled = true;
        }
Пример #3
0
        public void Fill(List <Object> objects, FillMode fillMode = FillMode.Default)
        {
            objects = new List <Object>(objects);

            if (fillMode == FillMode.Add)
            {
                components.RemoveAll(item => item == null);
                foreach (var component in components)
                {
                    if (!objects.Contains(component))
                    {
                        objects.Add(component);
                    }
                }
            }

            Dispose();
            components = objects;
            folouts.Clear();

            foreach (var component in components)
            {
                Foldout folout = new Foldout(string.Format("{0}", component.GetType().Name));
                folout.Value = components.Count == 1 ? true : false;
                folout.name  = folout.Title;
                folouts.Add(folout);

                folout.imageElement.image = EditorGUIUtility.ObjectContent(component, component.GetType()).image;
                folout.headerElement.RegisterCallback <MouseUpEvent>((evt) =>
                {
                    if (evt.button == 1)
                    {
                        Rect rect     = new Rect(folout.headerElement.layout);
                        rect.position = evt.mousePosition;
                        HierarchyEditor.DisplayObjectContextMenu(rect, component, 0);
                        evt.StopPropagation();
                    }
                });


                Label objectName = new Label(string.Format(" [{0}]", component.name));
                objectName.StyleTextColor(objectNameColor);
                objectName.RegisterCallback <MouseUpEvent>((evt) =>
                {
                    if (evt.button == 0)
                    {
                        EditorGUIUtility.PingObject(component);
                        Selection.activeObject = component;
                        evt.StopPropagation();
                    }
                });
                folout.headerElement.Add(objectName);

                Image remove = new Image();
                remove.image = EditorGUIUtility.IconContent("winbtn_win_close").image;
                remove.StyleSize(13, 13);
                remove.StylePosition(Position.Absolute);
                remove.StyleRight(8);
                remove.StyleAlignSelf(Align.Center);
                remove.RegisterCallback <MouseUpEvent>((evt) =>
                {
                    if (evt.button == 0)
                    {
                        if (component != null)
                        {
                            components.Remove(component);
                        }
                        else
                        {
                            components.RemoveAll(item => item == null);
                        }

                        Fill(new List <Object>(components));
                        evt.StopPropagation();
                    }
                });
                folout.headerElement.Add(remove);

                bool isMat = component is Material;

                UnityEditor.Editor editor = null;

                if (isMat)
                {
                    editor = MaterialEditor.CreateEditor(component) as MaterialEditor;
                }
                else
                {
                    editor = UnityEditor.Editor.CreateEditor(component);
                }

                VisualElement inspector = editor.CreateInspectorGUI();

                if (inspector == null)
                {
                    inspector = new IMGUIContainer(() =>
                    {
                        bool tempState  = EditorGUIUtility.wideMode;
                        float tempWidth = EditorGUIUtility.labelWidth;

                        EditorGUIUtility.wideMode = true;

                        if (component is Transform)
                        {
                            EditorGUIUtility.labelWidth = 64;
                        }

                        if (editor.target != null)
                        {
                            if (isMat)
                            {
                                MaterialEditor maEditor = editor as MaterialEditor;

                                EditorGUILayout.BeginVertical();
                                if (maEditor.PropertiesGUI())
                                {
                                    maEditor.PropertiesChanged();
                                }
                                EditorGUILayout.EndVertical();
                            }
                            else
                            {
                                editor.OnInspectorGUI();
                            }

                            objectName.StyleTextColor(objectNameColor);
                        }
                        else
                        {
                            objectName.StyleTextColor(Color.red);
                            EditorGUILayout.HelpBox("Reference not found.", MessageType.Info);
                        }

                        EditorGUIUtility.wideMode   = tempState;
                        EditorGUIUtility.labelWidth = tempWidth;
                    });
                }

                inspector.style.marginLeft  = 16;
                inspector.style.marginRight = 2;
                inspector.style.marginTop   = 4;

                folout.Add(inspector);
                editors.Add(editor);
                scrollView.Add(folout);

                if (isMat)
                {
                    var preview = new IMGUIContainer(() =>
                    {
                        editor.DrawPreview(new Rect(0, 0, inspector.layout.size.x,
                                                    Mathf.Clamp(inspector.layout.width / 2, 64, 200)));
                    });
                    preview.StyleMarginTop(4);
                    preview.StretchToParentWidth();
                    inspector.RegisterCallback <GeometryChangedEvent>((callback) =>
                    {
                        preview.StyleHeight(Mathf.Clamp(inspector.layout.width / 2, 64, 200));
                    });
                    preview.StylePosition(Position.Relative);
                    preview.name = "Material Preview";
                    folout.Add(preview);
                }
            }

            Repaint();
        }