Ejemplo n.º 1
0
        public IEnumerator Init()
        {
            // 加载 AssetManifest
            AssetBundleCreateRequest abReq = AssetBundle.LoadFromFileAsync(VersionManager.Instance.GetFilePath("AssetBundles", "assetmanifest"));

            yield return(abReq);

            if (abReq == null || abReq.assetBundle == null)
            {
                yield break;
            }

            AssetBundleRequest assetReq = abReq.assetBundle.LoadAssetAsync("AssetManifest.asset");

            yield return(assetReq);

            if (assetReq == null || assetReq.asset == null)
            {
                yield break;
            }

            AssetManifest am = assetReq.asset as AssetManifest;

            if (am != null)
            {
                for (int i = 0; i < am.mAssetNameList.Count; ++i)
                {
                    mAsset2BundleDict.Add(am.mAssetNameList[i], am.mAssetBundleNameList[am.mAssetBundleIndexList[i]]);
                }
            }

            mInited = true;
        }
Ejemplo n.º 2
0
        void CreateAssetManifest(string saveFolder, Dictionary <string, string> asset2BundleDict)
        {
            string[] includeExtensions = new string[] { ".prefab", ".bytes" };

            AssetManifest am = ScriptableObject.CreateInstance <AssetManifest>();

            if (am == null)
            {
                return;
            }

            foreach (var item in asset2BundleDict)
            {
                for (int i = 0; i < includeExtensions.Length; ++i)
                {
                    if (item.Key.EndsWith(includeExtensions[i]))
                    {
                        int assetBundleNameIndex = am.mAssetBundleNameList.IndexOf(item.Value);
                        if (assetBundleNameIndex < 0)
                        {
                            am.mAssetBundleNameList.Add(item.Value);
                            assetBundleNameIndex = am.mAssetBundleNameList.Count - 1;
                        }

                        am.mAssetNameList.Add(item.Key);
                        am.mAssetBundleIndexList.Add(assetBundleNameIndex);
                        break;
                    }
                }
            }

            if (Directory.Exists(saveFolder))
            {
                Directory.Delete(saveFolder, true);
            }
            Directory.CreateDirectory(saveFolder);

            string tempFile = saveFolder + "/AssetManifest.asset";

            AssetDatabase.CreateAsset(am, tempFile);
            AssetDatabase.SaveAssets();

            AssetImporter importer = AssetImporter.GetAtPath(tempFile);

            if (importer != null)
            {
                importer.SetAssetBundleNameAndVariant("AssetManifest", "");
            }
        }