Пример #1
0
        public static bool BuildAssetBundle(string[] assetsList, string outputPath, out uint crc, BundleType bundleType)
        {
            crc = 0;

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

            foreach (string assetPath in assetsList)
            {
                // Load all of assets in this bundle
                UnityEngine.Object[] assetsAtPath = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                if (assetsAtPath != null || assetsAtPath.Length != 0)
                {
                    List <UnityEngine.Object> filterResult = AssetFilter.FilterObjectByType(assetsAtPath, bundleType, assetPath);
                    assets.AddRange(filterResult);
                }
                else
                {
                    Debug.LogErrorFormat("Cannnot load [{0}] as asset object", assetPath);
                }
            }
            if (assets.Count == 0)
            {
                Debug.LogFormat("bundle name {0} empty", outputPath);
                return(false);
            }

            // Build bundle
            return(BuildAssetBundle(assets.ToArray(), outputPath, out crc));
        }
Пример #2
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);
        }