Ejemplo n.º 1
0
        void SetVisual()
        {
            VisualElement root = rootVisualElement;

            root.Clear();

            //var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/UIElementsEditor/Styles/Editor/EditorEditorWindow.uxml");
            var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(string.Format(basePath, "Styles/Editor/EditorEditorWindow.uxml"));
            //var visualTree = LoadFromRelativePath<VisualTreeAsset>("EditorEditorWindow.uxml");
            VisualElement content = visualTree.CloneTree();

            root.Add(content);

            var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>(string.Format(basePath, "Styles/Editor/EditorEditorWindow.uss"));

            root.styleSheets.Add(styleSheet);

            //Tree View
            treeViewContainer = root.Q <Box>("treeViewContainer");

            treeViewMap = new Dictionary <VisualElement, TreeViewItem>();

            previewRoot = root.Q <VisualElement>("PreviewRoot");

            rootItem        = CreateTreeViewItem(previewRoot);
            rootItem.IsRoot = true;

            rootItem.AppendTo(treeViewContainer);

            //Inspector
            inspector = new ElementInspector(root.Q <VisualElement>("inspectorRoot"));
            inspector.onChangeProperty += OnChangeInspector;

            //Toolbar
            toolbarRoot = root.Q <VisualElement>("toolbarRoot");
            CreateToolbar();

            //Drag Label
            dragHandler = new Label();
            dragHandler.AddToClassList("eeditor-dragLabel");
            dragHandler.focusable     = false;
            dragHandler.style.display = DisplayStyle.None;

            root.Add(dragHandler);

            ///////
            var button = new Button(() => {
                SetVisual();
            });

            button.text = "Reload";
            root.Add(button);
        }
        static VisualElement CreateField <T>(string label, T value, EventCallback <ChangeEvent <T> > evt)
        {
            VisualElement fieldElement;


            var lblText = label.Length > 16 ? label.Substring(0, 13) + "..." : label;


            var field = ElementInspector.GetField <T>(lblText, value, out fieldElement);

            field.RegisterValueChangedCallback(evt);

            fieldElement.AddToClassList("eeditor-inspectorField");
            fieldElement.tooltip = label;

            VisualElement root = new VisualElement();

            root.Add(fieldElement);

            root.AddToClassList("eeditor-inspectorProperty");

            return(root);
        }