internal void SetContext(EntitySelectionProxy proxy)
        {
            World = proxy.World;
            var isReadonly = !EditorApplication.isPlaying || IsWorldReadOnly(World);

            // TODO: Remove once we allow to write back the data.
            isReadonly      = true;
            EntityContainer = new EntityContainer(World.EntityManager, proxy.Entity, isReadonly);
        }
Ejemplo n.º 2
0
        public EntityHierarchy()
        {
            style.flexGrow = 1.0f;

            m_TreeView = new TreeView(m_TreeViewRootItems, Constants.EntityHierarchy.ItemHeight, OnMakeItem, OnBindItem)
            {
                selectionType = SelectionType.Single,
                name          = Constants.EntityHierarchy.FullViewName
            };
            m_TreeView.style.flexGrow     = 1.0f;
            m_TreeView.onSelectionChange += OnSelectionChanged;
            m_TreeView.RegisterCallback <PointerDownEvent>(evt =>
            {
                if (evt.button == (int)MouseButton.LeftMouse)
                {
                    m_TreeView.ClearSelection();
                }
            });
            m_TreeView.ItemExpandedStateChanging += (item, isExpanding) =>
            {
                var entityHierarchyItem = (EntityHierarchyItem)item;
                if (entityHierarchyItem.NodeId.Kind == NodeKind.Scene || entityHierarchyItem.NodeId.Kind == NodeKind.SubScene)
                {
                    EntityHierarchyState.OnFoldingStateChanged(entityHierarchyItem.NodeId, isExpanding);
                }
            };

            m_ListView = new ListView(m_ListViewFilteredItems, Constants.EntityHierarchy.ItemHeight, OnMakeItem, OnBindListItem)
            {
                selectionType = SelectionType.Single,
                name          = Constants.EntityHierarchy.SearchViewName
            };
            m_ListView.RegisterCallback <PointerDownEvent>(evt =>
            {
                if (evt.button == (int)MouseButton.LeftMouse)
                {
                    m_ListView.ClearSelection();
                }
            });

            m_ListView.style.flexGrow = 1.0f;

#if UNITY_2020_1_OR_NEWER
            m_ListView.onSelectionChange += OnSelectionChanged;
#else
            m_ListView.onSelectionChanged += OnSelectionChanged;
#endif

            m_SelectionProxy           = ScriptableObject.CreateInstance <EntitySelectionProxy>();
            m_SelectionProxy.hideFlags = HideFlags.HideAndDontSave;
            m_SelectionProxy.EntityControlSelectButton += OnSelectionChangedByInspector;

            m_Searcher = new DefaultHierarchySearcher();

            SwitchViewMode(ViewMode.Full);
        }
 void OnEnable()
 {
     selectionProxy           = ScriptableObject.CreateInstance <EntitySelectionProxy>();
     selectionProxy.hideFlags = HideFlags.HideAndDontSave;
     CreateSystemListView();
     CreateComponentGroupListView();
     CreateEntityListView();
     systemListView.TouchSelection();
     EditorApplication.playModeStateChanged += OnPlayModeStateChange;
 }
Ejemplo n.º 4
0
        private void CreateEntitySelectionProxy()
        {
            selectionProxy           = ScriptableObject.CreateInstance <EntitySelectionProxy>();
            selectionProxy.hideFlags = HideFlags.HideAndDontSave;

            selectionProxy.EntityControlDoubleClick += entity =>
            {
                entityListView?.OnEntitySelected(entity);
            };
        }
Ejemplo n.º 5
0
        private void CreateEntitySelectionProxy()
        {
            selectionProxy           = ScriptableObject.CreateInstance <EntitySelectionProxy>();
            selectionProxy.hideFlags = HideFlags.HideAndDontSave;

            selectionProxy.EntityControlSelectButton += (world, entity) =>
            {
                SetAllSelections(world, null, null, entity);
            };
        }
Ejemplo n.º 6
0
 void OnEnable()
 {
     Instance                 = this;
     selectionProxy           = ScriptableObject.CreateInstance <EntitySelectionProxy>();
     selectionProxy.hideFlags = HideFlags.HideAndDontSave;
     filterUI                 = new ComponentTypeFilterUI(SetAllEntitiesFilter, () => WorldSelection);
     CreateSystemListView();
     CreateComponentGroupListView();
     CreateEntityListView();
     systemListView.TouchSelection();
     EditorApplication.playModeStateChanged += OnPlayModeStateChange;
 }
        void OnEnable()
        {
            visitor = new EntityIMGUIVisitor(entity =>
            {
                var targetProxy = (EntitySelectionProxy)target;
                if (!targetProxy.Exists)
                {
                    return;
                }

                EntitySelectionProxy.SelectEntity(targetProxy.World, entity);
            },
                                             entity => currentEntityManager.GetName(entity));

            inclusionList = new SystemInclusionList();
        }
        void Initialize(EntitySelectionProxy proxy)
        {
            m_Context.SetContext(proxy);
            m_Root.Clear();

            var header = new PropertyElement();

            header.AddContext(m_Context);
            header.SetTarget(new EntityHeader(m_Context));
            m_Root.Add(header);
            m_SearchField = header.Q <ToolbarSearchField>();
            m_SearchField.RegisterValueChangedCallback(evt =>
            {
                m_Filters.Clear();
                var value   = evt.newValue.Trim();
                var matches = value.Split(' ');
                foreach (var match in matches)
                {
                    m_Filters.Add(match);
                }

                SearchChanged();
            });

            m_Settings = m_Root.Q <ToolbarMenu>();
            // TODO: Remove once we have menu items.
            m_Settings.Hide();

            m_ComponentsRoot = new VisualElement();

            m_Root.Add(m_ComponentsRoot);
            Resources.Templates.Inspector.ComponentsRoot.AddStyles(m_ComponentsRoot);
            m_ComponentsRoot.AddToClassList("entity-inspector__components-root");
            m_ComponentsRoot.RegisterCallback <GeometryChangedEvent>(OnGeometryChanged);
            m_TagsRoot = new TagComponentContainer(m_Context);
            m_ComponentsRoot.Add(m_TagsRoot);

            m_InspectorVisitor = new EntityInspectorVisitor(m_ComponentsRoot, m_TagsRoot, m_Context);
            PropertyContainer.Visit(m_Context.EntityContainer, m_InspectorVisitor);

            m_Root.ForceUpdateBindings();
        }
Ejemplo n.º 9
0
        void OnLocalSelectionChanged(EntityHierarchyItem selectedItem)
        {
            m_SelectedItem = selectedItem.NodeId;
            if (selectedItem.NodeId.Kind == NodeKind.Entity)
            {
                var entity = selectedItem.NodeId.ToEntity();
                if (entity != Entity.Null)
                {
                    var undoGroup = Undo.GetCurrentGroup();
                    EntitySelectionProxy.SelectEntity(m_Hierarchy.World, entity);

                    // Collapsing the selection of the entity into the selection of the ListView / TreeView item
                    Undo.CollapseUndoOperations(undoGroup);
                }
            }
            else
            {
                // TODO: Deal with non-Entity selections
            }
        }
        static void OnClicked(ClickEvent evt, EntityInspectorContext context, VisualElement current)
        {
            switch (current)
            {
            case Foldout foldout:
                if (!foldout.Q <Toggle>().worldBound.Contains(evt.position))
                {
                    break;
                }
                foldout.value = !foldout.value;
                break;

            case ObjectField objectField:
                var display = objectField.Q(className: UssClasses.UIToolkit.ObjectField.Display);
                if (null == display)
                {
                    break;
                }
                if (!display.worldBound.Contains(evt.position))
                {
                    break;
                }

                if (evt.clickCount == 1)
                {
                    EditorGUIUtility.PingObject(objectField.value);
                }
                else
                {
                    var value = objectField.value;
                    if (null != value && value)
                    {
                        Selection.activeObject = value;
                    }
                }
                break;

            case EntityField entityField:
                var input = entityField.Q(className: "unity-entity-field__input");
                if (null == input)
                {
                    break;
                }
                if (!input.worldBound.Contains(evt.position))
                {
                    break;
                }

                if (evt.clickCount > 1)
                {
                    var world = context.World;
                    if (null == world || !world.IsCreated)
                    {
                        break;
                    }
                    if (!context.EntityManager.Exists(entityField.value))
                    {
                        break;
                    }

                    EntitySelectionProxy.SelectEntity(context.World, entityField.value);
                }
                break;
            }

            for (var i = 0; i < current.childCount; ++i)
            {
                OnClicked(evt, context, current[i]);
            }
        }