Beispiel #1
0
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        AssetBundleWindow window = (AssetBundleWindow)EditorWindow.GetWindow(typeof(AssetBundleWindow));

        window.Show();
    }
Beispiel #2
0
    public static void OpenAssetBundleTool()
    {
        AssetBundleWindow win = EditorWindow.GetWindow <AssetBundleWindow>();

        win.titleContent.text = "AssetBundle工具";
        win.Show();
    }
Beispiel #3
0
    private static void CreateAssetBundle()
    {
        AssetBundleWindow win = EditorWindow.GetWindow <AssetBundleWindow>();

        win.titleContent = new GUIContent("Build AssetBundle");
        win.Show();
    }
Beispiel #4
0
    public static void AssetBundleMgr()
    {
        AssetBundleWindow win = (AssetBundleWindow)EditorWindow.GetWindow(typeof(AssetBundleWindow));

        win.titleContent = new GUIContent("资源包管理");
        win.Show();
    }
Beispiel #5
0
    public static void AssetBoundCreate()
    {
        AssetBundleWindow window = EditorWindow.GetWindow <AssetBundleWindow>();

        window.titleContent = new GUIContent("AssetBundle");
        window.Show();
    }
Beispiel #6
0
    public static void AssetBundleCreate()
    {
        AssetBundleWindow win = EditorWindow.GetWindow <AssetBundleWindow>();

        win.titleContent = new GUIContent("资源打包");
        win.Show();
    }
Beispiel #7
0
    public static void AssetBundleCreate()
    {
        //显示AB打包的窗口
        AssetBundleWindow win = EditorWindow.GetWindow <AssetBundleWindow>();

        win.titleContent = new GUIContent("AB打包工具");
        win.Show();
    }
Beispiel #8
0
 void OnEnable()
 {
     config.Add("test", "t1");
     instance   = this;
     mScroll    = Vector2.zero;
     msg_log    = string.Empty;
     sel_rename = string.Empty;
     EditorABSetting.LoadPrefs();
 }
    private static void StartBuildAsset(AssetBundleWindow window)
    {
        List<Object> commonList = new List<Object>();
        List<Object> prefabList = new List<Object>();
        List<Object> sceneList = new List<Object>();
        List<Object> monsterList = new List<Object>();

        Object[] selectFileList = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
        string assetPath = null;
        foreach (Object asset in selectFileList)
        {
            assetPath = AssetDatabase.GetAssetPath(asset);
            if (IsCommonAsset(asset)) commonList.Add(asset);
            else if (IsSceneAsset(assetPath)) sceneList.Add(asset);
            else if (IsMonsterAsset(assetPath)) monsterList.Add(asset);
            else prefabList.Add(asset);
        }

        if(window.isBuildCodeLib)
        {
            BuildCodeLibAssetBundle(window);
        }
        //打包公共资源并存储依赖关系
        foreach(Object obj in commonList)
        {
            BuildPipeline.PushAssetDependencies();
            BuildAssetBundle(window, obj);
        }
        //打包UI
        foreach(Object obj in prefabList)
        {
            BuildPipeline.PushAssetDependencies();
            BuildAssetBundle(window, obj);
            BuildPipeline.PopAssetDependencies();
        }
        //公共资源依赖出栈
        foreach(Object obj in commonList)
        {
            BuildPipeline.PopAssetDependencies();
        }
        foreach(Object obj in sceneList)
        {
            BuildSceneAssetBundle(window,obj);
        }
        foreach(Object obj in monsterList)
        {
            //Build Monster Asset
        }

        AssetDatabase.Refresh();

        if(window.isBuildAssetMd5)
        {
            BuildAssetMd5(window);
        }
    }
Beispiel #10
0
    public static void AssetBundleCreate()
    {
        // 实例化
        AssetBundleWindow win = EditorWindow.GetWindow <AssetBundleWindow>();

        //设置窗口名称
        win.titleContent = new GUIContent("AssetBundle");
        //窗口显示
        win.Show();
    }
    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();
    }
 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");
     }
 }
    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();
    }
    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);
    }
Beispiel #15
0
    public static void CreateAssetBundles()
    {
        AssetBundleWindow win = EditorWindow.GetWindow <AssetBundleWindow>();

        win.titleContent = new GUIContent("资源打包");
        win.Show();

        //string path = Application.dataPath + "/../AssetBundles";

        //if (!Directory.Exists(path))
        //{
        //    Directory.CreateDirectory(path);
        //}

        //string path = Application.dataPath + "/Editor/AssetBundle/AssetBundleConfig.xml";
        //AssetBundleDAL assetBundleDal=new AssetBundleDAL(path);

        //var list = assetBundleDal.GetList();

        //for (int i = 0; i < list.Count; i++)
        //{
        //    Debug.Log(list[i].Name);
        //}
    }
 private static void OpenAssetBundleWindow()
 {
     AssetBundleWindow ABEditor = EditorWindow.GetWindow <AssetBundleWindow>();
 }
 private static void OpenWindow(string path,AssetBundleWindow window)
 {
     //ReadEditorPrefs(window);
 }
Beispiel #18
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();
    }
Beispiel #19
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);
    }
Beispiel #20
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");
        }
    }
Beispiel #21
0
    public static void AssetBundleCreate()
    {
        AssetBundleWindow assetBundleWindow = EditorWindow.GetWindow <AssetBundleWindow>();

        assetBundleWindow.Show();
    }
    private static void BuildAssetMd5(AssetBundleWindow window)
    {
        string assetDir = Application.dataPath + window.assetBundleDir;
        FileInfo md5File = new FileInfo(Application.dataPath + "/Cfg/" + window.assetBundleMd5File);
        StreamWriter writer = new StreamWriter(md5File.FullName, false, UTF8Encoding.UTF8);

        List<String> fileList = GetAllFile(assetDir);

        string md5;
        string fileRelativeName;
        FileInfo tempInfo;
        foreach(string file in fileList)
        {
            if(file.EndsWith(window.assetBundleFileExtension) && !file.Contains("AssetsList.") && !file.Contains("Version."))
            {
                fileRelativeName = file.Replace(assetDir, "");
                fileRelativeName = fileRelativeName.Remove(0, 1);
                fileRelativeName = fileRelativeName.Replace("\\","/");
                md5 = GetFileMd5(file);
                tempInfo = new FileInfo(file);
                writer.WriteLine(fileRelativeName);
                writer.WriteLine(md5);
                writer.WriteLine(tempInfo.Length);
            }
        }
        writer.Flush();
        writer.Close();
        writer.Dispose();

        AssetDatabase.Refresh();

        Object md5Obj=AssetDatabase.LoadAllAssetsAtPath("Assets/Cfg/"+window.assetBundleMd5File)[0];
        BuildAssetBundle(window, md5Obj);

        File.Copy(Application.dataPath + "/Cfg/" + window.assetBundleMd5File, Application.dataPath + window.assetBundleDir + "/Cfg/" + window.assetBundleMd5File, true);
    }
 private static string GetRelativeDestDir(AssetBundleWindow window,Object obj)
 {
     string sourPath = AssetDatabase.GetAssetPath(obj);
     string destTempDir = sourPath.Replace("Assets/", "");
     if (destTempDir.LastIndexOf("/") > 0)
     {
         destTempDir = destTempDir.Substring(0, destTempDir.LastIndexOf("/"));
     }
     return destTempDir;
 }
Beispiel #24
0
 void OnDisable()
 {
     instance = null;
     EditorABSetting.SavePrefs();
 }
 /// <summary>
 /// 打包代码包
 /// </summary>
 /// <param name="window"></param>
 private static void BuildCodeLibAssetBundle(AssetBundleWindow window)
 {
     string dllPath = Application.dataPath.Replace(@"/Assets", "") + @"/obj/Debug/Assembly-CSharp.dll";
     string outputPath = Application.dataPath + "/Code/Assembly-CSharp.bytes";
     File.Copy(dllPath, outputPath, true);
     AssetDatabase.Refresh();
     Object obj = AssetDatabase.LoadAllAssetsAtPath("Assets/Code/Assembly-CSharp.bytes")[0];
     BuildAssetBundle(window, obj);
 }
    static void Init()
    {
        AssetBundleWindow window = (AssetBundleWindow)GetWindow(typeof(AssetBundleWindow));

        window.Show();
    }
