public static void UpdateBundleBuildList(FilterHandler filter)
        {
            if (filter == null)
            {
                m_useFilter = false;
                return;
            }
            m_useFilter = true;
            List <BundleImportData> dataList = m_dataControl.DataList;

            for (int l = 0; l < dataList.Count; ++l)
            {
                BundleImportData data = dataList[l];
                if (data == null)
                {
                    continue;
                }
                if (EditorUtility.DisplayCancelableProgressBar("Update Bundle List", data.RootPath, (l * 1.0f) / dataList.Count))
                {
                    Debug.LogWarning("CreateBundles Stop.");
                    break;
                }
                string     parentName = BundleDataManager.GetIndexBundleName(l);
                BundleData parent     = BundleDataManager.GetBundleData(parentName);
                for (int i = 0; parent != null && i < parent.children.Count; ++i)
                {
                    _ProcessUpdateBundleList(parent.children[i], data, filter);
                }
            }
            EditorUtility.ClearProgressBar();
            _ProcessDependBundleList();
        }
Example #2
0
        public static void BuildBundles()
        {
            BundleBuildHelper.PushAssetDependencies();

            BuildSingleBundle(BundleName.BN_SCRIPT, null);

            BundleData shader = BundleDataManager.GetBundleData(BundleName.BN_SHADER);

            for (int i = 0; shader != null && i < shader.children.Count; ++i)
            {
                BundleData  shaderChild = BundleDataManager.GetBundleData(shader.children[i]);
                BundleState childState  = BundleDataManager.GetBundleState(shader.children[i]);
                bool        result      = BundleBuildHelper.BuildShaderBundle(shaderChild, childState);
                if (!result)
                {
                    Debug.LogErrorFormat("[BundleAdapter] BuildShaderBundle {0} Failed.", shader.children[i]);
                }
            }

            List <BundleImportData> dataList = m_dataControl.DataList;

            for (int i = 0; i < dataList.Count; ++i)
            {
                BundleImportData data       = dataList[i];
                string           parentName = BundleDataManager.GetIndexBundleName(i);
                BuildSingleBundle(parentName, data);
            }

            BundleBuildHelper.PopAssetDependencies();

            BundleExport.ExportBundleMainfestToOutput();

            AssetDatabase.SaveAssets();
        }
Example #3
0
        public static bool RemoveBundle(string bundleName)
        {
            BundleData bundle = GetBundleData(bundleName);

            if (bundle == null)
            {
                return(false);
            }
            BundleDataAccessor.Datas.Remove(bundle);
            m_dataDict.Remove(bundleName);
            BundleDataAccessor.States.Remove(m_stateDict[bundleName]);
            m_stateDict.Remove(bundleName);

            if (!string.IsNullOrEmpty(bundle.parent) && m_dataDict.ContainsKey(bundle.parent))
            {
                m_dataDict[bundle.parent].children.Remove(bundleName);
            }

            for (int i = 0; i < bundle.includs.Count; ++i)
            {
                string nGuid = AssetDatabase.AssetPathToGUID(bundle.includs[i]);
                m_guidToBundle.Remove(nGuid);
            }

            return(true);
        }
Example #4
0
        public static void RemovePathFromBundle(string path, string bundleName)
        {
            BundleData bundle = GetBundleData(bundleName);

            if (bundle == null)
            {
                return;
            }
            string guid = AssetDatabase.AssetPathToGUID(path);

            //string path = AssetDatabase.GUIDToAssetPath(guid);

            if (m_guidToBundle.ContainsKey(guid))
            {
                m_guidToBundle.Remove(path);
            }

            for (int i = 0; i < bundle.includs.Count; ++i)
            {
                string nGuid = AssetDatabase.AssetPathToGUID(bundle.includs[i]);
                if (nGuid == guid)
                {
                    bundle.includs.RemoveAt(i);
                    break;
                }
            }
        }
Example #5
0
        private static void BuildSingleBundle(string name, BundleImportData data)
        {
            BundleData bundle = BundleDataManager.GetBundleData(name);

            if (bundle == null)
            {
                return;
            }
            for (int i = 0; i < bundle.children.Count; ++i)
            {
                BundleData  child      = BundleDataManager.GetBundleData(bundle.children[i]);
                BundleState childState = BundleDataManager.GetBundleState(bundle.children[i]);
                if (child == null || child.includs.Count == 0 || childState == null)
                {
                    continue;
                }
                if (m_buildAll && !m_bundleDict.ContainsKey(child.name))
                {
                    continue;
                }

                bool result = BundleBuildHelper.BuildSingleBundle(child, childState, data == null ? false : data.PushDependice);
                if (!result)
                {
                    Debug.LogErrorFormat("[BundleAdapter] BuildSingleBundle {0} Failed.", child.name);
                }
            }
        }
Example #6
0
        public static bool BuildSingleBundle(BundleData bundle, BundleState state)
        {
            if (bundle == null)
            {
                return(false);
            }

            string outputPath = "";

            EditorCommon.CreateDirectory(outputPath);
            uint crc = 0;

            string[] assetPaths = bundle.includs.ToArray();

            bool succeed = false;

            if (bundle.type == BundleType.UnityMap)
            {
                succeed = BuildSceneBundle(assetPaths, outputPath, out crc);
            }
            else
            {
                succeed = BuildAssetBundle(assetPaths, outputPath, out crc, bundle.type);
            }

            succeed = UpdateBundleState(bundle, state, outputPath, succeed, crc);

            return(succeed);
        }
Example #7
0
        public static BundleData GetBundleData(string name)
        {
            BundleData ret = null;

            m_dataDict.TryGetValue(name, out ret);
            return(ret);
        }
        private static void _PreProcessSpecialBundle()
        {
            BundleData shader = BundleDataManager.GetBundleData(BundleName.BN_SHADER);

            if (shader == null)
            {
                BundleDataManager.CreateNewBundle(BundleName.BN_SHADER, "", BundleType.None, BundleLoadState.UnLoadOnUnloadAsset);
                shader = BundleDataManager.GetBundleData(BundleName.BN_SHADER);
            }
            if (shader.children.Count == 0)
            {
                string name = BundleDataManager.GenBundleNameByType(BundleType.Shader);
                BundleDataManager.CreateNewBundle(name, shader.name, BundleType.Shader, BundleLoadState.PreLoad);
            }
            _AddToDict(shader.name, m_bundleDict);

            BundleData script = BundleDataManager.GetBundleData(BundleName.BN_SCRIPT);

            if (script == null)
            {
                BundleDataManager.CreateNewBundle(BundleName.BN_SCRIPT, "", BundleType.None, BundleLoadState.UnLoadOnUnloadAsset);
                script = BundleDataManager.GetBundleData(BundleName.BN_SCRIPT);
            }

            if (script.children.Count == 0)
            {
                string name = BundleDataManager.GenBundleNameByType(BundleType.Script);
                BundleDataManager.CreateNewBundle(name, script.name, BundleType.Script, BundleLoadState.PreLoad);
            }
            _AddToDict(script.name, m_bundleDict);
        }
        private static void _ProcessUpdateBundleList(string bundleName, BundleImportData selectData, FilterHandler filter)
        {
            BundleData data = BundleDataManager.GetBundleData(bundleName);

            if (data == null)
            {
                return;
            }

            for (int i = 0; i < data.includs.Count; ++i)
            {
                if (filter == null || filter(data.includs[i]))
                {
                    _AddToDict(data.name, m_bundleDict);
                    continue;
                }
                if (!selectData.Publish)
                {
                    continue;
                }
                string[] dep = AssetDepend.GetDependenciesCache(data.includs[i]);
                for (int k = 0; k < dep.Length; ++k)
                {
                    if (!filter(dep[k]))
                    {
                        continue;
                    }
                    if (!BundleDataManager.CheckPathInBundle(dep[k]))
                    {
                        _AddToDict(data.name, m_bundleDict);
                        break;
                    }
                }
            }
        }
Example #10
0
 private static void ProcessSpecialResource(string path)
 {
     if (m_specialCache.ContainsKey(path))
     {
         return;
     }
     m_specialCache.Add(path, path);
     if (EditorPath.IsShader(path))
     {
         if (!BundleDataManager.CheckPathInBundle(path))
         {
             BundleData shader = BundleDataManager.GetBundleData(BundleName.BN_SHADER);
             if (shader != null && shader.children.Count > 0)
             {
                 BundleDataManager.AddPathToBundle(path, shader.children[0], 1024);
             }
         }
     }
     else if (EditorPath.IsMaterial(path))
     {
         BundleData shaderBundle = BundleDataManager.GetBundleData(BundleName.BN_SHADER);
         if (shaderBundle == null)
         {
             return;
         }
         UnityEngine.Object[] assetAtPath = AssetDatabase.LoadAllAssetsAtPath(path);
         foreach (var obj in assetAtPath)
         {
             if (obj != null && obj.GetType() == typeof(Material))
             {
                 Material mat = obj as Material;
                 if (mat != null && mat.shader != null && !string.IsNullOrEmpty(mat.shader.name))
                 {
                     if (!shaderBundle.includs.Contains(mat.shader.name))
                     {
                         shaderBundle.includs.Add(mat.shader.name);
                     }
                 }
             }
             if ((!(obj is GameObject)) && (!(obj is Component)))
             {
                 Resources.UnloadAsset(obj);
             }
         }
         ProcessClear();
     }
     else if (EditorPath.IsScript(path))
     {
         BundleData script = BundleDataManager.GetBundleData(BundleName.BN_SCRIPT);
         if (script != null && script.children.Count > 0)
         {
             BundleDataManager.AddPathToBundle(path, script.children[0], 1024);
         }
     }
 }
        public static bool BuildShaderBundle(BundleData bundle, BundleState state)
        {
            if (bundle == null || state == null)
            {
                return(false);
            }

            List <UnityEngine.Object> list = new List <UnityEngine.Object>();

            for (int i = 0; i < bundle.includs.Count; ++i)
            {
                string path = bundle.includs[i];
                if (path.StartsWith("Assets", StringComparison.OrdinalIgnoreCase))
                {
                    UnityEngine.Object[] assetsAtPath = AssetDatabase.LoadAllAssetsAtPath(path);
                    if (assetsAtPath != null || assetsAtPath.Length != 0)
                    {
                        list.AddRange(assetsAtPath);
                    }
                    else
                    {
                        Debug.LogError("Cannnot load [" + path + "] as asset object");
                    }
                }
                else
                {
                    UnityEngine.Object obj = Shader.Find(path);
                    if (obj == null)
                    {
                        Debug.LogError("Find shader " + path + " failed.");
                    }
                    else
                    {
                        list.Add(obj);
                    }
                }
            }

            if (list.Count == 0)
            {
                Debug.LogError("Empty Shader Bundle " + bundle.name);
                return(false);
            }

            uint   crc        = 0;
            string outputPath = BuildConfig.GetBuildOutputPath(bundle.name);

            EditorTool.CreateDirectory(outputPath);

            bool succeed = BuildAssetBundle(list.ToArray(), outputPath, out crc);

            succeed = UpdateBundleState(bundle, state, outputPath, succeed, crc);

            return(succeed);
        }
Example #12
0
 public static bool IsBundleFull(BundleData bundle, int maxCount, int memSize)
 {
     if (memSize > 0 && bundle.size > memSize)
     {
         return(true);
     }
     if (maxCount > 0 && bundle.includs.Count >= maxCount)
     {
         return(true);
     }
     return(false);
 }
Example #13
0
        public static bool BuildSingleBundle(BundleData bundle, BundleState state, bool pushDepend)
        {
            if (pushDepend)
            {
                PushAssetDependencies();
            }
            bool ret = BuildSingleBundle(bundle, state);

            if (pushDepend)
            {
                PopAssetDependencies();
            }
            return(ret);
        }
Example #14
0
        private static void ProcessUpdateBundleList(string bundleName)
        {
            BundleData data = BundleDataManager.GetBundleData(bundleName);

            if (data == null)
            {
                return;
            }

            for (int i = 0; i < data.includs.Count; ++i)
            {
                _AddToDict(data.name, m_bundleDict);
            }
        }
