예제 #1
0
        private static AssetAttributes DrawSingleAssetAttributes(BundleBuilderData data, string assetPath)
        {
            var fileInfoWidth = 60f;
            var fileInfo      = new FileInfo(assetPath);
            var fileSize      = fileInfo.Exists ? fileInfo.Length : 0L;
            var assetObject   = AssetDatabase.LoadMainAssetAtPath(assetPath);
            var attrs         = data.GetAssetPathAttributes(assetPath);
            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);
            EditorGUILayout.LabelField(PathUtils.GetFileSizeString(fileSize), _rightAlignStyle, GUILayout.MaxWidth(fileInfoWidth));

            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.RemoveAssetPathAttributes(assetPath);
            }
            else if (bNew)
            {
                if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                {
                    var newAttributes = data.AddAssetPathAttributes(assetPath);
                    newAttributes.priority = attrs.priority;
                    newAttributes.packer   = attrs.packer;
                }
            }

            return(attrs);
        }
예제 #2
0
        private static AssetAttributes DrawSearchResultAssetAttributes(Rect elementRect, BundleBuilderData data, SearchResult result, BundleBuilderWindow builder, bool batchMode)
        {
            var assetPath      = result.assetPath;
            var fileInfoWidth  = 60f;
            var sliceInfoWidth = 260f;
            var fileInfo       = new FileInfo(assetPath);
            var fileSize       = fileInfo.Exists ? fileInfo.Length : 0L;
            var attrs          = data.GetAssetPathAttributes(assetPath);
            var bNew           = attrs == null;

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

            var iRect        = new Rect(elementRect.x, elementRect.y, 110f, elementRect.height);
            var nAssetPacker = (AssetPacker)EditorGUI.EnumPopup(iRect, attrs.packer);

            iRect.x     += 110f + 8f;
            iRect.width  = 220f;
            iRect.height = elementRect.height - 2f;
            var nPriority = EditorGUI.IntSlider(iRect, attrs.priority, 0, data.priorityMax);

            iRect.x     += iRect.width;
            iRect.width  = 180f;
            iRect.height = elementRect.height - 4f;
            if (assetPath.StartsWith("Assets/"))
            {
                var assetObject = AssetDatabase.LoadMainAssetAtPath(assetPath);
                EditorGUI.ObjectField(iRect, assetObject, typeof(Object), false);
            }
            else
            {
                EditorGUI.LabelField(iRect, "<External>");
            }
            iRect.x     += iRect.width;
            iRect.width  = fileInfoWidth;
            iRect.height = elementRect.height - 2f;
            EditorGUI.LabelField(iRect, PathUtils.GetFileSizeString(fileSize), _rightAlignStyle);

            iRect.x    += iRect.width;
            iRect.width = elementRect.width - iRect.x - sliceInfoWidth - 20f + 20f;
            EditorGUI.TextField(iRect, assetPath);

            iRect.x     += iRect.width;
            iRect.width  = sliceInfoWidth;
            iRect.height = elementRect.height - 2f;
            if (result.bundleInfo != null)
            {
                EditorGUI.TextField(iRect, result.bundleSlice.name);
                iRect.x    += iRect.width;
                iRect.width = 20f;
                if (GUI.Button(iRect, ">"))
                {
                    BundleAssetsWindow.Inspect(data, new List <BundleBuilderData.BundleInfo>(new[] { result.bundleInfo }));
                }
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUI.TextField(iRect, "<null>");
                iRect.x    += iRect.width;
                iRect.width = 20f;
                GUI.Button(iRect, ">");
                EditorGUI.EndDisabledGroup();
            }

            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.RemoveAssetPathAttributes(assetPath);
                }
                else if (bNew)
                {
                    if (attrs.priority != 0 || attrs.packer != AssetPacker.Auto)
                    {
                        var newAttributes = data.AddAssetPathAttributes(assetPath);
                        newAttributes.priority = attrs.priority;
                        newAttributes.packer   = attrs.packer;
                    }
                }
            }

            return(attrs);
        }
예제 #3
0
        // showDefinedOnly: 只显示已定义
        // searchCount: 结果数量限制
        private void UpdateSearchResults()
        {
            var keyword                 = _searchKeyword;
            var sliceKeyword            = _searchSliceKeyword;
            var showDefinedOnly         = _showDefinedOnly;
            var useRegexMatch           = _useRegexMatch;
            var showSelectionOnly       = _showSelectionOnly;
            var showStreamingAssetsOnly = _showStreamingAssetsOnly;
            // var searchCount = _data.searchMax;

            Regex nameRegex      = null;
            Regex sliceNameRegex = null;

            if (_useRegexMatch)
            {
                nameRegex      = MakeRegex(keyword);
                sliceNameRegex = MakeRegex(sliceKeyword);
            }

            _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.ForEachAssetPath((bundleInfo, bundleSplit, bundleSlice, assetPath) =>
            {
                if (!showStreamingAssetsOnly || bundleSlice.streamingAssets)
                {
                    if (!showSelectionOnly || selectionSet.Contains(assetPath))
                    {
                        if (IsStringMatch(nameRegex, keyword, assetPath))
                        {
                            if (IsStringMatch(sliceNameRegex, sliceKeyword, bundleSlice.name))
                            {
                                var attrs = _data.GetAssetPathAttributes(assetPath);
                                if (attrs != null || !showDefinedOnly)
                                {
                                    var result = new SearchResult()
                                    {
                                        bundleInfo  = bundleInfo,
                                        bundleSplit = bundleSplit,
                                        bundleSlice = bundleSlice,
                                        assetPath   = assetPath,
                                    };

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