Ejemplo n.º 1
0
 void SelectRange(PooledList <ComponentType> commonComponentTypes, int boundA, int boundB)
 {
     for (var i = math.min(boundA, boundB); i <= math.max(boundA, boundB); i++)
     {
         m_State.SelectedComponentTypes.Add(commonComponentTypes.List[i].TypeIndex);
     }
 }
 void SearchChanged()
 {
     using (var pooled = PooledList <ComponentElementBase> .Make())
     {
         var list = pooled.List;
         m_ComponentsRoot.Query <ComponentElementBase>().ToList(list);
         if (m_Filters.Count == 0)
         {
             list.ForEach(ce => ce.Show());
         }
         else
         {
             list.ForEach(ce =>
             {
                 var showShow = false;
                 foreach (var token in m_Filters)
                 {
                     if (ce.Path.IndexOf(token, StringComparison.InvariantCultureIgnoreCase) >= 0)
                     {
                         showShow = true;
                         break;
                     }
                 }
                 if (showShow)
                 {
                     ce.Show();
                 }
                 else
                 {
                     ce.Hide();
                 }
             });
         }
     }
 }
        void UpdateComponentOrder(EntityInspectorComponentOrder current)
        {
            m_CurrentComponentOrder.Reset();
            using (var pooledElements = PooledList <ComponentElementBase> .Make())
            {
                ComputeCurrentComponentOrder(m_CurrentComponentOrder, pooledElements);

                if (current == m_CurrentComponentOrder)
                {
                    return;
                }

                // Component removed since the last update
                using (var pooled = ComputeRemovedComponents(current.Components, m_CurrentComponentOrder.Components))
                {
                    var list = pooled.List;
                    foreach (var path in list)
                    {
                        var element = pooledElements.List.Find(ce => ce.Path == path);
                        element?.RemoveFromHierarchy();
                    }
                }

                // Tags removed since the last update
                using (var pooled = ComputeRemovedComponents(current.Tags, m_CurrentComponentOrder.Tags))
                {
                    var list = pooled.List;
                    foreach (var path in list)
                    {
                        var element = pooledElements.List.Find(ce => ce.Path == path);
                        element?.RemoveFromHierarchy();
                    }
                }

                // Component added since the last update
                using (var pooled = ComputeAddedComponents(current.Components, m_CurrentComponentOrder.Components))
                {
                    var list      = pooled.List;
                    var container = Target.Container;
                    foreach (var path in list)
                    {
                        PropertyContainer.Visit(ref container, m_InspectorVisitor, new PropertyPath(path));
                    }
                }

                // Tags removed since the last update
                using (var pooled = ComputeAddedComponents(current.Tags, m_CurrentComponentOrder.Tags))
                {
                    var list      = pooled.List;
                    var container = Target.Container;
                    foreach (var path in list)
                    {
                        PropertyContainer.Visit(ref container, m_InspectorVisitor, new PropertyPath(path));
                    }
                }
            }
        }
        public EntityQueryDesc BuildQuery(string input, out string unmatchedInput)
        {
            unmatchedInput = input;

            if (string.IsNullOrEmpty(input))
            {
                return(null);
            }

            var matches = k_Regex.Matches(input);

            if (matches.Count == 0)
            {
                return(null);
            }

            using (var componentTypes = PooledList <ComponentType> .Make())
            {
                var b   = new StringBuilder();
                var pos = 0;
                for (var i = 0; i < matches.Count; i++)
                {
                    var match      = matches[i];
                    var matchGroup = match.Groups["componentType"];

                    var length = match.Index - pos;
                    if (length > 0)
                    {
                        b.Append(input.Substring(pos, length));
                    }

                    pos = match.Index + match.Length;

                    if (m_ComponentTypes.TryGetValue(matchGroup.Value, out var includedType))
                    {
                        componentTypes.List.Add(includedType);
                    }
                }

                if (input.Length - pos > 0)
                {
                    b.Append(input.Substring(pos));
                }

                unmatchedInput = b.ToString();

                if (componentTypes.List.Count == 0)
                {
                    return(null);
                }

                return(new EntityQueryDesc {
                    Any = componentTypes.List.ToArray()
                });
            }
        }
        public static void ForceUpdateBindings(this VisualElement element)
        {
            using (var pooled = PooledList <IBinding> .Make())
            {
                var list = pooled.List;
                PopulateBindings(element, list);

                foreach (var binding in list)
                {
                    binding.PreUpdate();
                }

                foreach (var binding in list)
                {
                    binding.Update();
                }
            }
        }
Ejemplo n.º 6
0
        void HandleComponentSelection(PooledList <ComponentType> componentTypes, ComponentType componentType, int indexInOrderedComponentList, bool isSelected, bool isSelectedInUi)
        {
            var isMultiSelectionEnabled = EditorGUI.actionKey;
            var isWideSelectionEnabled  = Event.current.shift;

            if (isSelected && !isSelectedInUi)
            {
                if (isWideSelectionEnabled && m_LastSelectedComponentIdx != -1)
                {
                    m_State.SelectedComponentTypes.Clear();
                    SelectRange(componentTypes, m_LastSelectedComponentIdx, indexInOrderedComponentList);
                }
                else if (m_State.SelectedComponentTypes.Count > 1 && !isMultiSelectionEnabled)
                {
                    m_State.SelectedComponentTypes.Clear();
                    m_State.SelectedComponentTypes.Add(componentType.TypeIndex);
                    m_LastSelectedComponentIdx = indexInOrderedComponentList;
                }
                else
                {
                    m_State.SelectedComponentTypes.Remove(componentType.TypeIndex);
                }
            }
            else if (!isSelected && isSelectedInUi)
            {
                if (!isMultiSelectionEnabled)
                {
                    m_State.SelectedComponentTypes.Clear();
                }

                if (isWideSelectionEnabled && m_LastSelectedComponentIdx != -1 && m_LastSelectedComponentIdx != indexInOrderedComponentList)
                {
                    SelectRange(componentTypes, m_LastSelectedComponentIdx, indexInOrderedComponentList);
                }
                else
                {
                    m_State.SelectedComponentTypes.Add(componentType.TypeIndex);
                    m_LastSelectedComponentIdx = indexInOrderedComponentList;
                }
            }
        }
Ejemplo n.º 7
0
 public static PooledList <T> GetList <T>()
 {
     return(PooledList <T> .Make());
 }