Exemple #1
0
        private List <PopupMenuItem> GetFiltered(int maxMismatchThreshold = 7, int maxNumberOfResults = 50)
        {
            int filterLength = filter.Length;

            if (filterLength == 0)
            {
                return(rootItems);
            }

            if (!string.Equals(filter, lastAppliedFilter))
            {
                lastAppliedFilter = filter;

                if (!searchableListBuilt)
                {
                    BuildSearchableList();
                }

                searchableList.Filter = filter;
                var matches = searchableList.GetValues(maxMismatchThreshold);
                int count   = Mathf.Min(matches.Length, maxNumberOfResults);

                                #if UNITY_EDITOR
                AssetPreview.SetPreviewTextureCacheSize(maxNumberOfResults);
                                #endif

                itemsFiltered.Clear();

                if (!searchableListBuilt)
                {
                    BuildSearchableList();
                }

                for (int n = 0; n < count; n++)
                {
                    var item = itemsByLabel[matches[n]];
                    itemsFiltered.Add(item);
                                        #if DEV_MODE && PI_ASSERTATIONS
                    if (item == null)
                    {
                        Debug.LogError("FindByLabel(\"" + matches[n] + "\") returned null\nwith rootItems:\n" + StringUtils.ToString(rootItems, "\n"));
                    }
                                        #endif
                }
            }
            return(itemsFiltered);
        }
        /// <summary>
        /// Gets AddComponentMenu items that should be shown in the Add Component menu with the provided search filter.
        /// </summary>
        /// <returns> An array containing all items for the Add Component menu that pass the filter. </returns>
        public static AddComponentMenuItem[] GetFiltered(string filter, int maxMismatchThreshold = 0, int maxNumberOfResults = 50)
        {
            int filterLength = filter.Length;

            if (filterLength == 0)
            {
                return(GetAll());
            }

            Setup();

            if (!string.Equals(filter, lastAppliedFilter))
            {
                lastAppliedFilter     = filter;
                searchableList.Filter = filter;
                var matches = searchableList.GetValues(maxMismatchThreshold);
                int count   = Mathf.Min(matches.Length, maxNumberOfResults);

                                #if UNITY_EDITOR
                UnityEditor.AssetPreview.SetPreviewTextureCacheSize(maxNumberOfResults);
                                #endif

                int oldCount = itemsFiltered.Length;
                if (oldCount != count)
                {
                    Array.Resize(ref itemsFiltered, count);
                }

                for (int n = 0; n < count; n++)
                {
                    itemsFiltered[n] = GetMenuItem(matches[n]);
                }
            }

            return(itemsFiltered);
        }