コード例 #1
0
        /// <summary>
        /// 重命名AB包
        /// </summary>
        public void RenameBundle(string name)
        {
            for (int i = 0; i < _filePaths.Count; i++)
            {
                AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(_filePaths[i]);
                file.ReadDependenciesFile();
                file.Bundled = name;
                AssetImporter import = AssetImporter.GetAtPath(_filePaths[i]);
                import.assetBundleName = name;

                for (int j = 0; j < file.Dependencies.Count; j++)
                {
                    AssetFileInfo depenFile = AssetBundleEditorUtility.GetFileInfoByPath(file.Dependencies[j]);
                    if (depenFile.IndirectBundled.ContainsKey(Name))
                    {
                        int number = depenFile.IndirectBundled[Name];
                        depenFile.IndirectBundled.Remove(Name);
                        depenFile.IndirectBundled.Add(name, number);
                    }
                    if (depenFile.IndirectBundledRelation.ContainsKey(_filePaths[i]))
                    {
                        depenFile.IndirectBundledRelation[_filePaths[i]] = name;
                    }
                }
            }

            AssetDatabase.RemoveAssetBundleName(Name, true);
            Name = name;
        }
コード例 #2
0
        private void CurrentAssetBundlesGUI()
        {
            _currentABViewRect   = new Rect(5, (int)position.height / 2 + 10, 240, (int)position.height / 2 - 15);
            _currentABScrollRect = new Rect(5, (int)position.height / 2 + 10, 240, _currentABViewHeight);
            _currentABScroll     = GUI.BeginScrollView(_currentABViewRect, _currentABScroll, _currentABScrollRect);
            GUI.BeginGroup(_currentABScrollRect, _box);

            _currentABViewHeight = 5;

            if (_currentAB != null)
            {
                GUI.Button(new Rect(0, 0, 160, 20), _currentAB.Name, _preButton);
                if (GUI.Button(new Rect(160, 0, 80, 20), _currentAB.MemorySizeFormat, _preDropDown))
                {
                    _currentAB.ChangeSortMode();
                }
                _currentABViewHeight += 20;

                for (int i = 0; i < _currentAB.Count; i++)
                {
                    AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(_currentAB[i]);
                    if (_currentABFile == file)
                    {
                        GUI.Box(new Rect(0, _currentABViewHeight, 240, 15), "", _LRSelect);
                    }
                    GUIContent content = EditorGUIUtility.ObjectContent(null, file.AssetType);
                    content.text = file.Name;
                    if (GUI.Button(new Rect(5, _currentABViewHeight, 150, 15), content, _prefabLabel))
                    {
                        _currentABFile         = file;
                        Selection.activeObject = _currentABFile.AssetObject;
                        EditorGUIUtility.PingObject(_currentABFile.AssetObject);
                    }
                    GUI.Label(new Rect(160, _currentABViewHeight, 60, 15), file.MemorySizeFormat, _assetLabel);
                    if (GUI.Button(new Rect(220, _currentABViewHeight, 20, 15), "", _oLMinus))
                    {
                        _currentAB.RemoveAsset(_currentAB[i]);
                        _currentABFile = null;
                    }
                    _currentABViewHeight += 20;
                }
            }

            _currentABViewHeight += 5;
            if (_currentABViewHeight < _currentABViewRect.height)
            {
                _currentABViewHeight = (int)_currentABViewRect.height;
            }

            GUI.EndGroup();
            GUI.EndScrollView();
        }
