Exemplo n.º 1
0
        // showDefinedOnly: 只显示已定义
        // searchCount: 结果数量限制
        private void UpdateSearchResults(string keyword, bool showDefinedOnly, bool showSelectionOnly, int searchCount)
        {
            _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);
                    }
                }
            }

            for (var i = 0; i < data.allCollectedAssetsPath.Length; i++)
            {
                var assetPath = data.allCollectedAssetsPath[i];
                if (showSelectionOnly && !selectionSet.Contains(assetPath))
                {
                    continue;
                }

                if (string.IsNullOrEmpty(keyword) ||
                    assetPath.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    var assetGuid = AssetDatabase.AssetPathToGUID(assetPath);
                    var attrs     = data.GetAssetAttributes(assetGuid);
                    if (attrs != null || !showDefinedOnly)
                    {
                        _searchResults.Add(assetPath);
                    }

                    if (_searchResults.Count >= searchCount)
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static AssetAttributes DrawSingleAssetAttributes(BundleBuilderData data, string assetGuid,
                                                                 BundleBuilderWindow builder, bool batchMode, Action additionalOp)
        {
            var assetPath   = AssetDatabase.GUIDToAssetPath(assetGuid);
            var assetObject = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var attrs       = data.GetAssetAttributes(assetGuid);
            var bNew        = attrs == null;

            if (bNew)
            {
                attrs = new AssetAttributes();
            }

            var nAssetPacker =
                (AssetPacker)EditorGUILayout.EnumPopup(attrs.packer, GUILayout.MaxWidth(110f));
            var nPriority = EditorGUILayout.IntSlider(attrs.priority, 0, data.priorityMax,
                                                      GUILayout.MaxWidth(220f));

            EditorGUILayout.ObjectField(assetObject, typeof(Object), false, GUILayout.MaxWidth(180f));
            EditorGUILayout.TextField(assetPath);
            var fileInfoWidth = 60f;

            EditorGUILayout.LabelField(GetFileSizeString(assetPath), _rightAlignStyle, GUILayout.MaxWidth(fileInfoWidth));
            additionalOp?.Invoke();

            if (batchMode)
            {
                if (nAssetPacker != attrs.packer)
                {
                    builder?.ApplyAllMarks(attributes => attributes.packer = nAssetPacker);
                }

                if (nPriority != attrs.priority)
                {
                    var deltaPriority = nPriority - attrs.priority;
                    builder?.ApplyAllMarks(attributes => attributes.priority = Math.Max(0,
                                                                                        Math.Min(data.priorityMax, attributes.priority + deltaPriority)));
                }
            }
            else
            {
                if (nAssetPacker != attrs.packer)
                {
                    attrs.packer = nAssetPacker;
                    data.MarkAsDirty();
                }

                if (nPriority != attrs.priority)
                {
                    attrs.priority = nPriority;
                    data.MarkAsDirty();
                }

                if (attrs.priority == 0 && attrs.packer == AssetPacker.Auto)
                {
                    data.RemoveAssetAttributes(assetGuid);
                }
                else if (bNew)
                {
                    if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                    {
                        var newAttributes = data.AddAssetAttributes(assetGuid);
                        newAttributes.priority = attrs.priority;
                        newAttributes.packer   = attrs.packer;
                    }
                }
            }

            return(attrs);
        }
Exemplo n.º 3
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);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 4
0
        private static AssetAttributes DrawSingleAssetAttributes(BundleBuilderData data, string assetGuid,
                                                                 BundleBuilderWindow builder, bool batchMode, bool rLookup)
        {
            var assetPath   = AssetDatabase.GUIDToAssetPath(assetGuid);
            var assetObject = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var attrs       = data.GetAssetAttributes(assetGuid);
            var bNew        = attrs == null;

            if (bNew)
            {
                attrs = new AssetAttributes();
            }

            var nAssetPacker =
                (AssetPacker)EditorGUILayout.EnumPopup(attrs.packer, GUILayout.MaxWidth(80f));
            var nPriority = EditorGUILayout.IntSlider(attrs.priority, 0, data.priorityMax,
                                                      GUILayout.MaxWidth(220f));

            EditorGUILayout.ObjectField(assetObject, typeof(Object), false, GUILayout.MaxWidth(180f));
            EditorGUILayout.TextField(assetPath);
            if (rLookup)
            {
                BundleBuilderData.BundleInfo  rBundleInfo;
                BundleBuilderData.BundleSplit rBundleSplit;
                BundleBuilderData.BundleSlice rBundleSlice;
                var exists = data.Lookup(assetGuid, out rBundleInfo, out rBundleSplit, out rBundleSlice);
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.TextField(exists ? rBundleSlice.name : "<null>");
                EditorGUI.EndDisabledGroup();
                if (GUILayout.Button(">", GUILayout.Width(20f)))
                {
                    BundleAssetsWindow.Inspect(data, new List <BundleBuilderData.BundleInfo>(new[] { rBundleInfo }));
                }
            }

            if (batchMode)
            {
                if (nAssetPacker != attrs.packer)
                {
                    builder?.ApplyAllMarks(attributes => attributes.packer = nAssetPacker);
                }

                if (nPriority != attrs.priority)
                {
                    var deltaPriority = nPriority - attrs.priority;
                    builder?.ApplyAllMarks(attributes => attributes.priority = Math.Max(0,
                                                                                        Math.Min(data.priorityMax, attributes.priority + deltaPriority)));
                }
            }
            else
            {
                if (nAssetPacker != attrs.packer)
                {
                    attrs.packer = nAssetPacker;
                    data.MarkAsDirty();
                }

                if (nPriority != attrs.priority)
                {
                    attrs.priority = nPriority;
                    data.MarkAsDirty();
                }

                if (attrs.priority == 0 && attrs.packer == AssetPacker.Auto)
                {
                    data.RemoveAssetAttributes(assetGuid);
                }
                else if (bNew)
                {
                    if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                    {
                        var newAttributes = data.AddAssetAttributes(assetGuid);
                        newAttributes.priority = attrs.priority;
                        newAttributes.packer   = attrs.packer;
                    }
                }
            }

            return(attrs);
        }