示例#1
0
        public static void CreateBundles()
        {
            PreProcessSpecialBundle();

            List <string> list = m_dataControl.GetPublishPackagePath();

            for (int i = 0; i < list.Count; ++i)
            {
                string name = Path.GetFileName(list[i]);
                if (EditorUtility.DisplayCancelableProgressBar("Create Bundle", name, (i * 1.0f) / list.Count))
                {
                    Debug.LogWarning("[BundleAdapter] CreateBundles Stop.");
                    break;
                }
                string[] dep = AssetDepot.GetDependenciesCache(list[i]);
                for (int j = 0; j < dep.Length; ++j)
                {
                    if (string.IsNullOrEmpty(dep[j]))
                    {
                        continue;
                    }
                    ProcessSpecialResource(dep[j]);
                    BundleImportData data = m_dataControl.GetPathImportData(dep[j]);
                    if (data != null && !data.SkipData)
                    {
                        _AddPathToBundleByImportData(data, dep[j]);
                    }
                }
            }
            EditorUtility.ClearProgressBar();

            BundleDataAccessor.SaveData();
            AssetDatabase.SaveAssets();
        }
示例#2
0
 public static void RefreshData()
 {
     m_dataControl.RefreshBaseData();
     m_bundleDict.Clear();
     m_specialCache.Clear();
     AssetSize.Clear();
     AssetDepot.Clear();
 }
示例#3
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) || 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 = AssetDepot.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);
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        public static long CalcAssetSize(string assetPath, BundleType type)
        {
            assetPath = EditorPath.FormatAssetPath(assetPath);
            assetPath = EditorPath.NormalizePathSplash(assetPath);

            long ret = 0;

            if (m_pathFileSize.TryGetValue(assetPath, out ret))
            {
                return(ret);
            }

            BundleImportData assetImportData = BundleDataControl.Instance.GetPathImportData(assetPath);

            UnityEngine.Object[] assets = null;

            switch (type)
            {
            case BundleType.Texture:
                assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                for (int i = 0; i < assets.Length; ++i)
                {
                    if (assets[i] is Texture)
                    {
                        ret += EditorTool.GetRuntimeMemorySize(assets[i]);
                    }
                }

                break;

            case BundleType.Material:
                string[] deps = AssetDepot.GetDependenciesCache(assetPath);
                for (int i = 0; i < deps.Length; ++i)
                {
                    if (EditorPath.IsTexture(deps[i]))
                    {
                        BundleImportData data = BundleDataControl.Instance.GetPathImportData(deps[i]);
                        if (assetImportData == null || data == null || assetImportData.Index < data.Index || data.SkipData)
                        {
                            ret += EditorTool.CalculateTextureSizeBytes(deps[i]);
                        }
                    }
                }
                ret += 512;
                break;

            case BundleType.FBX:
            case BundleType.Controller:
            case BundleType.Animation:
                assets = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                List <UnityEngine.Object> list = AssetFilter.FilterObjectByType(assets, type, assetPath);
                for (int i = 0; i < list.Count; ++i)
                {
                    ret += EditorTool.GetRuntimeMemorySize(list[i]);
                }
                break;

            default:
                FileInfo fileInfo = new FileInfo(assetPath);
                ret = fileInfo.Length;
                break;
            }

            for (int i = 0; assets != null && i < assets.Length; ++i)
            {
                if ((!(assets[i] is GameObject)) && (!(assets[i] is Component)))
                {
                    Resources.UnloadAsset(assets[i]);
                }
            }

            m_pathFileSize.Add(assetPath, ret);
            return(ret);
        }
示例#5
0
        public static void ExportBundleDictToOutput()
        {
            EditorTool.CreateDirectory(BuildConfig.InterpretedOutputPath);

            BundleDataControl dataControl    = BundleDataControl.Instance;
            BundleMainfest    bundleMainfest = new BundleMainfest();

            BundleData[] bundleData = BundleDataAccessor.Datas.ToArray();

            Dictionary <string, string> dict = new Dictionary <string, string>();

            for (int i = 0; i < bundleData.Length; ++i)
            {
                for (int j = 0; j < bundleData[i].includs.Count; ++j)
                {
                    string path = bundleData[i].includs[j];
                    if (string.IsNullOrEmpty(path))
                    {
                        continue;
                    }

                    if (!dict.ContainsKey(path))
                    {
                        dict.Add(path, bundleData[i].name);
                    }
                    else
                    {
                        Debug.LogWarningFormat("[BundleExport] Path to bundle name have same path {0} : {1} _ {2}", path, bundleData[i].name, dict[path]);
                    }

                    BundleImportData data = dataControl.GetPathImportData(path);
                    if (data == null || !data.Publish || !path.StartsWith("Assets", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    string bundlePath = path; // format path to load path!!!
                    bundleMainfest.AddPathToBundle(bundlePath, bundleData[i].name);
                }
            }

            for (int i = 0; i < bundleData.Length; ++i)
            {
                for (int j = 0; j < bundleData[i].includs.Count; ++j)
                {
                    string[] dep = AssetDepot.GetDependenciesCache(bundleData[i].includs[j]);
                    for (int k = 0; k < dep.Length; ++k)
                    {
                        if (EditorPath.IsScript(dep[k]) || EditorPath.IsShader(dep[k]))
                        {
                            continue;
                        }

                        string bundleName = null;
                        dict.TryGetValue(EditorPath.NormalizePathSplash(dep[k]), out bundleName);
                        if (string.IsNullOrEmpty(bundleName) || bundleName == bundleData[i].name)
                        {
                            continue;
                        }

                        BundleState childBuildState = BundleDataManager.GetBundleState(bundleName);
                        if (childBuildState.loadState == BundleLoadState.Preload || childBuildState.size == -1)
                        {
                            continue;
                        }

                        bundleMainfest.AddBundleDepend(bundleData[i].name, bundleName);
                    }
                }
            }

            List <BundleState> stateList = new List <BundleState>(BundleDataAccessor.States);

            bundleMainfest.AddBundleState(stateList);

            bundleMainfest.SaveBytes(BuildConfig.BundleMainfestOutputPath);

            AssetDatabase.ImportAsset(BuildConfig.BundleMainfestOutputPath, ImportAssetOptions.ForceSynchronousImport);
        }