//判断当前资源文件夹是否被分配到Bundle中 private bool IsAssignedSourceFolder(SourceFolder sourceFolder) { if (m_CachedAssignedSourceFolders.Contains(sourceFolder)) { return(true); } if (m_CachedUnassignedSourceFolders.Contains(sourceFolder)) { return(false); } foreach (SourceAsset sourceAsset in sourceFolder.GetAssets()) { if (!IsAssignedSourceAsset(sourceAsset)) { m_CachedUnassignedSourceFolders.Add(sourceFolder); return(false); } } foreach (SourceFolder subSourceFolder in sourceFolder.GetFolders()) { if (!IsAssignedSourceFolder(subSourceFolder)) { m_CachedUnassignedSourceFolders.Add(sourceFolder); return(false); } } m_CachedAssignedSourceFolders.Add(sourceFolder); return(true); }
//修改资源的选中状态 private void SetSelectedSourceAsset(SourceAsset sourceAsset, bool select) { if (select) { m_SelectedSourceAssets.Add(sourceAsset); SourceFolder folder = sourceAsset.Folder; while (folder != null) { m_CachedUnselectedSourceFolders.Remove(folder); folder = folder.Folder; } } else { m_SelectedSourceAssets.Remove(sourceAsset); SourceFolder folder = sourceAsset.Folder; while (folder != null) { m_CachedSelectedSourceFolders.Remove(folder); folder = folder.Folder; } } }
private readonly List <SourceAsset> m_Assets; //文件列表 public SourceFolder(string name, SourceFolder folder) { m_Folders = new List <SourceFolder>(); m_Assets = new List <SourceAsset>(); Name = name; Folder = folder; }
private void SetExpandedSourceFolder(SourceFolder sourceFolder, bool expand) { if (expand) { m_ExpandedSourceFolders.Add(sourceFolder); } else { m_ExpandedSourceFolders.Remove(sourceFolder); } }
public SourceAsset(string guid, string path, string name, SourceFolder folder) { if (folder == null) { throw new GameFrameworkException("Source asset folder is invalid."); } Guid = guid; Path = path; Name = name; Folder = folder; m_CachedIcon = null; }
//修改资源文件夹选中状态 private void SetSelectedSourceFolder(SourceFolder sourceFolder, bool select) { if (select) { m_CachedSelectedSourceFolders.Add(sourceFolder); m_CachedUnselectedSourceFolders.Remove(sourceFolder); SourceFolder folder = sourceFolder; while (folder != null) { m_CachedUnselectedSourceFolders.Remove(folder); folder = folder.Folder; } } else { m_CachedSelectedSourceFolders.Remove(sourceFolder); m_CachedUnselectedSourceFolders.Add(sourceFolder); SourceFolder folder = sourceFolder; while (folder != null) { m_CachedSelectedSourceFolders.Remove(folder); folder = folder.Folder; } } foreach (SourceAsset sourceAsset in sourceFolder.GetAssets()) { if (m_HideAssignedSourceAssets && IsAssignedSourceAsset(sourceAsset)) { continue; } SetSelectedSourceAsset(sourceAsset, select); } foreach (SourceFolder subSourceFolder in sourceFolder.GetFolders()) { if (m_HideAssignedSourceAssets && IsAssignedSourceFolder(subSourceFolder)) { continue; } SetSelectedSourceFolder(subSourceFolder, select); } }
//绘制资源文件夹 private void DrawSourceFolder(SourceFolder sourceFolder) { if (m_HideAssignedSourceAssets && IsAssignedSourceFolder(sourceFolder)) { return; } bool expand = IsExpandedSourceFolder(sourceFolder); //是否展开了文件夹 EditorGUILayout.BeginHorizontal(); { bool select = IsSelectedSourceFolder(sourceFolder); if (select != EditorGUILayout.Toggle(select, GUILayout.Width(12f + 14f * sourceFolder.Depth))) { select = !select; SetSelectedSourceFolder(sourceFolder, select); } GUILayout.Space(-14f * sourceFolder.Depth); if (expand != EditorGUI.Foldout(new Rect(18f + 14f * sourceFolder.Depth, 20f * m_CurrentSourceRowOnDraw + 2f, int.MaxValue, 14f), expand, string.Empty, true)) { expand = !expand; SetExpandedSourceFolder(sourceFolder, expand); } GUI.DrawTexture(new Rect(32f + 14f * sourceFolder.Depth, 20f * m_CurrentSourceRowOnDraw + 1f, 16f, 16f), SourceFolder.Icon); EditorGUILayout.LabelField(string.Empty, GUILayout.Width(26f + 14f * sourceFolder.Depth), GUILayout.Height(18f)); EditorGUILayout.LabelField(sourceFolder.Name); } EditorGUILayout.EndHorizontal(); m_CurrentSourceRowOnDraw++; if (expand) { foreach (SourceFolder subSourceFolder in sourceFolder.GetFolders()) { DrawSourceFolder(subSourceFolder); } foreach (SourceAsset sourceAsset in sourceFolder.GetAssets()) { DrawSourceAsset(sourceAsset); } } }
//添加文件夹 public SourceFolder AddFolder(string name) { if (string.IsNullOrEmpty(name)) { throw new GameFrameworkException("Source folder name is invalid."); } SourceFolder folder = GetFolder(name); if (folder != null) { throw new GameFrameworkException("Source folder is already exist."); } folder = new SourceFolder(name, this); m_Folders.Add(folder); return(folder); }
private void OnAssetAssigned(SourceAsset[] sourceAssets) { HashSet <SourceFolder> affectedFolders = new HashSet <SourceFolder>(); foreach (SourceAsset sourceAsset in sourceAssets) { m_CachedAssignedSourceAssets.Add(sourceAsset); m_CachedUnassignedSourceAssets.Remove(sourceAsset); affectedFolders.Add(sourceAsset.Folder); } foreach (SourceFolder sourceFolder in affectedFolders) { SourceFolder folder = sourceFolder; while (folder != null) { m_CachedUnassignedSourceFolders.Remove(folder); folder = folder.Folder; } } }
//搜索资源 public void ScanSourceAssets() { m_SourceAssets.Clear(); SourceAssetRoot.Clear(); string[] sourceAssetSearchPaths = m_SourceAssetSearchPaths.ToArray(); HashSet <string> tempGuids = new HashSet <string>(); tempGuids.UnionWith(AssetDatabase.FindAssets(m_SourceAssetUnionTypeFilter, sourceAssetSearchPaths)); //并集运算 tempGuids.UnionWith(AssetDatabase.FindAssets(m_SourceAssetUnionLabelFilter, sourceAssetSearchPaths)); //并集运算 tempGuids.ExceptWith(AssetDatabase.FindAssets(m_SourceAssetExceptTypeFilter, sourceAssetSearchPaths)); //排除运算 tempGuids.ExceptWith(AssetDatabase.FindAssets(m_SourceAssetExceptLabelFilter, sourceAssetSearchPaths)); //排除运算 string[] assetGuids = new List <string>(tempGuids).ToArray(); foreach (string assetGuid in assetGuids) { string fullPath = AssetDatabase.GUIDToAssetPath(assetGuid); if (AssetDatabase.IsValidFolder(fullPath)) { // Skip folder. continue; } string assetPath = fullPath.Substring(SourceAssetRootPath.Length + 1); string[] splitPath = assetPath.Split('/'); SourceFolder folder = SourceAssetRoot; for (int i = 0; i < splitPath.Length - 1; i++) { SourceFolder subFolder = folder.GetFolder(splitPath[i]); folder = subFolder == null?folder.AddFolder(splitPath[i]) : subFolder; } SourceAsset asset = folder.AddAsset(assetGuid, fullPath, splitPath[splitPath.Length - 1]); m_SourceAssets.Add(asset.Guid, asset); } }
private bool IsExpandedSourceFolder(SourceFolder sourceFolder) { return(m_ExpandedSourceFolders.Contains(sourceFolder)); }