示例#1
0
        private static void SetDepInfoAB(AssetsInfo info)
        {
            var abConfig = ABConfig.Instance;

            if (info.type == AssetsType.Shader)
            {
                SetAB(info.path, abConfig.ab_prefix_shader);
            }
            else
            {
                if (info.refCount > 1)
                {
                    info.size = ABHelper.GetAssetSize(info.path);
                    var abName = ABConfig.GetDepNeedSetABName(info);
                    if (!string.IsNullOrEmpty(abName))
                    {
                        SetDepAB(info.path, abName);
                    }
                }
                else
                {
                    if (info.category == AssetsCategory.Scene)
                    {
                        if (info.type == AssetsType.Texture || info.type == AssetsType.Asset)
                        {
                            var abName = info.GetFirstRefAB();
                            SetDepAB(info.path, ABConfig.GetABNameWithDepSuffix(abName));
                        }
                    }
                }
            }
        }
示例#2
0
        public static List <AssetsInfo> GetDepList(Dictionary <string, List <string> > depDic)
        {
            var infoDic = new Dictionary <string, AssetsInfo>();

            foreach (var kv in depDic)
            {
                var abName = kv.Key;
                foreach (var depPath in kv.Value)
                {
                    var extension = Path.GetExtension(depPath).ToLower();
                    var category  = ABConfig.GetDepCategory(depPath);
                    var type      = ABConfig.GetAssetType(extension);
                    if (!ABConfig.IsValidDep(category, type))
                    {
                        continue;
                    }
                    if (!infoDic.ContainsKey(depPath))
                    {
                        infoDic[depPath] = new AssetsInfo()
                        {
                            path      = depPath,
                            category  = category,
                            type      = type,
                            name      = Path.GetFileNameWithoutExtension(depPath),
                            extension = extension,
                            abName    = GetABName(depPath),
                            size      = 0,
                        };
                    }
                    infoDic[depPath].AddRefAB(abName);
                }
            }
            return(infoDic.Values.ToList());
        }
示例#3
0
        private static void SetScenePrefabABName(ref List <AssetsInfo> depList)
        {
            var targetList = new List <AssetsInfo>();

            for (int i = depList.Count - 1; i >= 0; i--)
            {
                var info = depList[i];
                if (info.category != AssetsCategory.Model && info.category != AssetsCategory.UI &&
                    info.refCount > 1 &&
                    string.IsNullOrEmpty(info.abName) &&
                    info.extension.Equals(".prefab"))
                {
                    targetList.Add(info);
                    SetDepAB(info.path, ABConfig.GetSceneDepPrefabABName(info.name));
                    depList.Remove(info);
                }
            }
            var list = ABHelper.GetDepList(ABHelper.GetDependencies(targetList));

            foreach (var info in list)
            {
                if (info.type != AssetsType.Shader)
                {
                    var abName = info.GetFirstRefAB();
                    SetDepAB(info.path, ABConfig.GetSceneDepPrefabABName(abName));
                }
            }
        }
        /// <summary>
        /// 场景材质球和它关联的贴图一起打AB,如果贴图依赖大于1时,贴图单独打
        /// </summary>
        /// <param name="depList"></param>
        private static void SetSceneMaterialABName(ref List <AssetsInfo> depList)
        {
            var targetList = new List <AssetsInfo>();

            for (int i = depList.Count - 1; i >= 0; i--)
            {
                var info = depList[i];
                if (info.type == AssetsType.Material &&
                    info.category != AssetsCategory.Model && info.category != AssetsCategory.UI &&
                    string.IsNullOrEmpty(info.abName))
                {
                    targetList.Add(info);
                    SetAB(info.path, ABConfig.GetSceneDepMaterialABName(info.name));
                    depList.Remove(info);
                }
            }
            var list = ABHelper.GetDepList(ABHelper.GetDependencies(targetList));

            foreach (var info in list)
            {
                if (info.type != AssetsType.Shader)
                {
                    if (info.refCount > 1)
                    {
                        SetABIfEmpty(info.path, info.name.ToLower());
                    }
                    else
                    {
                        var abName = info.GetFirstRefAB();
                        SetABIfEmpty(info.path, ABConfig.GetSceneDepMaterialABName(abName));
                    }
                }
            }
        }
示例#5
0
        public static bool ClearDepAB(string path)
        {
            var import = AssetImporter.GetAtPath(path);

            if (import && string.IsNullOrEmpty(import.assetBundleName) && ABConfig.IsDepABName(import.assetBundleName))
            {
                import.assetBundleName = null;
                return(true);
            }
            return(false);
        }
示例#6
0
 public static void AutoSetABName()
 {
     if (Selection.objects.Length == 0)
     {
         Debug.LogWarning("need selected a asset.");
         return;
     }
     foreach (var obj in Selection.objects)
     {
         if (EditorUtility.IsPersistent(obj) && !obj.GetType().ToString().Equals("UnityEditor.DefaultAsset"))
         {
             var path   = AssetDatabase.GetAssetPath(obj);
             var abName = ABConfig.GetDefaultABName(path);
             SetAB(path, abName);
             Debug.Log(string.Format("AutoSetABName:path={0},abName={1}", path, abName));
         }
     }
 }
示例#7
0
        public static bool ClearAllDepABName(bool refreshAndSaveAssets)
        {
            var needRefresh = false;

            foreach (var abName in AssetDatabase.GetAllAssetBundleNames())
            {
                if (ABConfig.IsDepABName(abName))
                {
                    foreach (var path in AssetDatabase.GetAssetPathsFromAssetBundle(abName))
                    {
                        needRefresh |= ClearAB(path);
                    }
                    AssetDatabase.RemoveAssetBundleName(abName, true);
                }
            }
            if (needRefresh && refreshAndSaveAssets)
            {
                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();
            }
            return(true);
        }