/// <summary>
        /// 读取资源文件夹下的子资源
        /// </summary>
        public static void ReadAssetsInChildren(AssetFolderInfo folder)
        {
            DirectoryInfo di = new DirectoryInfo(folder.FullPath);

            FileSystemInfo[] fileinfos = di.GetFileSystemInfos();
            for (int i = 0; i < fileinfos.Length; i++)
            {
                EditorUtility.DisplayProgressBar("Hold On", "Collect Assets[" + i + "/" + fileinfos.Length + "]......", (float)i / fileinfos.Length);

                if (fileinfos[i] is DirectoryInfo)
                {
                    if (IsValidFolder(fileinfos[i].Name))
                    {
                        AssetFolderInfo fi = GetFolderInfoByFullPath(fileinfos[i].FullName);
                        folder.ChildAsset.Add(fi);
                    }
                }
                else
                {
                    if (fileinfos[i].Extension != ".meta")
                    {
                        AssetFileInfo fi = GetFileInfoByPath(GetAssetPathByFullPath(fileinfos[i].FullName));
                        folder.ChildAsset.Add(fi);
                    }
                }
            }
            EditorUtility.ClearProgressBar();
        }
        private void AssetGUI(AssetInfoBase asset, int indentation)
        {
            AssetFileInfo   fileInfo   = asset as AssetFileInfo;
            AssetFolderInfo folderInfo = asset as AssetFolderInfo;

            if (fileInfo != null)
            {
                if ((_hideInvalidAsset && !fileInfo.IsValid) || (_hideBundleAsset && fileInfo.Bundled != ""))
                {
                    return;
                }
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(indentation * 20 + 5);
            if (folderInfo != null)
            {
                GUIContent content = EditorGUIUtility.IconContent("Folder Icon");
                content.text           = folderInfo.Name;
                folderInfo.IsExpanding = EditorGUILayout.Foldout(folderInfo.IsExpanding, content, true);
            }
            else
            {
                GUI.enabled = fileInfo.IsValid;
                GUI.color   = (_currentFile == fileInfo ? Color.cyan : (fileInfo.IsRedundant ? Color.red : Color.white));

                GUILayout.Space(10);
                GUIContent content = EditorGUIUtility.ObjectContent(null, fileInfo.AssetType);
                content.text = fileInfo.Name;
                if (GUILayout.Button(content, _prefabLabel, GUILayout.Height(20)))
                {
                    _currentFile = fileInfo;
                }

                if (fileInfo.Bundled != "")
                {
                    GUILayout.Label("[" + fileInfo.Bundled + "]", _prefabLabel);
                }

                GUI.color   = Color.white;
                GUI.enabled = true;

                if (fileInfo.IsRedundant)
                {
                    GUILayout.Label(_redundant, _brokenPrefabLabel, GUILayout.Height(20));
                }
            }
            _assetViewHeight += 20;
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (folderInfo != null && folderInfo.IsExpanding)
            {
                folderInfo.ReadChildAsset();
                for (int i = 0; i < folderInfo.ChildAsset.Count; i++)
                {
                    AssetGUI(folderInfo.ChildAsset[i], indentation + 1);
                }
            }
        }
        private void RedundantAssetGUI()
        {
            foreach (KeyValuePair <string, AssetFileInfo> file in AssetBundleEditorUtility.FileInfos)
            {
                if (file.Value.IsRedundant)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(5);

                    GUI.color = (_currentFile == file.Value ? Color.cyan : Color.red);

                    GUILayout.Space(10);
                    GUIContent content = EditorGUIUtility.ObjectContent(null, file.Value.AssetType);
                    content.text = file.Value.Name;
                    if (GUILayout.Button(content, _prefabLabel, GUILayout.Height(20)))
                    {
                        _currentFile = file.Value;
                    }

                    if (file.Value.Bundled != "")
                    {
                        GUILayout.Label("[" + file.Value.Bundled + "]", _prefabLabel);
                    }

                    GUI.color = Color.white;

                    GUILayout.Label(_redundant, _brokenPrefabLabel, GUILayout.Height(20));

                    _assetViewHeight += 20;
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
            }
        }
Ejemplo n.º 4
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;
        }
        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();
        }
 /// <summary>
 /// 通过路径获取资源文件对象
 /// </summary>
 public static AssetFileInfo GetFileInfoByPath(string filePath)
 {
     if (_fileInfos.ContainsKey(filePath))
     {
         return(_fileInfos[filePath]);
     }
     else
     {
         string        fullPath  = Application.dataPath + filePath.Replace("Assets", "");
         string        name      = Path.GetFileName(fullPath);
         string        extension = Path.GetExtension(fullPath);
         AssetFileInfo file      = new AssetFileInfo(fullPath, name, extension);
         _fileInfos.Add(filePath, file);
         return(file);
     }
 }
        /// <summary>
        /// 读取资源文件的依赖关系
        /// </summary>
        public static void ReadAssetDependencies(string filePath)
        {
            AssetFileInfo file = GetFileInfoByPath(filePath);

            string[] paths = AssetDatabase.GetDependencies(filePath);
            for (int i = 0; i < paths.Length; i++)
            {
                EditorUtility.DisplayProgressBar("Hold On", "Collect Dependencies[" + i + "/" + paths.Length + "]", (float)i / paths.Length);

                if (filePath != paths[i])
                {
                    file.Dependencies.Add(paths[i]);
                }
            }
            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 8
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);
             }
         });
     }
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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 = "";
        }
        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;
            }
        }
        private void AssetBundlesGUI()
        {
            _ABViewRect   = new Rect(5, 45, 240, (int)position.height / 2 - 40);
            _ABScrollRect = new Rect(5, 45, 240, _ABViewHeight);
            _ABScroll     = GUI.BeginScrollView(_ABViewRect, _ABScroll, _ABScrollRect);
            GUI.BeginGroup(_ABScrollRect, _box);

            _ABViewHeight = 5;

            for (int i = 0; i < AssetBundleEditorUtility.BundleInfosList.Count; i++)
            {
                BundleInfo bundle = AssetBundleEditorUtility.BundleInfosList[i];
                string     icon   = bundle.Count > 0 ? "Prefab Icon" : "GameObject Icon";
                if (_currentAB == bundle)
                {
                    GUI.Box(new Rect(0, _ABViewHeight, 240, 15), "", _LRSelect);

                    if (_isRename)
                    {
                        GUIContent content = EditorGUIUtility.IconContent(icon);
                        content.text = "";
                        GUI.Label(new Rect(5, _ABViewHeight, 230, 15), content, _prefabLabel);
                        _renameValue = EditorGUI.TextField(new Rect(40, _ABViewHeight, 140, 15), _renameValue);
                        if (GUI.Button(new Rect(180, _ABViewHeight, 30, 15), "OK", _miniButtonLeft))
                        {
                            if (_renameValue != "")
                            {
                                if (!AssetBundleEditorUtility.IsExistBundleInfo(_renameValue))
                                {
                                    AssetBundleEditorUtility.RenameBundleInfo(_currentAB.Name, _renameValue);
                                    _renameValue = "";
                                    _isRename    = false;
                                }
                                else
                                {
                                    GlobalTools.LogError("Already existed AssetBundle name:" + _renameValue);
                                }
                            }
                        }
                        if (GUI.Button(new Rect(210, _ABViewHeight, 30, 15), "NO", _miniButtonRight))
                        {
                            _isRename = false;
                        }
                    }
                    else
                    {
                        GUIContent content = EditorGUIUtility.IconContent(icon);
                        content.text = bundle.Name;
                        GUI.Label(new Rect(5, _ABViewHeight, 230, 15), content, _prefabLabel);
                    }
                }
                else
                {
                    GUIContent content = EditorGUIUtility.IconContent(icon);
                    content.text = bundle.Name;
                    if (GUI.Button(new Rect(5, _ABViewHeight, 230, 15), content, _prefabLabel))
                    {
                        _currentAB     = bundle;
                        _currentABFile = null;
                        _isRename      = false;
                    }
                }
                _ABViewHeight += 20;
            }

            _ABViewHeight += 5;
            if (_ABViewHeight < _ABViewRect.height)
            {
                _ABViewHeight = (int)_ABViewRect.height;
            }

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