예제 #1
0
        public bool IsMatch(string path)
        {
            int index = path.IndexOf(BuildConfig.ResourceRootPath);

            if (index != -1)
            {
                path = path.Substring(index + BuildConfig.ResourceRootPath.Length);
            }
            string packagePath = EditorPath.NormalizePathSplash(path);

            if (packagePath.StartsWith("/"))
            {
                packagePath = packagePath.Substring(1);
            }

            string formatPath = EditorPath.NormalizePathSplash(RootPath);

            if (!string.IsNullOrEmpty(formatPath) &&
                !packagePath.StartsWith(formatPath, System.StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            EditorRegex regex = EditorRegex.Create(FileNameMatch);

            return(regex == null ? false : regex.IsMatch(packagePath));
        }
예제 #2
0
        public BundleImportData GetPathImportData(string path)
        {
            path = EditorPath.FormatAssetPath(path);
            path = EditorPath.NormalizePathSplash(path);
            AssetPathInfo pathInfo = AssetPathInfo.CreatePathInfo(path);

            if (pathInfo == null)
            {
                return(null);
            }

            if (pathInfo.Index >= 0 && pathInfo.Index < m_dataList.Count)
            {
                return(m_dataList[pathInfo.Index]);
            }
            for (int i = m_dataList.Count - 1; i >= 0; --i)
            {
                if (m_dataList[i].IsMatch(path))
                {
                    return(m_dataList[i]);
                }
            }
            return(null);
        }
예제 #3
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);
        }
예제 #4
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);
        }