Ejemplo n.º 1
0
        // showDefinedOnly: 只显示已定义
        // searchCount: 结果数量限制
        private void UpdateSearchResults()
        {
            var keyword                 = _searchKeyword;
            var sliceKeyword            = _searchSliceKeyword;
            var showDefinedOnly         = _showDefinedOnly;
            var showSelectionOnly       = _showSelectionOnly;
            var showStreamingAssetsOnly = _showStreamingAssetsOnly;
            var searchCount             = _data.searchMax;

            _searchResults.Clear();
            var selectionSet = new HashSet <string>();

            if (showSelectionOnly)
            {
                for (int i = 0, size = Selection.objects.Length; i < size; i++)
                {
                    var sel       = Selection.objects[i];
                    var assetPath = AssetDatabase.GetAssetPath(sel);
                    if (!string.IsNullOrEmpty(assetPath))
                    {
                        selectionSet.Add(assetPath);
                    }
                }
            }

            _data.ForEachAsset((bundleInfo, bundleSplit, bundleSlice, assetGuid) =>
            {
                if (_searchResults.Count < searchCount)
                {
                    if (!showStreamingAssetsOnly || bundleSlice.streamingAssets)
                    {
                        var assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
                        if (!showSelectionOnly || selectionSet.Contains(assetPath))
                        {
                            if (string.IsNullOrEmpty(keyword) ||
                                assetPath.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) >= 0)
                            {
                                if (string.IsNullOrEmpty(sliceKeyword) ||
                                    bundleSlice.name.IndexOf(sliceKeyword, StringComparison.OrdinalIgnoreCase) >= 0)
                                {
                                    var attrs = _data.GetAssetAttributes(assetGuid);
                                    if (attrs != null || !showDefinedOnly)
                                    {
                                        var result = new SearchResult()
                                        {
                                            bundleInfo  = bundleInfo,
                                            bundleSplit = bundleSplit,
                                            bundleSlice = bundleSlice,
                                            assetPath   = assetPath,
                                            assetGuid   = assetGuid,
                                        };

                                        _searchResults.Add(result);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }