public bool UnassignAsset(string assetGuid)
        {
            if (m_AssetBundleCollection.UnassignAsset(assetGuid))
            {
                SourceAsset sourceAsset = GetSourceAsset(assetGuid);
                if (sourceAsset != null)
                {
                    if (OnAssetUnassigned != null)
                    {
                        OnAssetUnassigned(new SourceAsset[] { sourceAsset });
                    }
                }

                return(true);
            }

            return(false);
        }
        public bool RemoveAssetBundle(string assetBundleName, string assetBundleVariant)
        {
            Asset[] assetsToRemove = m_AssetBundleCollection.GetAssets(assetBundleName, assetBundleVariant);
            if (m_AssetBundleCollection.RemoveAssetBundle(assetBundleName, assetBundleVariant))
            {
                List <SourceAsset> unassignedSourceAssets = new List <SourceAsset>();
                foreach (Asset asset in assetsToRemove)
                {
                    SourceAsset sourceAsset = GetSourceAsset(asset.Guid);
                    if (sourceAsset != null)
                    {
                        unassignedSourceAssets.Add(sourceAsset);
                    }
                }

                OnAssetUnassigned?.Invoke(unassignedSourceAssets.ToArray());
                return(true);
            }

            return(false);
        }
        private int AssetGuidComparer(Asset a, Asset 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);
        }
示例#4
0
 public void GetAssetBundleName(SourceAsset source, ref string AssetBundleName, ref string assetBundleVariant)
 {
     string[] folder = source.Folder.FromRootPath.Split('/');
     if (folder[0].CompareTo("LuaScripts") == 0)
     {
         AssetBundleName = GameFramework.Utility.Path.GetCombinePath(source.Folder.FromRootPath, "_") + ".folder";//按目录分类
     }
     else if (folder[0].CompareTo("UI") == 0)
     {
         string   Extension       = Path.GetExtension(source.FromRootPath);
         int      dotIndex        = source.FromRootPath.IndexOf('.');
         string   assetBundleName = dotIndex > 0 ? source.FromRootPath.Substring(0, dotIndex) : source.FromRootPath;
         string[] names           = assetBundleName.Split('@');
         AssetBundleName = names[0] + Extension;
     }
     else if (folder[0].CompareTo("Models") == 0)
     {
         string Extension = Path.GetExtension(source.FromRootPath);
         if (Extension.ToLower().CompareTo(".fbx") == 0 || Extension.ToLower().CompareTo(".mat") == 0)
         {
             int count = GetRef(source.Path);
             if (count > 1)
             {
                 int      dotIndex        = source.FromRootPath.IndexOf('.');
                 string   assetBundleName = dotIndex > 0 ? source.FromRootPath.Substring(0, dotIndex) : source.FromRootPath;
                 string[] names           = assetBundleName.Split('@');
                 AssetBundleName = names[0] + Extension;
             }
             else
             {
                 AssetBundleName = null;
             }
         }
         else if (Extension.ToLower().CompareTo(".prefab") != 0)
         {
             AssetBundleName = null;
         }
     }
 }
示例#5
0
        private void DrawAssetBundleView()
        {
            m_AssetBundleViewScroll = EditorGUILayout.BeginScrollView(m_AssetBundleViewScroll);
            {
                if (m_SelectedAssetBundle != null)
                {
                    int     index  = 0;
                    Asset[] assets = m_Controller.GetAssets(m_SelectedAssetBundle.Name, m_SelectedAssetBundle.Variant);
                    m_CurrentAssetBundleContentCount = assets.Length;
                    foreach (Asset asset in assets)
                    {
                        SourceAsset sourceAsset = m_Controller.GetSourceAsset(asset.Guid);
                        string      assetName   = sourceAsset != null ? (m_Controller.AssetSorter == AssetSorterType.Path ? sourceAsset.Path : (m_Controller.AssetSorter == AssetSorterType.Name ? sourceAsset.Name : sourceAsset.Guid)) : asset.Guid;
                        EditorGUILayout.BeginHorizontal();
                        {
                            float emptySpace = position.width;
                            bool  select     = IsSelectedAssetInSelectedAssetBundle(asset);
                            if (select != EditorGUILayout.Toggle(select, GUILayout.Width(emptySpace - 12f)))
                            {
                                select = !select;
                                SetSelectedAssetInSelectedAssetBundle(asset, 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();
            m_SourceAssetRoot.Clear();

            string[]         sourceAssetSearchPaths = m_SourceAssetSearchPaths.ToArray();
            HashSet <string> tempGuids = new HashSet <string>();

            tempGuids.UnionWith(AssetDatabase.FindAssets(SourceAssetUnionTypeFilter, sourceAssetSearchPaths));
            tempGuids.UnionWith(AssetDatabase.FindAssets(SourceAssetUnionLabelFilter, sourceAssetSearchPaths));
            tempGuids.ExceptWith(AssetDatabase.FindAssets(SourceAssetExceptTypeFilter, sourceAssetSearchPaths));
            tempGuids.ExceptWith(AssetDatabase.FindAssets(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    = m_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);
            }
        }
示例#7
0
 private bool IsSelectedSourceAsset(SourceAsset sourceAsset)
 {
     return(m_SelectedSourceAssets.Contains(sourceAsset));
 }