Example #15
0
        public static bool IsNameDuplicatedAsset(BundleData bundle, string newAsset)
        {
            string newName = Path.GetFileNameWithoutExtension(newAsset).ToUpperInvariant();

            foreach (string path in bundle.includs)
            {
                string file = Path.GetFileNameWithoutExtension(path).ToUpperInvariant();
                if (file == newName)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #16
0
        public static bool AddPathToBundle(string path, string bundleName, long size)
        {
            if (!CanAddPathToBundle(path, bundleName))
            {
                return(false);
            }

            BundleData bundle = m_dataDict[bundleName];
            string     guid   = AssetDatabase.AssetPathToGUID(path);

            bundle.includs.Add(path);
            m_guidToBundle.Add(guid, bundleName);
            bundle.size += size;

            return(true);
        }
Example #17
0
        private static void _ProcessDependBundleList()
        {
            bool loop = true;

            while (loop)
            {
                loop = false;
                List <string> list = new List <string>(m_bundleDict.Keys);
                for (int i = 0; i < list.Count; ++i)
                {
                    bool isProcess = false;

                    if (!m_bundleDict.TryGetValue(list[i], out isProcess))
                    {
                        continue;
                    }
                    if (isProcess)
                    {
                        continue;
                    }

                    m_bundleDict[list[i]] = true;
                    loop = true;

                    BundleData data = BundleDataManager.GetBundleData(list[i]);
                    if (data == null)
                    {
                        continue;
                    }
                    for (int j = 0; j < data.includs.Count; ++j)
                    {
                        string[] dep = AssetDepend.GetDependenciesCache(data.includs[j]);
                        for (int k = 0; k < dep.Length; ++k)
                        {
                            string bundleName = BundleDataManager.GetPathBundleName(dep[k]);
                            if (!string.IsNullOrEmpty(bundleName))
                            {
                                _AddToDict(bundleName, m_bundleDict);
                            }
                        }
                    }
                }
            }
        }
Example #18
0
        public static List <object> GetIndexBundleList(int index)
        {
            List <object> list             = new List <object>();
            string        parentBundleName = GetIndexBundleName(index);
            BundleData    bundleData       = GetBundleData(parentBundleName);

            if (bundleData == null)
            {
                return(list);
            }
            for (int i = 0; i < bundleData.children.Count; ++i)
            {
                BundleData child = GetBundleData(bundleData.children[i]);
                if (child != null)
                {
                    list.Add(child);
                }
            }
            return(list);
        }
Example #19
0
        private static bool UpdateBundleState(BundleData bundle, BundleState state, string outputPath, bool succeed, uint crc)
        {
            if (!succeed || (crc == state.crc && state.size > 0))
            {
                return(succeed);
            }

            state.version++;
            if (state.version == int.MaxValue)
            {
                state.version = 0;
            }
            state.crc = crc;
            FileInfo bundleFileInfo = new FileInfo(outputPath);

            state.size      = bundleFileInfo.Length;
            state.loadState = bundle.loadState;
            state.storePos  = BundleStorePos.Building;

            return(succeed);
        }
Example #20
0
        public static bool CreateNewBundle(string name, string parent, BundleType type, BundleLoadState loadState)
        {
            if (m_dataDict.ContainsKey(name))
            {
                return(false);
            }

            BundleData newBundle = new BundleData();

            newBundle.name      = name;
            newBundle.type      = type;
            newBundle.loadState = loadState;

            if (!string.IsNullOrEmpty(parent))
            {
                if (m_dataDict.ContainsKey(parent))
                {
                    return(false);
                }
                else
                {
                    m_dataDict[parent].children.Add(name);
                }

                newBundle.parent = parent;
            }

            m_dataDict.Add(name, newBundle);
            BMDataAccessor.Datas.Add(newBundle);

            BundleState newState = new BundleState();

            newState.bundleID = name;
            newState.version  = 1;
            m_stateDict.Add(name, newState);
            BMDataAccessor.States.Add(newState);

            return(true);
        }
        public void OnBundleSelected(object selected, int col)
        {
            BundleData bundleData = selected as BundleData;

            if (bundleData == null)
            {
                return;
            }

            if (m_assetTable != null)
            {
                List <object> list = new List <object>();
                for (int i = 0; i < bundleData.includs.Count; ++i)
                {
                    AssetPathInfo pathInfo = AssetPathInfo.CreatePathInfo(bundleData.includs[i]);
                    if (pathInfo != null)
                    {
                        list.Add(pathInfo);
                    }
                }
                m_assetTable.RefreshData(list);
            }
        }
Example #22
0
        public static bool SetParent(string child, string newParent)
        {
            if (!CanBundleParentTo(child, newParent))
            {
                return(false);
            }

            BundleData childBundle = m_dataDict[child];

            if (m_dataDict.ContainsKey(childBundle.parent))
            {
                m_dataDict[childBundle.parent].children.Remove(child);
            }
            childBundle.parent = newParent;

            if (!string.IsNullOrEmpty(newParent))
            {
                BundleData newParentBundle = m_dataDict[newParent];
                newParentBundle.children.Add(child);
                newParentBundle.children.Sort();
            }

            return(true);
        }
Example #23
0
        private static void _BuildSingleBundle(string name, BundleImportData data)
        {
            BundleData bundle = BundleDataManager.GetBundleData(name);

            if (bundle == null)
            {
                return;
            }
            for (int i = 0; i < bundle.children.Count; ++i)
            {
                BundleData  child      = BundleDataManager.GetBundleData(bundle.children[i]);
                BundleState childState = BundleDataManager.GetBundleState(bundle.children[i]);
                if (child == null || child.includs.Count == 0 || childState == null)
                {
                    continue;
                }
                if (m_useFilter && !m_bundleDict.ContainsKey(child.name))
                {
                    continue;
                }

                BuildHelper.BuildSingleBundle(child, childState, data.PushDependice);
            }
        }
Example #24
0
        private static void _AddPathToBundleByPathConfig(BundleImportData data, string path)
        {
            if (data == null || string.IsNullOrEmpty(path) || BundleDataManager.CheckPathInBundle(path))
            {
                return;
            }

            string parentName = BundleDataManager.GetIndexBundleName(data.Index);

            if (data.Type == BundleType.Shader)
            {
                parentName = BundleName.BN_SHADER;
            }
            string bundleName = BundleDataManager.GetPathBundleName(path);

            if (!string.IsNullOrEmpty(bundleName))
            {
                BundleData bundleData = BundleDataManager.GetBundleData(bundleName);
                if (bundleData.parent == parentName)
                {
                    return;
                }
                else
                {
                    BundleDataManager.RemovePathFromBundle(path, bundleName);
                }
            }

            _AddToDict(bundleName, m_bundleDict);

            BundleData parent = BundleDataManager.GetBundleData(parentName);

            if (parent == null)
            {
                BundleDataManager.CreateNewBundle(parentName, "", BundleType.None, BundleLoadState.UnLoadOnUnloadAsset);
                parent = BundleDataManager.GetBundleData(parentName);
            }

            string name = "";

            for (int i = 0; i < parent.children.Count; ++i)
            {
                int        index = parent.children.Count - i - 1;
                BundleData child = BundleDataManager.GetBundleData(parent.children[index]);

                if (BundleDataManager.IsBundleFull(child, data.LimitCount, data.LimitKBSize * 1024))
                {
                    continue;
                }

                if (data.Publish && BundleDataManager.IsNameDuplicatedAsset(child, path))
                {
                    continue;
                }

                name = child.name;
                break;
            }

            if (string.IsNullOrEmpty(name))
            {
                name = BundleDataManager.GenBundleNameByType(data.Type);
                BundleDataManager.CreateNewBundle(name, parent.name, data.Type, data.LoadState);
            }

            long size = CalcPathFileSize(path, data.Type);

            BundleDataManager.AddPathToBundle(path, name, size);
            _AddToDict(name, m_bundleDict);
        }