Beispiel #1
0
        public EditorAssetMap(AssetbundleBuildSettings settings)
        {
            var assetPath = new List <string>();
            var loadPath  = new List <string>();

            foreach (var setting in settings.BundleSettings)
            {
                assetPath.Clear();
                loadPath.Clear();
                var folderPath = UnityEditor.AssetDatabase.GUIDToAssetPath(setting.Folder.guid);
                Utility.GetFilesInDirectory(string.Empty, assetPath, loadPath, folderPath, setting.IncludeSubfolder);
                var assetList = new Dictionary <string, List <string> >();
                for (int i = 0; i < assetPath.Count; i++)
                {
                    if (assetList.TryGetValue(loadPath[i], out var list))
                    {
                        list.Add(assetPath[i]);
                        continue;
                    }
                    assetList.Add(loadPath[i], new List <string>()
                    {
                        assetPath[i]
                    });
                }
                m_Map.Add(setting.BundleName, assetList);
            }
        }
        public static List <AssetBundleBuild> GetAssetBundlesList(AssetbundleBuildSettings settings)
        {
            var bundleList = new List <AssetBundleBuild>();

            foreach (var setting in settings.BundleSettings)
            {
                //find folder
                var folderPath = AssetDatabase.GUIDToAssetPath(setting.Folder.guid);
                if (!AssetDatabase.IsValidFolder(folderPath))
                {
                    throw new Exception($"Could not found Path {folderPath} for {setting.BundleName}");
                }

                //collect assets
                var assetPathes = new List <string>();
                var loadPathes  = new List <string>();
                Utility.GetFilesInDirectory(string.Empty, assetPathes, loadPathes, folderPath, setting.IncludeSubfolder);
                if (assetPathes.Count == 0)
                {
                    Debug.LogWarning($"Could not found Any Assets {folderPath} for {setting.BundleName}");
                }

                //make assetbundlebuild
                var newBundle = new AssetBundleBuild();
                newBundle.assetBundleName  = setting.BundleName;
                newBundle.assetNames       = assetPathes.ToArray();
                newBundle.addressableNames = loadPathes.ToArray();
                bundleList.Add(newBundle);
            }

            return(bundleList);
        }
        public static void WriteConstStringBundles(AssetbundleBuildSettings settings)
        {
            var bundleList = GetAssetBundlesList(settings);
            var writeFile  = AssetBundleConstBuilder.CreateConstString(bundleList);
            var writePath  = Path.Combine(settings.ConstStringFilePath, settings.ConstStringFileName).Replace('\\', '/');

            File.WriteAllText(writePath, writeFile);
        }
        public static void UploadToS3Bucket(AssetbundleBuildSettings settings)
        {
            var s3Client = new AmazonS3Client(RegionEndpoint.EUCentral1);

            Debug.LogError("UploadDirAsync Start!");
            UploadDirAsync(s3Client, settings.RemoteOutputPath, "moba-prototype-yaml-bucket");
            Debug.LogError("UploadDirAsync End!");
        }
        public static void WriteExpectedSharedBundles(AssetbundleBuildSettings settings)
        {
            var bundleList = GetAssetBundlesList(settings);
            var treeResult = AssetDependencyTree.ProcessDependencyTree(bundleList);

            WriteSharedBundleLog($"{Application.dataPath}/../", treeResult);
            if (!Application.isBatchMode)
            {
                EditorUtility.DisplayDialog("Succeeded!", $"Check {LogExpectedSharedBundleFileName} in your project root directory!", "Confirm");
            }
        }
 public CustomBuildParameters(AssetbundleBuildSettings settings,
                              BuildTarget target,
                              BuildTargetGroup group,
                              string outputFolder,
                              Dictionary <string, HashSet <string> > deps,
                              BuildType buildType) : base(target, group, outputFolder)
 {
     CurrentSettings  = settings;
     CurrentBuildType = buildType;
     DependencyDic    = deps;
 }
        static void SetupAssetdatabaseUsage()
        {
            s_EditorBuildSettings = AssetbundleBuildSettings.EditorInstance;
            if (s_EditorBuildSettings == null || !s_EditorBuildSettings.IsValid())
            {
                throw new System.Exception("AssetbundleBuildSetting is not valid");
            }

            if (s_EditorBuildSettings.CleanCacheInEditor)
            {
                Caching.ClearCache();
            }

            UseAssetDatabase = !s_EditorBuildSettings.EmulateInEditor;

            if (UseAssetDatabase)
            {
                var assetPath = new List <string>();
                var loadPath  = new List <string>();
                foreach (var setting in s_EditorBuildSettings.BundleSettings)
                {
                    assetPath.Clear();
                    loadPath.Clear();

                    var folderPath = UnityEditor.AssetDatabase.GUIDToAssetPath(setting.Folder.guid);
                    var dir        = new DirectoryInfo(Path.Combine(Application.dataPath, folderPath.Remove(0, 7)));
                    AssetbundleBuildSettings.GetFilesInDirectory(string.Empty, assetPath, loadPath, dir, setting.IncludeSubfolder);
                    var assetList = new Dictionary <string, List <string> >();
                    for (int i = 0; i < assetPath.Count; i++)
                    {
                        if (assetList.TryGetValue(loadPath[i], out var list))
                        {
                            list.Add(assetPath[i]);
                            continue;
                        }

                        assetList.Add(loadPath[i], new List <string>()
                        {
                            assetPath[i]
                        });
                    }

                    s_AssetListForEditor.Add(setting.BundleName, assetList);
                }
            }
        }
        public static string Generate(AssetbundleBuildSettings settings, IBundleBuildResults result)
        {
            var linkGenerator = new LinkXmlGenerator();

            foreach (var writeResult in result.WriteResults)
            {
                linkGenerator.AddTypes(writeResult.Value.includedTypes);
            }

            var settingsPath = Application.dataPath.Remove(Application.dataPath.Length - 6) + AssetDatabase.GetAssetPath(settings);

            settingsPath = settingsPath.Remove(settingsPath.LastIndexOf('/'));
            var linkPath = $"{settingsPath}/link.xml";

            linkGenerator.Save(linkPath);
            AssetDatabase.Refresh();
            return(linkPath.Remove(0, Application.dataPath.Length - 6));
        }
 public static void SetupApiTestSettings(AssetbundleBuildSettings settings = null)
 {
     if (Application.isPlaying)
     {
         throw new System.Exception("This funcion cannot be called while playing!");
     }
     if (settings == null)
     {
         settings = AssetbundleBuildSettings.EditorInstance;
     }
     if (settings == null || !settings.IsValid())
     {
         throw new System.Exception("AssetbundleBuildSetting is not valid");
     }
     UseAssetDatabase = true;
     //create editor asset map only for testing
     s_EditorAssetMap = new EditorAssetMap(settings);
 }
Beispiel #10
0
        public static void WriteExpectedSharedBundles(AssetbundleBuildSettings settings)
        {
            if (!Application.isBatchMode)
            {
                //have to ask save current scene
                var saved = UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();

                if (!saved)
                {
                    EditorUtility.DisplayDialog("Failed!", $"User Canceled", "Confirm");
                    return;
                }
            }

            var tempPrevSceneKey = "WriteExpectedSharedBundlesPrevScene";
            var prevScene        = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene();

            EditorPrefs.SetString(tempPrevSceneKey, prevScene.path);

            var bundleList = GetAssetBundlesList(settings);
            var treeResult = AssetDependencyTree.ProcessDependencyTree(bundleList);

            WriteSharedBundleLog($"{Application.dataPath}/../", treeResult);
            if (!Application.isBatchMode)
            {
                EditorUtility.DisplayDialog("Succeeded!", $"Check {LogExpectedSharedBundleFileName} in your project root directory!", "Confirm");
            }

            //domain reloaded, we need to restore previous scene path
            var prevScenePath = EditorPrefs.GetString(tempPrevSceneKey, string.Empty);

            //back to previous scene as all processed scene's prefabs are unpacked.
            if (string.IsNullOrEmpty(prevScenePath))
            {
                UnityEditor.SceneManagement.EditorSceneManager.NewScene(UnityEditor.SceneManagement.NewSceneSetup.DefaultGameObjects);
            }
            else
            {
                UnityEditor.SceneManagement.EditorSceneManager.OpenScene(prevScenePath);
            }
        }
        public static void UploadAllRemoteFiles(AssetbundleBuildSettings settings)
        {
            System.Exception exception = null;
            try
            {
                var buildTargetString = EditorUserBuildSettings.activeBuildTarget.ToString();
                var credential        = new NetworkCredential(settings.FtpUserName, settings.FtpUserPass);
                var uploadRootPath    = Path.Combine(settings.FtpHost, buildTargetString);
                var dirInfo           = new DirectoryInfo(Path.Combine(settings.RemoteOutputPath, buildTargetString));
                var files             = dirInfo.GetFiles();
                var progress          = 0f;
                var progressStep      = 1f / files.Length;
                foreach (var fileInfo in dirInfo.GetFiles())
                {
                    byte[] data = File.ReadAllBytes(fileInfo.FullName);
                    EditorUtility.DisplayProgressBar("Uploading AssetBundles", fileInfo.Name, progress);
                    FtpUpload(Path.Combine(uploadRootPath, fileInfo.Name), data, credential);
                    progress += progressStep;
                }
            }
            catch (System.Exception e)
            {
                exception = e;
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }

            if (exception == null)
            {
                EditorUtility.DisplayDialog("Upload Success", "Uploaded All AssetBundles", "Confirm");
            }
            else
            {
                Debug.LogException(exception);
                EditorUtility.DisplayDialog("Upload Failed", "Got Error while uploading see console for detail.", "Confirm");
            }
        }
        public static void WriteExpectedSharedBundles(AssetbundleBuildSettings settings)
        {
            if (!Application.isBatchMode)
            {
                //have to ask save current scene
                var saved = UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();

                if (!saved)
                {
                    EditorUtility.DisplayDialog("Failed!", $"User Canceled", "Confirm");
                    return;
                }
            }

            var bundleList = GetAssetBundlesList(settings);
            var treeResult = AssetDependencyTree.ProcessDependencyTree(bundleList);

            WriteSharedBundleLog($"{Application.dataPath}/../", treeResult);
            if (!Application.isBatchMode)
            {
                EditorUtility.DisplayDialog("Succeeded!", $"Check {LogExpectedSharedBundleFileName} in your project root directory!", "Confirm");
            }
        }
        static void SetupAssetdatabaseUsage()
        {
            s_EditorBuildSettings = AssetbundleBuildSettings.EditorInstance;
            if (s_EditorBuildSettings == null || !s_EditorBuildSettings.IsValid())
            {
                throw new System.Exception("AssetbundleBuildSetting is not valid");
            }

            if (s_EditorBuildSettings.CleanCacheInEditor)
            {
                Caching.ClearCache();
            }

            UseAssetDatabase = !s_EditorBuildSettings.EmulateInEditor;

            //create editor asset map
            if (UseAssetDatabase)
            {
                s_EditorAssetMap = new EditorAssetMap(s_EditorBuildSettings);
                //set initialied so it does not need explit call initialzed when using aassetdatabase
                Initialized = true;
            }
        }
        public static void BuildAssetBundles(AssetbundleBuildSettings settings, BuildType buildType)
        {
            if (!Application.isBatchMode)
            {
                //have to ask save current scene
                var saved = UnityEditor.SceneManagement.EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();

                if (!saved)
                {
                    EditorUtility.DisplayDialog("Build Failed!", $"User Canceled", "Confirm");
                    return;
                }
            }

            var bundleList = GetAssetBundlesList(settings);

            var buildTarget = EditorUserBuildSettings.activeBuildTarget;
            var groupTarget = BuildPipeline.GetBuildTargetGroup(buildTarget);

            var outputPath = Utility.CombinePath(buildType == BuildType.Local ? settings.LocalOutputPath : settings.RemoteOutputPath, buildTarget.ToString());


            //generate sharedBundle if needed, and pre generate dependency
            var treeResult = AssetDependencyTree.ProcessDependencyTree(bundleList);

            if (settings.AutoCreateSharedBundles)
            {
                bundleList.AddRange(treeResult.SharedBundles);
            }

            var buildParams = new CustomBuildParameters(settings, buildTarget, groupTarget, outputPath, treeResult.BundleDependencies, buildType);

            buildParams.UseCache = !settings.ForceRebuild;

            if (buildParams.UseCache && settings.UseCacheServer)
            {
                buildParams.CacheServerHost = settings.CacheServerHost;
                buildParams.CacheServerPort = settings.CacheServerPort;
            }

            ContentPipeline.BuildCallbacks.PostPackingCallback += PostPackingForSelectiveBuild;
            var returnCode = ContentPipeline.BuildAssetBundles(buildParams, new BundleBuildContent(bundleList.ToArray()), out var results);

            ContentPipeline.BuildCallbacks.PostPackingCallback -= PostPackingForSelectiveBuild;


            if (returnCode == ReturnCode.Success)
            {
                //only remote bundle build generates link.xml
                switch (buildType)
                {
                case BuildType.Local:
                    WriteManifestFile(outputPath, results, buildTarget, settings.RemoteURL);
                    WriteLogFile(outputPath, results);
                    if (!Application.isBatchMode)
                    {
                        EditorUtility.DisplayDialog("Build Succeeded!", "Local bundle build succeeded!", "Confirm");
                    }
                    break;

                case BuildType.Remote:
                    WriteManifestFile(outputPath, results, buildTarget, settings.RemoteURL);
                    WriteLogFile(outputPath, results);
                    var linkPath = TypeLinkerGenerator.Generate(settings, results);
                    if (!Application.isBatchMode)
                    {
                        EditorUtility.DisplayDialog("Build Succeeded!", $"Remote bundle build succeeded, \n {linkPath} updated!", "Confirm");
                    }
                    if (settings.AutoUploadS3)
                    {
                        LocusAssetbundleUploaderExtension.UploadToS3Bucket(settings);
                    }
                    break;
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Build Failed!", $"Bundle build failed, \n Code : {returnCode}", "Confirm");
                Debug.LogError(returnCode);
            }
        }
 public CustomBuildParameters(AssetbundleBuildSettings settings, BuildTarget target, BuildTargetGroup group, string outputFolder, BuildType buildType) : base(target, group, outputFolder)
 {
     CurrentSettings  = settings;
     CurrentBuildType = buildType;
 }
Beispiel #16
0
        public static void BuildAssetBundles(AssetbundleBuildSettings settings, BuildType buildType)
        {
            var bundleList = new List <AssetBundleBuild>();

            foreach (var setting in settings.BundleSettings)
            {
                var folderPath = AssetDatabase.GUIDToAssetPath(setting.Folder.guid);
                var dir        = new DirectoryInfo(Path.Combine(Application.dataPath, folderPath.Remove(0, 7)));
                if (!dir.Exists)
                {
                    throw new Exception($"Could not found Path {folderPath} for {setting.BundleName}");
                }
                var assetPathes = new List <string>();
                var loadPathes  = new List <string>();
                AssetbundleBuildSettings.GetFilesInDirectory(string.Empty, assetPathes, loadPathes, dir, setting.IncludeSubfolder);
                if (assetPathes.Count == 0)
                {
                    Debug.LogWarning($"Could not found Any Assets {folderPath} for {setting.BundleName}");
                }
                var newBundle = new AssetBundleBuild();
                newBundle.assetBundleName  = setting.BundleName;
                newBundle.assetNames       = assetPathes.ToArray();
                newBundle.addressableNames = loadPathes.ToArray();
                bundleList.Add(newBundle);
            }

            var buildTarget = EditorUserBuildSettings.activeBuildTarget;
            var groupTarget = BuildPipeline.GetBuildTargetGroup(buildTarget);

            var outputPath  = Path.Combine(buildType == BuildType.Local ? settings.LocalOutputPath : settings.RemoteOutputPath, buildTarget.ToString());
            var buildParams = new CustomBuildParameters(settings, buildTarget, groupTarget, outputPath, buildType == BuildType.Local);

            buildParams.UseCache = !settings.ForceRebuild;

            if (buildParams.UseCache && settings.UseCacheServer)
            {
                buildParams.CacheServerHost = settings.CacheServerHost;
                buildParams.CacheServerPort = settings.CacheServerPort;
            }

            s_CurrentBuildingSettings = settings;
            s_CurrentBuildType        = buildType;
            ContentPipeline.BuildCallbacks.PostPackingCallback += PostPackingForSelectiveBuild;
            var returnCode = ContentPipeline.BuildAssetBundles(buildParams, new BundleBuildContent(bundleList.ToArray()), out var results);

            ContentPipeline.BuildCallbacks.PostPackingCallback -= PostPackingForSelectiveBuild;

            if (buildType == BuildType.Dry)
            {
                EditorUtility.DisplayDialog("Build Succeeded!", "Dry bundle build succeeded!", "Confirm");
                return;
            }

            if (returnCode == ReturnCode.Success)
            {
                WriteManifestFile(outputPath, results, buildTarget, settings.RemoteURL);
                WriteLogFile(outputPath, results);
                //only remote bundle build generates link.xml

                switch (buildType)
                {
                case BuildType.Local:
                    EditorUtility.DisplayDialog("Build Succeeded!", "Local bundle build succeeded!", "Confirm");
                    break;

                case BuildType.Remote:
                    var linkPath = TypeLinkerGenerator.Generate(settings, results);
                    EditorUtility.DisplayDialog("Build Succeeded!", $"Remote bundle build succeeded, \n {linkPath} updated!", "Confirm");
                    break;

                case BuildType.Dry:
                    EditorUtility.DisplayDialog("Build Succeeded!", $"Dry bundle build succeeded", "Confirm");
                    break;
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Build Failed!", $"Bundle build failed, \n Code : {returnCode}", "Confirm");
                Debug.LogError(returnCode);
            }
        }
Beispiel #17
0
 public CustomBuildParameters(AssetbundleBuildSettings settings, BuildTarget target, BuildTargetGroup group, string outputFolder, bool isLocal) : base(target, group, outputFolder)
 {
     m_Settings = settings;
     m_IsLocal  = isLocal;
 }