//取消分配资源
        public bool UnassignAssetInfo(string assetGuid)
        {
            if (m_AssetBundleCollection.UnassignAssetInfo(assetGuid))
            {
                SourceAsset sourceAsset = GetSourceAsset(assetGuid);
                if (sourceAsset != null)
                {
                    if (EventOnAssetUnassigned != null)
                    {
                        EventOnAssetUnassigned.Invoke(new SourceAsset[] { sourceAsset });
                    }
                }

                return(true);
            }

            return(false);
        }
        private int AssetGuidComparer(AssetInfo a, AssetInfo b)
        {
            SourceAsset sourceAssetA = GetSourceAsset(a.Guid);
            SourceAsset sourceAssetB = GetSourceAsset(b.Guid);

            if (sourceAssetA != null && sourceAssetB != null || sourceAssetA == null && sourceAssetB == null)
            {
                return(a.Guid.CompareTo(b.Guid));
            }

            if (sourceAssetA == null)
            {
                return(-1);
            }

            if (sourceAssetB == null)
            {
                return(1);
            }

            return(0);
        }
Пример #3
0
        //绘制Bundle视图
        private void DrawAssetBundleAssetsView()
        {
            m_AssetBundleViewScroll = EditorGUILayout.BeginScrollView(m_AssetBundleViewScroll);
            {
                if (m_SelectedAssetBundleInfo != null)
                {
                    int         index      = 0;
                    AssetInfo[] assetInfos = m_Controller.GetAssetInfos(m_SelectedAssetBundleInfo.Name, m_SelectedAssetBundleInfo.Variant); //BundleInfo包含的资源信息
                    m_CurrentAssetBundleContentCount = assetInfos.Length;                                                                   //缓存资源数量
                    foreach (AssetInfo assetInfo in assetInfos)
                    {
                        SourceAsset sourceAsset = m_Controller.GetSourceAsset(assetInfo.Guid);  //获取资源文件
                        string      assetName   = sourceAsset != null ? (m_Controller.AssetSorter == AssetSorterType.Path ? sourceAsset.Path : (m_Controller.AssetSorter == AssetSorterType.Name ? sourceAsset.Name : sourceAsset.Guid)) : assetInfo.Guid;
                        EditorGUILayout.BeginHorizontal();
                        {
                            float emptySpace = position.width;
                            bool  select     = IsSelectedAssetInSelectedAssetBundle(assetInfo);
                            if (select != EditorGUILayout.Toggle(select, GUILayout.Width(emptySpace - 12f)))
                            {
                                select = !select;
                                SetSelectedAssetInSelectedAssetBundle(assetInfo, select);   //修改选中状态
                            }

                            GUILayout.Space(-emptySpace + 24f);
                            GUI.DrawTexture(new Rect(20f, 20f * (index++) + 1f, 16f, 16f), (sourceAsset != null ? sourceAsset.Icon : m_MissingSourceAssetIcon));
                            EditorGUILayout.LabelField(string.Empty, GUILayout.Width(14f), GUILayout.Height(18f));
                            EditorGUILayout.LabelField(assetName);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                else
                {
                    m_CurrentAssetBundleContentCount = 0;
                }
            }
            EditorGUILayout.EndScrollView();
        }
        //搜索资源
        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);
            }
        }
Пример #5
0
 private bool IsSelectedSourceAsset(SourceAsset sourceAsset)
 {
     return(m_SelectedSourceAssets.Contains(sourceAsset));
 }