public void Entity_WithNoComponents_HasEmptyInspector()
        {
            Assert.That(m_Editor, Is.TypeOf <EntityEditor>());
            var root = m_Editor.CreateInspectorGUI();
            var list = root.Query <ComponentElementBase>().ToList();

            Assert.That(list.Count, Is.EqualTo(0));
        }
Beispiel #2
0
        private void SetupPoser(VisualElement root, HVRHandPoser poser)
        {
            CleanupPoserEditor();

            _poserEditor = UnityEditor.Editor.CreateEditor(poser);
            _poserRoot   = _poserEditor.CreateInspectorGUI();
            root.Add(_poserRoot);
            _poserRoot.Unbind();
            _poserRoot.Bind(_poserEditor.serializedObject);
        }
Beispiel #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();
        }