コード例 #1
0
        public static void ShowWindow()
        {
            AssetBundleWindow thisWindow = (AssetBundleWindow)EditorWindow.GetWindow(typeof(AssetBundleWindow));

            thisWindow.title = "Bundle Creator";

            ReadEditorPrefs(thisWindow);
            CreateAssetBundles.ReadBundleControlFile(Application.dataPath + thisWindow.exportLocation + CreateAssetBundles.bundleControlFileName, thisWindow.bundleVersions);
            CreateAssetBundles.ReadBundleContentsFile(Application.dataPath + thisWindow.exportLocation + CreateAssetBundles.bundleContentsFileName, thisWindow.bundleContents);
            thisWindow.ReadBundleFileSizes();
        }
コード例 #2
0
 private static void ReadEditorPrefs(AssetBundleWindow thisWindow)
 {
     //load editor prefs
     //cws is for "cry wolf studios"
     if (EditorPrefs.HasKey("cws_assetFolder"))
     {
         thisWindow.assetBundleFolderLocation = EditorPrefs.GetString("cws_assetFolder");
     }
     if (EditorPrefs.HasKey("cws_exportFolder"))
     {
         thisWindow.exportLocation = EditorPrefs.GetString("cws_exportFolder");
     }
     if (EditorPrefs.HasKey("cws_bundleExtension"))
     {
         thisWindow.bundleFileExtension = EditorPrefs.GetString("cws_bundleExtension");
     }
     if (EditorPrefs.HasKey("cws_optionalSettings"))
     {
         thisWindow.optionalSettings = EditorPrefs.GetBool("cws_optionalSettings");
     }
     if (EditorPrefs.HasKey("cws_buildTarget"))
     {
         thisWindow.buildTarget = (BuildTarget)EditorPrefs.GetInt("cws_buildTarget");
     }
     if (EditorPrefs.HasKey("cws_buildAssetBundleOptions"))
     {
         thisWindow.buildAssetBundleOptions = EditorPrefs.GetBool("cws_buildAssetBundleOptions");
     }
     if (EditorPrefs.HasKey("cws_collectDependencies"))
     {
         thisWindow.collectDependencies = EditorPrefs.GetBool("cws_collectDependencies");
     }
     if (EditorPrefs.HasKey("cws_completeAssets"))
     {
         thisWindow.completeAssets = EditorPrefs.GetBool("cws_completeAssets");
     }
     if (EditorPrefs.HasKey("cws_disableWriteTypeTree"))
     {
         thisWindow.disableWriteTypeTree = EditorPrefs.GetBool("cws_disableWriteTypeTree");
     }
     if (EditorPrefs.HasKey("cws_deterministicAssetBundle"))
     {
         thisWindow.deterministicAssetBundle = EditorPrefs.GetBool("cws_deterministicAssetBundle");
     }
     if (EditorPrefs.HasKey("cws_uncompressedAssetBundle"))
     {
         thisWindow.uncompressedAssetBundle = EditorPrefs.GetBool("cws_uncompressedAssetBundle");
     }
     if (EditorPrefs.HasKey("cws_setLowerCaseName"))
     {
         thisWindow.setLowerCaseName = EditorPrefs.GetBool("cws_setLowerCaseName");
     }
 }
コード例 #3
0
        private static void ClearPreferences(AssetBundleWindow thisWindow)
        {
            thisWindow.assetBundleFolderLocation = "/BundleCreator/Data/AssetBundles/";
            thisWindow.exportLocation            = "/../AssetBundles/";
            thisWindow.bundleFileExtension       = ".unity3d";

            thisWindow.optionalSettings = false;
            thisWindow.buildTarget      = BuildTarget.WebPlayer;

            //BuildAssetBundleOptions
            thisWindow.buildAssetBundleOptions  = true;
            thisWindow.collectDependencies      = true;
            thisWindow.completeAssets           = true;
            thisWindow.disableWriteTypeTree     = false;
            thisWindow.deterministicAssetBundle = false;
            thisWindow.uncompressedAssetBundle  = false;
            thisWindow.bundleVersions.Clear();
            thisWindow.bundleContents.Clear();
            thisWindow.bundleFileSizes.Clear();
        }