コード例 #3
0
 /// <summary>
 /// 改变排序方式
 /// </summary>
 public void ChangeSortMode()
 {
     if (_sortMode == BundleAssetSortMode.FromBig)
     {
         _sortMode = BundleAssetSortMode.FromSmall;
         _filePaths.Sort((a, b) =>
         {
             AssetFileInfo afile = AssetBundleEditorUtility.GetFileInfoByPath(a);
             AssetFileInfo bfile = AssetBundleEditorUtility.GetFileInfoByPath(b);
             if (afile.MemorySize > bfile.MemorySize)
             {
                 return(1);
             }
             else if (afile.MemorySize == bfile.MemorySize)
             {
                 return(0);
             }
             else
             {
                 return(-1);
             }
         });
     }
     else
     {
         _sortMode = BundleAssetSortMode.FromBig;
         _filePaths.Sort((a, b) =>
         {
             AssetFileInfo afile = AssetBundleEditorUtility.GetFileInfoByPath(a);
             AssetFileInfo bfile = AssetBundleEditorUtility.GetFileInfoByPath(b);
             if (afile.MemorySize > bfile.MemorySize)
             {
                 return(-1);
             }
             else if (afile.MemorySize == bfile.MemorySize)
             {
                 return(0);
             }
             else
             {
                 return(1);
             }
         });
     }
 }
コード例 #4
0
        /// <summary>
        /// 添加资源到AB包中
        /// </summary>
        public void AddAsset(string filePath)
        {
            AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(filePath);

            if (file.Bundled != Name)
            {
                file.Bundled = Name;
                MemorySize  += file.MemorySize;
                file.ReadDependenciesFile();
                file.UpdateRedundantState();
                _filePaths.Add(filePath);

                for (int i = 0; i < file.Dependencies.Count; i++)
                {
                    AssetFileInfo depenFile = AssetBundleEditorUtility.GetFileInfoByPath(file.Dependencies[i]);
                    if (depenFile.IsValid)
                    {
                        if (!depenFile.IndirectBundled.ContainsKey(Name))
                        {
                            depenFile.IndirectBundled.Add(Name, 0);
                            MemorySize += depenFile.MemorySize;
                        }
                        depenFile.IndirectBundled[Name] = depenFile.IndirectBundled[Name] + 1;
                        if (!depenFile.IndirectBundledRelation.ContainsKey(filePath))
                        {
                            depenFile.IndirectBundledRelation.Add(filePath, Name);
                        }
                        depenFile.UpdateRedundantState();
                    }
                }
                MemorySizeFormat = EditorUtility.FormatBytes(MemorySize);
            }

            AssetImporter import = AssetImporter.GetAtPath(filePath);

            import.assetBundleName = Name;
        }
コード例 #5
0
        /// <summary>
        /// 从AB包中移除资源
        /// </summary>
        public void RemoveAsset(string filePath)
        {
            AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(filePath);

            if (file.Bundled == Name)
            {
                file.Bundled = "";
                MemorySize  -= file.MemorySize;
                file.ReadDependenciesFile();
                file.UpdateRedundantState();
                _filePaths.Remove(filePath);

                for (int i = 0; i < file.Dependencies.Count; i++)
                {
                    AssetFileInfo depenFile = AssetBundleEditorUtility.GetFileInfoByPath(file.Dependencies[i]);
                    if (depenFile.IndirectBundled.ContainsKey(Name))
                    {
                        depenFile.IndirectBundled[Name] = depenFile.IndirectBundled[Name] - 1;
                        if (depenFile.IndirectBundled[Name] <= 0)
                        {
                            depenFile.IndirectBundled.Remove(Name);
                            MemorySize -= depenFile.MemorySize;
                        }
                    }
                    if (depenFile.IndirectBundledRelation.ContainsKey(filePath))
                    {
                        depenFile.IndirectBundledRelation.Remove(filePath);
                    }
                    depenFile.UpdateRedundantState();
                }
                MemorySizeFormat = EditorUtility.FormatBytes(MemorySize);
            }

            AssetImporter import = AssetImporter.GetAtPath(filePath);

            import.assetBundleName = "";
        }
