コード例 #1
0
    public static void BuildBundleForCurrentPlatforms(AssetBundleListing listing)
    {
        var curPlats = Settings.GetPlatformsForCurrentBuildTarget(EditorUserBuildSettings.activeBuildTarget);

        foreach (BundlePlatform plat in curPlats)
        {
            string        path = Settings.bundleDirectoryRelativeToProjectFolder;
            DirectoryInfo di   = new DirectoryInfo(path);
            path += "/" + listing.name + "_" + plat.name + ".unity3d";
            if (!di.Exists)
            {
                di.Create();
            }
            BuildAssetBundleOptions babOpts = BuildAssetBundleOptions.CompleteAssets;
            if (listing.gatherDependencies)
            {
                babOpts |= BuildAssetBundleOptions.CollectDependencies;
            }
            if (!listing.compressed)
            {
                babOpts |= BuildAssetBundleOptions.UncompressedAssetBundle;
            }
            var files = listing.GetListingForPlatform(plat.name);
            var names = listing.assets.ConvertAll <string>((x) => x.name).ToList();
            BuildPipeline.BuildAssetBundleExplicitAssetNames(files.ToArray(), names.ToArray(), path, babOpts, plat.unityBuildTarget);
        }
    }
コード例 #2
0
 public static void BuildBundleForCurrentPlatforms(AssetBundleListing listing)
 {
     var curPlats = Settings.GetPlatformsForCurrentBuildTarget(EditorUserBuildSettings.activeBuildTarget);
     foreach(BundlePlatform plat in curPlats){
         string path = Settings.bundleDirectoryRelativeToProjectFolder;
         DirectoryInfo di = new DirectoryInfo(path);
         path += "/" + listing.name + "_" + plat.name +".unity3d";
         if(!di.Exists)
             di.Create();
         BuildAssetBundleOptions babOpts = BuildAssetBundleOptions.CompleteAssets;
         if(listing.gatherDependencies)
             babOpts |= BuildAssetBundleOptions.CollectDependencies;
         if(!listing.compressed)
             babOpts |= BuildAssetBundleOptions.UncompressedAssetBundle;
         var files = listing.GetListingForPlatform(plat.name);
         var names = listing.assets.ConvertAll<string>((x) => x.name).ToList();
         BuildPipeline.BuildAssetBundleExplicitAssetNames(files.ToArray(),names.ToArray(), path, babOpts, plat.unityBuildTarget);
     }
 }
コード例 #3
0
    public void OnGUI()
    {
        if (detectedBundlesFileInfos == null || detectedBundles == null)
        {
            Refresh();
            return;
        }
        EditorGUIUtility.LookLikeInspector();
        GUILayout.BeginHorizontal();
        GUILayout.Label("Bundles", EditorStyles.boldLabel);
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Refresh", EditorStyles.miniButton))
        {
            Refresh();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginVertical(GUI.skin.box);
        GUILayout.BeginHorizontal(EditorStyles.toolbar);
        GUILayout.Label("Name", GUILayout.MinWidth(100));
        GUILayout.FlexibleSpace();
        foreach (var plat in AssetBundleListingEditor.Settings.platforms)
        {
            GUILayout.Label(new GUIContent(plat.name, plat.icon32), GUILayout.Height(14), GUILayout.Width(60));
        }
        GUILayout.EndHorizontal();

        List <AssetBundleListing> listingsOutOfDate = new List <AssetBundleListing>();
        var curPlats = AssetBundleListingEditor.Settings.GetPlatformsForCurrentBuildTarget(EditorUserBuildSettings.activeBuildTarget);

        for (int i = 0; i < detectedBundles.Count; i++)
        {
            AssetBundleListing listing = detectedBundles[i];
            if (listing == null)
            {
                Refresh();
                return;
            }
            FileInfo listingFile = detectedBundlesFileInfos[i];
            if (listingFile == null)
            {
                Refresh();
                return;
            }
            Dictionary <string, bool> isOutofdate = new Dictionary <string, bool>();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(listing.name, EditorStyles.miniButton, GUILayout.MinWidth(100)))
            {
                Selection.activeObject = listing;
                EditorGUIUtility.PingObject(Selection.activeObject);
            }
            GUILayout.FlexibleSpace();
            DateTime badDate = new DateTime((System.Int64) 0);
            foreach (var plat in AssetBundleListingEditor.Settings.platforms)
            {
                DateTime lastBundleWriteTime = AssetBundleListingEditor.Settings.GetLastWriteTime(listing, plat.name);
                bool     exists = lastBundleWriteTime != badDate;
                isOutofdate[plat.name] = listingFile.LastWriteTimeUtc > lastBundleWriteTime;
                var platObjs = listing.GetListingForPlatform(plat.name);

                string[] strings = platObjs.ConvertAll <string>((x) => {
                    return(AssetDatabase.GetAssetPath(x));
                }).Distinct().ToArray <string>();
                strings = AssetDatabase.GetDependencies(strings);

                platObjs = Array.ConvertAll <string, UnityEngine.Object>(strings, (x) => {
                    return(AssetDatabase.LoadMainAssetAtPath(x));
                }).ToList();

                foreach (var obj in platObjs)
                {
                    string projectPath = AssetDatabase.GetAssetPath(obj);
                    if (projectPath == "")
                    {
                        continue;
                    }
                    FileInfo objFileInfo  = new FileInfo(projectPath);
                    string   metaPath     = AssetDatabase.GetTextMetaDataPathFromAssetPath(projectPath);
                    FileInfo metaFileInfo = new FileInfo(metaPath);
                    if (objFileInfo.LastWriteTimeUtc > lastBundleWriteTime ||
                        (metaPath != "" && metaFileInfo.LastWriteTimeUtc > lastBundleWriteTime))
                    {
                        isOutofdate[plat.name] = true;
                    }
                }
                if (!exists)
                {
                    GUILayout.Label(AssetBundleListingEditor.Settings.box, GUILayout.Width(60));
                    if (curPlats.Contains(plat) && !listingsOutOfDate.Contains(listing))
                    {
                        listingsOutOfDate.Add(listing);
                    }
                }
                else if (isOutofdate[plat.name])
                {
                    GUILayout.Label(AssetBundleListingEditor.Settings.outOfDate, GUILayout.Width(60));
                    if (curPlats.Contains(plat) && !listingsOutOfDate.Contains(listing))
                    {
                        listingsOutOfDate.Add(listing);
                    }
                }
                else
                {
                    GUILayout.Label(AssetBundleListingEditor.Settings.checkedBox, GUILayout.Width(60));
                }
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();

        string platList = "";

        foreach (var plat in curPlats)
        {
            platList += " " + plat.name;
        }
        if (listingsOutOfDate.Count > 0 && GUILayout.Button("Build missing/out of date bundles for" + platList + " (" + listingsOutOfDate.Count + ")"))
        {
            foreach (AssetBundleListing listing in listingsOutOfDate)
            {
                AssetBundleListingEditor.BuildBundleForCurrentPlatforms(listing);
            }
        }
    }