コード例 #4
0
        private static void WriteEditorPrefs(AssetBundleWindow thisWindow)
        {
            //save editor prefs
            //cws is for "cry wolf studios"
            EditorPrefs.SetString("cws_assetFolder", thisWindow.assetBundleFolderLocation);
            EditorPrefs.SetString("cws_exportFolder", thisWindow.exportLocation);
            EditorPrefs.SetString("cws_bundleExtension", thisWindow.bundleFileExtension);
            EditorPrefs.SetBool("cws_optionalSettings", thisWindow.optionalSettings);
            EditorPrefs.SetInt("cws_buildTarget", (int)thisWindow.buildTarget);
            EditorPrefs.SetBool("cws_buildAssetBundleOptions", thisWindow.buildAssetBundleOptions);
            EditorPrefs.SetBool("cws_collectDependencies", thisWindow.collectDependencies);
            EditorPrefs.SetBool("cws_completeAssets", thisWindow.completeAssets);
            EditorPrefs.SetBool("cws_disableWriteTypeTree", thisWindow.disableWriteTypeTree);
            EditorPrefs.SetBool("cws_deterministicAssetBundle", thisWindow.deterministicAssetBundle);
            EditorPrefs.SetBool("cws_uncompressedAssetBundle", thisWindow.uncompressedAssetBundle);
            EditorPrefs.SetBool("cws_setLowerCaseName", thisWindow.setLowerCaseName);

            //If you want the export folder at runtime (for asset bundle loading in editor mode)
            PlayerPrefs.SetString("cws_exportFolder", thisWindow.exportLocation);
        }
コード例 #5
0
        /// <summary>
        /// Helper function to build an asset bundle
        /// This will iterate through all the settings of the AssetBundleWindow and set them accordingly
        /// </summary>
        /// <param name="thisWindow"></param>
        /// <param name="toInclude"></param>
        /// <param name="bundlePath"></param>
        public static bool BuildAssetBundle(AssetBundleWindow thisWindow, List <Object> toInclude, string bundlePath)
        {
            BuildAssetBundleOptions buildAssetOptions = 0;

            if (thisWindow.buildAssetBundleOptions)
            {
                if (thisWindow.collectDependencies)
                {
                    if (buildAssetOptions == 0)
                    {
                        buildAssetOptions = BuildAssetBundleOptions.CollectDependencies;
                    }
                    else
                    {
                        buildAssetOptions |= BuildAssetBundleOptions.CollectDependencies;
                    }
                }
                if (thisWindow.completeAssets)
                {
                    if (buildAssetOptions == 0)
                    {
                        buildAssetOptions = BuildAssetBundleOptions.CompleteAssets;
                    }
                    else
                    {
                        buildAssetOptions |= BuildAssetBundleOptions.CompleteAssets;
                    }
                }
                if (thisWindow.disableWriteTypeTree)
                {
                    if (buildAssetOptions == 0)
                    {
                        buildAssetOptions = BuildAssetBundleOptions.DisableWriteTypeTree;
                    }
                    else
                    {
                        buildAssetOptions |= BuildAssetBundleOptions.DisableWriteTypeTree;
                    }
                }
                if (thisWindow.deterministicAssetBundle)
                {
                    if (buildAssetOptions == 0)
                    {
                        buildAssetOptions = BuildAssetBundleOptions.DeterministicAssetBundle;
                    }
                    else
                    {
                        buildAssetOptions |= BuildAssetBundleOptions.DeterministicAssetBundle;
                    }
                }
                if (thisWindow.uncompressedAssetBundle)
                {
                    if (buildAssetOptions == 0)
                    {
                        buildAssetOptions = BuildAssetBundleOptions.UncompressedAssetBundle;
                    }
                    else
                    {
                        buildAssetOptions |= BuildAssetBundleOptions.UncompressedAssetBundle;
                    }
                }
            }

            //If none of "BuildAssetBundleOptions" or "Optional Settings" are set, then create without dependency tracking
            if (!thisWindow.buildAssetBundleOptions && !thisWindow.optionalSettings)
            {
//                if (!BuildPipeline.BuildAssetBundle(null, toInclude.ToArray(), bundlePath))
//                {
//                    return false;
//                }
            }
            else
            {
                if (buildAssetOptions == 0) //If it's still zero, set default values
                {
                    Debug.LogWarning("No BuildAssetBundleOptions are set, reverting back to dependency tracking. If you want no dependency tracking uncheck the 'BuildAssetBundleOptions' && 'Optional Settings' toggles all together");
                    buildAssetOptions = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;
                    thisWindow.buildAssetBundleOptions = true;
                    thisWindow.collectDependencies     = true;
                    thisWindow.completeAssets          = true;
                }
                if (thisWindow.optionalSettings) //Support for different build targets
                {
                    if (!BuildPipeline.BuildAssetBundle(null, toInclude.ToArray(), bundlePath, buildAssetOptions, thisWindow.buildTarget))
                    {
                        return(false);
                    }
                }
                else
                {
//                    if (!BuildPipeline.BuildAssetBundle(null, toInclude.ToArray(), bundlePath, buildAssetOptions))
//                    {
//                        return false;
//                    }
                }
            }
            return(true);
        }