コード例 #6
0
        private void AssetPropertyGUI()
        {
            if (_currentFile != null)
            {
                _currentFile.ReadDependenciesFile();

                GUI.color = (_currentFile.IsRedundant ? Color.red : Color.white);

                _assetPropertyViewRect   = new Rect((int)position.width - 420, 50, 400, 400);
                _assetPropertyScrollRect = new Rect((int)position.width - 420, 50, 400, _assetPropertyViewHeight);
                _assetPropertyScroll     = GUI.BeginScrollView(_assetPropertyViewRect, _assetPropertyScroll, _assetPropertyScrollRect);
                GUI.BeginGroup(_assetPropertyScrollRect, _helpBox);

                _assetPropertyViewHeight = 5;

                GUIContent content = EditorGUIUtility.ObjectContent(null, _currentFile.AssetType);
                content.text = _currentFile.Name;
                GUI.Label(new Rect(5, _assetPropertyViewHeight, 40, 15), "Asset:");
                if (GUI.Button(new Rect(50, _assetPropertyViewHeight, 280, 15), content, _prefabLabel))
                {
                    Selection.activeObject = _currentFile.AssetObject;
                    EditorGUIUtility.PingObject(_currentFile.AssetObject);
                }
                GUI.enabled = (_currentAB != null && _currentFile.Bundled == "");
                if (GUI.Button(new Rect(340, _assetPropertyViewHeight, 50, 15), "Bundle", _preButton))
                {
                    _currentAB.AddAsset(_currentFile.AssetPath);
                    _currentFile = null;
                    return;
                }
                GUI.enabled = true;
                _assetPropertyViewHeight += 20;

                GUI.Label(new Rect(5, _assetPropertyViewHeight, 330, 15), "Path: " + _currentFile.AssetPath);
                if (GUI.Button(new Rect(340, _assetPropertyViewHeight, 50, 15), "Copy", _preButton))
                {
                    GUIUtility.systemCopyBuffer = _currentFile.AssetPath;
                }
                _assetPropertyViewHeight += 20;

                if (_currentFile.Dependencies.Count > 0)
                {
                    _isShowDependencies       = EditorGUI.Foldout(new Rect(5, _assetPropertyViewHeight, 390, 15), _isShowDependencies, "Dependencies:", true);
                    _assetPropertyViewHeight += 20;
                    if (_isShowDependencies)
                    {
                        for (int i = 0; i < _currentFile.Dependencies.Count; i++)
                        {
                            AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(_currentFile.Dependencies[i]);
                            content      = EditorGUIUtility.ObjectContent(null, file.AssetType);
                            content.text = file.Name;
                            if (GUI.Button(new Rect(45, _assetPropertyViewHeight, 350, 15), content, _prefabLabel))
                            {
                                Selection.activeObject = file.AssetObject;
                                EditorGUIUtility.PingObject(file.AssetObject);
                            }
                            _assetPropertyViewHeight += 20;
                        }
                    }
                }

                if (_currentFile.IndirectBundledRelation.Count > 0)
                {
                    _isShowIndirectBundled    = EditorGUI.Foldout(new Rect(5, _assetPropertyViewHeight, 390, 15), _isShowIndirectBundled, "Indirect Bundled:", true);
                    _assetPropertyViewHeight += 20;
                    if (_isShowIndirectBundled)
                    {
                        foreach (KeyValuePair <string, string> bundle in _currentFile.IndirectBundledRelation)
                        {
                            AssetFileInfo file = AssetBundleEditorUtility.GetFileInfoByPath(bundle.Key);
                            content      = EditorGUIUtility.ObjectContent(null, file.AssetType);
                            content.text = file.Name + "  >>  " + bundle.Value;
                            if (GUI.Button(new Rect(45, _assetPropertyViewHeight, 350, 15), content, _prefabLabel))
                            {
                                Selection.activeObject = file.AssetObject;
                                EditorGUIUtility.PingObject(file.AssetObject);
                            }
                            _assetPropertyViewHeight += 20;
                        }
                    }
                }

                _assetPropertyViewHeight += 5;
                if (_assetPropertyViewHeight < _assetPropertyViewRect.height)
                {
                    _assetPropertyViewHeight = (int)_assetPropertyViewRect.height;
                }

                GUI.EndGroup();
                GUI.EndScrollView();

                GUI.color = Color.white;
            }
        }