//判断当前资源文件夹是否被分配到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 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); } } }