コード例 #6
0
        public static bool ExportAssetBundleFolders(AssetBundleWindow thisWindow)
        {
            //To keep track of the versions with the control file
            //버전 관리를 위한 컨트롤 파일
            Dictionary <string, int> bundleVersions = new Dictionary <string, int>();

            //A list of all the assets in each bundle
            //각각의 번들에 들어있는 모든 에셋의 목록
            //This will be saved into the file bundleContents.txt;
            //이 내용은 bundleContents.txt에 저장할 것이다.
            Dictionary <string, List <string> > bundleContents = new Dictionary <string, List <string> >();

            //The AssetBundle folder
            string path = Application.dataPath + thisWindow.exportLocation;

            //The folder location in the editor
            string assetBundleFolderLocation = thisWindow.assetBundleFolderLocation;

            //Create directory if it does not exist
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //Read and parse the control file
            ReadBundleControlFile(path + bundleControlFileName, bundleVersions);
            //Read and parse the contents file
            ReadBundleContentsFile(path + bundleContentsFileName, bundleContents);

            //Check if the directory exist
            if (!Directory.Exists(Application.dataPath + assetBundleFolderLocation))
            {
                Debug.LogError("Specified 'AssetBundles folder' does not exist! Open Assets->Bundle Creator->Asset Bundle Creator to correct it");
                return(false);
            }

            int createdBundles = 0;

            string[] directoryNames = Directory.GetDirectories(Application.dataPath + assetBundleFolderLocation);
            foreach (string folderPath in directoryNames)
            {
                //Generate the name of this asset bundle
                DirectoryInfo dirInfo = new DirectoryInfo(folderPath);

                //if the user has specified a build target, add a prefix to the bundle name
                string bundleName    = "";
                string directoryName = dirInfo.Name;
                if (thisWindow.setLowerCaseName)
                {
                    directoryName = directoryName.ToLower();
                }

                if (!thisWindow.optionalSettings)
                {
                    bundleName = directoryName + thisWindow.bundleFileExtension;
                }
                else
                {
                    bundleName = thisWindow.buildTarget.ToString().ToLower() + "_" + directoryName + thisWindow.bundleFileExtension;
                }

                List <Object> toInclude      = new List <Object>();
                string[]      assetsInFolder = Directory.GetFiles(folderPath);

                //To save in the contents file(information)
                List <string> assetListInFolder = new List <string>();

                foreach (string asset in assetsInFolder)
                {
                    string thisFileName = Path.GetFileName(asset);
                    if (asset.EndsWith(".prefab"))
                    {
                        string     internalFilePath = "Assets" + assetBundleFolderLocation + dirInfo.Name + "/" + thisFileName;
                        GameObject prefab           = (GameObject)AssetDatabase.LoadAssetAtPath(internalFilePath, typeof(GameObject));
                        toInclude.Add((Object)prefab);

                        assetListInFolder.Add(thisFileName);
                    }
                    else if (!asset.EndsWith(".meta"))
                    {
                        //toInclude.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetBundleFolderLocation + dirInfo.Name + "/" + thisFileName));
                        string internalFilePath = "Assets" + assetBundleFolderLocation + dirInfo.Name + "/" + thisFileName;
                        toInclude.Add((Object)AssetDatabase.LoadAssetAtPath(internalFilePath, typeof(Object)));
                        assetListInFolder.Add(thisFileName);
                    }
                }

                //Build only if there are any files in this folder
                if (toInclude.Count > 0)
                {
                    //Check if the bundle already have been created
                    if (bundleContents.ContainsKey(bundleName))
                    {
                        bundleContents.Remove(bundleName);
                    }
                    //Add to the contents text file
                    bundleContents.Add(bundleName, assetListInFolder);

                    Debug.Log("Building bundle:" + bundleName);
                    if (!BuildAssetBundle(thisWindow, toInclude, path + bundleName))
                    {
                        return(false); //It failed, abort everything
                    }
                    createdBundles++;

                    //Checks to save the version numbers
                    int versionNumber = -1;
                    bundleVersions.TryGetValue(bundleName, out versionNumber);

                    if (versionNumber == -1)
                    {
                        versionNumber = 1;
                    }
                    else
                    {
                        versionNumber++;
                        bundleVersions.Remove(bundleName);
                    }
                    bundleVersions.Add(bundleName, versionNumber);
                }
                toInclude.Clear();
            }

            WriteBundleControlFile(path + bundleControlFileName, bundleVersions, path);
            WriteBundleControlFileXml(path + bundleControlFileName, bundleVersions, path);
            WriteBundleContentsFileXml(path + bundleContentsFileName, bundleContents, path);
            WriteBundleContentsFile(path + bundleContentsFileName, bundleContents, path);
            bundleVersions.Clear();
            foreach (KeyValuePair <string, List <string> > pair in bundleContents)
            {
                pair.Value.Clear();
            }
            bundleContents.Clear();

            Debug.Log("***Successfully Created " + createdBundles + " AssetBundles!***");
            return(true);
        }