void GenerateSharedAssetGroups(Dictionary <string, List <string> > sharedAssets, ref Dictionary <string, AssetFileGroup> sharedGroups)
        {
            foreach (var sAsset in sharedAssets)
            {
                string bundleGUID = sAsset.Value[0];


                if (sAsset.Value.Count > 1)
                {
                    for (int i = 1; i < sAsset.Value.Count; i++)
                    {
                        bundleGUID = EditorCRUtlity.StringOrOperation(bundleGUID, sAsset.Value[i]);
                    }
                    bundleGUID = EditorCRUtlity.CalauateMD5Code(bundleGUID);
                }
                bool isLoadAsset = false;
                if (sAsset.Value.Count == 1)
                {
                    isLoadAsset = true;
                    bundleGUID  = "load/" + bundleGUID;
                }
                else
                {
                    isLoadAsset = false;
                    bundleGUID  = "sharedassets/" + bundleGUID;
                }


                AssetFileGroup group = null;
                if (!sharedGroups.ContainsKey(bundleGUID))
                {
                    group = new AssetFileGroup();
                    group.m_IsLoadAsset = isLoadAsset;
                    group.m_BundleName  = bundleGUID;
                    sharedGroups.Add(bundleGUID, group);
                }
                group = sharedGroups[bundleGUID];
                group.m_AssetFiles.Add(new AssetFile()
                {
                    m_AssetDatabaseId = AssetDatabase.AssetPathToGUID(sAsset.Key),
                    m_FilePath        = sAsset.Key,
                    m_FileLowrPath    = sAsset.Key.ToLower()
                });
            }
        }
Beispiel #2
0
        void IBundleNameBuilder.Hanlde(List <AssetFile> input, out List <AssetFileGroup> output)
        {
            Dictionary <string, AssetFileGroup> groups = new Dictionary <string, AssetFileGroup>();

            foreach (var assetFile in input)
            {
                string         bundleName = CRUtlity.DeleteExtension(assetFile.m_FileLowrPath).Replace("assets/cresources/", "");
                AssetFileGroup aGroup     = null;
                if (groups.ContainsKey(bundleName) == false)
                {
                    aGroup = groups[bundleName] = new AssetFileGroup();
                    aGroup.m_AssetFiles = new List <AssetFile>();
                }
                else
                {
                    aGroup = groups[bundleName];
                }
                aGroup.m_BundleName = bundleName;
                aGroup.m_AssetFiles.Add(assetFile);
            }
            output = groups.Values.ToList <AssetFileGroup>();
        }
Beispiel #3
0
        public void Hanlde(List <AssetFileGroup> input, out List <BundleFile> output)
        {
            string cachePath = System.IO.Path.GetFullPath(m_BundleCachePath);

            AssetBundleBuild[] assetBundleBuilds = new AssetBundleBuild[input.Count];
            output = new List <BundleFile>();
            for (int k = 0; k < input.Count; k++)
            {
                AssetFileGroup assetFileGroup = input[k];

                assetBundleBuilds[k].assetBundleName    = assetFileGroup.m_BundleName;
                assetBundleBuilds[k].assetBundleVariant = assetFileGroup.m_BundleVarintsName;

                List <string> assetsPaths = new List <string>();
                for (int i = 0; i < assetFileGroup.m_AssetFiles.Count; i++)
                {
                    assetsPaths.Add(assetFileGroup.m_AssetFiles[i].m_FilePath);
                }
                assetsPaths.Sort();
                assetBundleBuilds[k].assetNames = assetsPaths.ToArray();
            }

            if (!System.IO.Directory.Exists(cachePath))
            {
                System.IO.Directory.CreateDirectory(cachePath);
            }

            AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(cachePath, assetBundleBuilds, m_Options, EditorUserBuildSettings.activeBuildTarget);

            if (manifest != null)
            {
                foreach (var bundlePath in manifest.GetAllAssetBundles())
                {
                    BundleFile bundleFile = new BundleFile()
                    {
                        m_BundleName = bundlePath,
                        m_Path       = Path.Combine(cachePath, bundlePath),
                        m_BFType     = BundleFile.BFType.Bundle
                    };
                    output.Add(bundleFile);
                }

                //BundleFile manifestFile = new BundleFile()
                //{
                //    m_BundleName = Path.GetFileName(cachePath),
                //    m_Path = Path.Combine(cachePath ,System.IO.Path.GetFileName(cachePath)),
                //    m_BFType = BundleFile.BFType.Manifest
                //};
                //output.Add(manifestFile);

                string locationPath = Path.Combine(cachePath, "locations");
                WriteLocation(input, manifest, locationPath);

                BundleFile loactions = new BundleFile()
                {
                    m_BundleName = "locations",
                    m_Path       = locationPath,
                    m_BFType     = BundleFile.BFType.Location
                };

                output.Add(loactions);
            }
        }