Beispiel #27
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;
        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)Resources.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)Resources.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);
        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;
    }
    /// <summary>
    /// 打包场景
    /// </summary>
    /// <param name="window"></param>
    /// <param name="obj"></param>
    private static void BuildSceneAssetBundle(AssetBundleWindow window,Object obj)
    {
        string sourPath = AssetDatabase.GetAssetPath(obj);
        string destDir = GetAndCreateDestDir(window, obj);
        string destPath = destDir + "/" + obj.name + window.assetBundleFileExtension;
        string depFilePath = destDir + "/" + obj.name + "_dep.txt";

        FileInfo depFile = new FileInfo(depFilePath);
        StreamWriter writer = new StreamWriter(depFile.FullName, false,UTF8Encoding.UTF8);

        string[] levels=new string[] { sourPath };
        string[] depList = AssetDatabase.GetDependencies(levels);
        foreach(string depPath in depList)
        {
            if(isSceneDependAsset(depPath))
            {
                Object depObj=AssetDatabase.LoadAllAssetsAtPath(depPath)[0];
                string depDestDir = GetAndCreateDestDir(window, depObj);
                string depDestPath = depDestDir + "/" + depObj.name + window.assetBundleFileExtension;
                string depRelativePath = GetRelativeDestDir(window,depObj) + "/" + depObj.name + window.assetBundleFileExtension;
                writer.WriteLine(depRelativePath);

                BuildPipeline.PushAssetDependencies();
                BuildAssetBundle(window, depObj);
            }
        }
        writer.Flush();
        writer.Close();
        writer.Dispose();

        BuildPipeline.PushAssetDependencies();
        BuildPipeline.BuildPlayer(levels,destPath,window.assetBundleBuildTarget,BuildOptions.BuildAdditionalStreamedScenes);
        BuildPipeline.PopAssetDependencies();

        foreach(string depPath in depList)
        {
            if (isSceneDependAsset(depPath)) BuildPipeline.PopAssetDependencies();
        }

        AssetDatabase.Refresh();

        string depFileAssetPath = "Assets" + depFilePath.Replace(Application.dataPath,"");
        Object depFileObj=AssetDatabase.LoadAllAssetsAtPath(depFileAssetPath)[0];
        string depFileDestPath = destDir + "/" + obj.name+ "_dep" + window.assetBundleFileExtension;
        BuildAssetBundle(window, depFileObj, depFileDestPath);
    }
 private static void BuildAssetBundle(AssetBundleWindow window , Object obj , string destPath = null)
 {
     string destDir = GetAndCreateDestDir(window, obj);
     destPath = destPath ?? destDir +"/"+ obj.name + window.assetBundleFileExtension;
     Debug.Log("Asset Path:" + destPath);
     if (BuildPipeline.BuildAssetBundle(obj, null, destPath,
         BuildAssetBundleOptions.CollectDependencies |
         BuildAssetBundleOptions.CompleteAssets |
         BuildAssetBundleOptions.DeterministicAssetBundle,
         window.assetBundleBuildTarget))
     {
         Debug.Log("Build Asset Success:" + destPath);
     }
     else
     {
         Debug.LogError("Build Asset Failed:" + destPath);
     }
 }
Beispiel #30
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;
        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)Resources.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)Resources.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);
        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;
    }
Beispiel #31
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;
    }
Beispiel #32
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;
    }
 private static string GetAndCreateDestDir(AssetBundleWindow window, Object obj)
 {
     string sourPath = AssetDatabase.GetAssetPath(obj);
     string destTempDir = sourPath.Replace("Assets/", "");
     if (destTempDir.LastIndexOf("/") > 0)
     {
         destTempDir = destTempDir.Substring(0, destTempDir.LastIndexOf("/"));
     }
     string destDir= Application.dataPath + window.assetBundleDir + "/" + destTempDir;
     DirectoryInfo info = new DirectoryInfo(destDir);
     if (!info.Exists) info.Create();
     return destDir;
 }