Ejemplo n.º 1
0
 public int this[BuildTarget index] {
     get {
         return(this[BuildTargetUtility.TargetToGroup(index)]);
     }
     set {
         this[BuildTargetUtility.TargetToGroup(index)] = value;
     }
 }
        public void Setup(BuildTarget target,
                          NodeData node,
                          ConnectionPointData inputPoint,
                          ConnectionData connectionToOutput,
                          Dictionary <string, List <Asset> > inputGroupAssets,
                          List <string> alreadyCached,
                          Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var outputDict = new Dictionary <string, List <Asset> >();

            outputDict[key] = new List <Asset>();

            var bundleNames = inputGroupAssets.Keys.ToList();

            var bundleVariants = new Dictionary <string, List <string> >();

            // get all variant name for bundles
            foreach (var name in bundleNames)
            {
                bundleVariants[name] = new List <string>();
                var assets = inputGroupAssets[name];
                foreach (var a in assets)
                {
                    var variantName = a.variantName;
                    if (!bundleVariants[name].Contains(variantName))
                    {
                        bundleVariants[name].Add(variantName);
                    }
                }
            }

            // add manifest file
            var manifestName = BuildTargetUtility.TargetToAssetBundlePlatformName(target);

            bundleNames.Add(manifestName);
            bundleVariants[manifestName] = new List <string>()
            {
                ""
            };

            var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node);

            foreach (var name in bundleNames)
            {
                foreach (var v in bundleVariants[name])
                {
                    string bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v;
                    Asset  bundle     = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName));
                    Asset  manifest   = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName + AssetBundleGraphSettings.MANIFEST_FOOTER));
                    outputDict[key].Add(bundle);
                    outputDict[key].Add(manifest);
                }
            }

            Output(connectionToOutput, outputDict, new List <string>());
        }
Ejemplo n.º 3
0
        public static bool IsBuildTargetSupported(BuildTarget t)
        {
            var objType = typeof(UnityEditor.BuildPipeline);
            var method  = objType.GetMethod("IsBuildTargetSupported", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

                        #if UNITY_5_6
            BuildTargetGroup g = BuildTargetUtility.TargetToGroup(t);
            //internal static extern bool IsBuildTargetSupported (BuildTargetGroup buildTargetGroup, BuildTarget target);
            var retval = method.Invoke(null, new object[] {
                System.Enum.ToObject(typeof(BuildTargetGroup), g),
                System.Enum.ToObject(typeof(BuildTarget), t)
            });
                        #else
            //internal static extern bool IsBuildTargetSupported (BuildTarget target);
            var retval = method.Invoke(null, new object[] { System.Enum.ToObject(typeof(BuildTarget), t) });
                        #endif
            return(Convert.ToBoolean(retval));
        }
            public void SetupSupportedBuildTargets()
            {
                if (supportedBuildTargets == null)
                {
                    supportedBuildTargets      = new List <BuildTarget>();
                    supportedBuildTargetGroups = new List <BuildTargetGroup>();

                    try {
                        foreach (BuildTarget target in Enum.GetValues(typeof(BuildTarget)))
                        {
                            if (BuildTargetUtility.IsBuildTargetSupported(target))
                            {
                                if (!supportedBuildTargets.Contains(target))
                                {
                                    supportedBuildTargets.Add(target);
                                }
                                BuildTargetGroup g = BuildTargetUtility.TargetToGroup(target);
                                if (g == BuildTargetGroup.Unknown)
                                {
                                    // skip unknown platform
                                    continue;
                                }
                                if (!supportedBuildTargetGroups.Contains(g))
                                {
                                    supportedBuildTargetGroups.Add(g);
                                }
                            }
                        }

                        supportedBuildTargetNames = new string[supportedBuildTargets.Count];
                        for (int i = 0; i < supportedBuildTargets.Count; ++i)
                        {
                            supportedBuildTargetNames[i] = BuildTargetUtility.TargetToHumaneString(supportedBuildTargets[i]);
                        }
                    } catch (Exception e) {
                        Debug.LogError(e.ToString());
                    }
                }
            }
            public void SetupPlatformButtons()
            {
                SetupSupportedBuildTargets();
                var buttons = new List <PlatformButton>();

                Dictionary <BuildTargetGroup, string> icons = new Dictionary <BuildTargetGroup, string> {
                    { BuildTargetGroup.Android, "BuildSettings.Android.Small" },
                    { BuildTargetGroup.iOS, "BuildSettings.iPhone.Small" },
                    { BuildTargetGroup.Nintendo3DS, "BuildSettings.N3DS.Small" },
                    { BuildTargetGroup.PS3, "BuildSettings.PS3.Small" },
                    { BuildTargetGroup.PS4, "BuildSettings.PS4.Small" },
                    { BuildTargetGroup.PSM, "BuildSettings.PSM.Small" },
                    { BuildTargetGroup.PSP2, "BuildSettings.PSP2.Small" },
                    { BuildTargetGroup.SamsungTV, "BuildSettings.Android.Small" },
                    { BuildTargetGroup.Standalone, "BuildSettings.Standalone.Small" },
                    { BuildTargetGroup.Tizen, "BuildSettings.Tizen.Small" },
                    { BuildTargetGroup.tvOS, "BuildSettings.tvOS.Small" },
                    { BuildTargetGroup.Unknown, "BuildSettings.Standalone.Small" },
                    { BuildTargetGroup.WebGL, "BuildSettings.WebGL.Small" },
                    { BuildTargetGroup.WiiU, "BuildSettings.WiiU.Small" },
                    { BuildTargetGroup.WSA, "BuildSettings.WP8.Small" },
                    { BuildTargetGroup.XBOX360, "BuildSettings.Xbox360.Small" },
                    { BuildTargetGroup.XboxOne, "BuildSettings.XboxOne.Small" }
                };

                buttons.Add(new PlatformButton(new GUIContent("Default", "Default settings"), BuildTargetGroup.Unknown));

                foreach (var g in supportedBuildTargetGroups)
                {
                    buttons.Add(new PlatformButton(new GUIContent(GetPlatformIcon(icons[g]), BuildTargetUtility.GroupToHumaneString(g)), g));
                }

                this.platformButtons = buttons.ToArray();
            }
 public static IModifier CreateModifier(NodeData node, BuildTarget target)
 {
     return(CreateModifier(node, BuildTargetUtility.TargetToGroup(target)));
 }
Ejemplo n.º 7
0
 public static IPrefabBuilder CreatePrefabBuilder(NodeData node, BuildTarget target)
 {
     return(CreatePrefabBuilder(node, BuildTargetUtility.TargetToGroup(target)));
 }
Ejemplo n.º 8
0
        public static void BuildFromCommandline()
        {
            try {
                var arguments = new List <string>(System.Environment.GetCommandLineArgs());

                Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.None);

                BuildTarget target = EditorUserBuildSettings.activeBuildTarget;

                int targetIndex = arguments.FindIndex(a => a == "-target");

                if (targetIndex >= 0)
                {
                    var targetStr = arguments[targetIndex + 1];
                    Debug.Log("Target specified:" + targetStr);

                    var newTarget = BuildTargetUtility.BuildTargetFromString(arguments[targetIndex + 1]);
                    if (!BuildTargetUtility.IsBuildTargetSupported(newTarget))
                    {
                        throw new AssetBundleGraphException(newTarget + " is not supported to build with this Unity. Please install platform support with installer(s).");
                    }

                    if (newTarget != target)
                    {
                        EditorUserBuildSettings.SwitchActiveBuildTarget(newTarget);
                        target = newTarget;
                    }
                }

                Debug.Log("Asset bundle building for:" + BuildTargetUtility.TargetToHumaneString(target));

                if (!SaveData.IsSaveDataAvailableAtDisk())
                {
                    Debug.Log("AssetBundleGraph save data not found. Aborting...");
                    return;
                }

                // load data from file.
                SaveData             saveData = SaveData.LoadFromDisk();
                List <NodeException> errors   = new List <NodeException>();
                Dictionary <ConnectionData, Dictionary <string, List <Asset> > > result = null;

                Action <NodeException> errorHandler = (NodeException e) => {
                    errors.Add(e);
                };

                // perform setup. Fails if any exception raises.
                AssetBundleGraphController.Perform(saveData, target, false, errorHandler, null);

                // if there is error reported, then run
                if (errors.Count > 0)
                {
                    Debug.Log("Build terminated because following error found during Setup phase. Please fix issues by opening editor before building.");
                    errors.ForEach(e => Debug.LogError(e));

                    return;
                }

                NodeData lastNodeData = null;
                float    lastProgress = 0.0f;
                Action <NodeData, float> updateHandler = (NodeData node, float progress) => {
                    if (node != null && lastNodeData != node)
                    {
                        lastNodeData = node;
                        lastProgress = progress;

                        Debug.LogFormat("Processing {0}...", node.Name);
                    }
                    if (progress > lastProgress)
                    {
                        if (progress <= 1.0f)
                        {
                            Debug.LogFormat("{0} Complete.", node.Name);
                        }
                        else if ((progress - lastProgress) > 0.2f)
                        {
                            Debug.LogFormat("{0}: {1} %", node.Name, (int)progress * 100f);
                        }
                        lastProgress = progress;
                    }
                };

                // run datas.
                result = AssetBundleGraphController.Perform(saveData, target, true, errorHandler, updateHandler);

                AssetDatabase.Refresh();
                AssetBundleGraphController.Postprocess(saveData, result, true);
            } catch (Exception e) {
                Debug.LogError(e);
                Debug.LogError("Building asset bundles terminated due to unexpected error.");
            } finally {
                Debug.Log("End of build.");
            }
        }
Ejemplo n.º 9
0
        /**
         * Build from commandline - entrypoint.
         */
        public static void BuildFromCommandline()
        {
            try {
                var arguments = new List <string>(System.Environment.GetCommandLineArgs());

                Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.None);

                BuildTarget target = EditorUserBuildSettings.activeBuildTarget;

                int targetIndex = arguments.FindIndex(a => a == "-target");

                if (targetIndex >= 0)
                {
                    var targetStr = arguments[targetIndex + 1];
                    LogUtility.Logger.Log("Target specified:" + targetStr);

                    var newTarget = BuildTargetUtility.BuildTargetFromString(arguments[targetIndex + 1]);
                    if (!BuildTargetUtility.IsBuildTargetSupported(newTarget))
                    {
                        throw new AssetBundleGraphException(newTarget + " is not supported to build with this Unity. Please install platform support with installer(s).");
                    }

                    if (newTarget != target)
                    {
                                                #if UNITY_5_6
                        EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetUtility.TargetToGroup(newTarget), newTarget);
                                                #else
                        EditorUserBuildSettings.SwitchActiveBuildTarget(newTarget);
                                                #endif
                        target = newTarget;
                    }
                }

                LogUtility.Logger.Log("AssetReference bundle building for:" + BuildTargetUtility.TargetToHumaneString(target));

                if (!SaveData.IsSaveDataAvailableAtDisk())
                {
                    LogUtility.Logger.Log("AssetBundleGraph save data not found. Aborting...");
                    return;
                }

                // load data from file.
                AssetBundleGraphController c = new AssetBundleGraphController();

                // perform setup. Fails if any exception raises.
                c.Perform(target, false, true, null);

                // if there is error reported, then run
                if (c.IsAnyIssueFound)
                {
                    LogUtility.Logger.Log("Build terminated because following error found during Setup phase. Please fix issues by opening editor before building.");
                    c.Issues.ForEach(e => LogUtility.Logger.LogError(LogUtility.kTag, e));

                    return;
                }

                NodeData lastNodeData = null;
                float    lastProgress = 0.0f;

                Action <NodeData, string, float> updateHandler = (NodeData node, string message, float progress) => {
                    if (node != null && lastNodeData != node)
                    {
                        lastNodeData = node;
                        lastProgress = progress;

                        LogUtility.Logger.LogFormat(LogType.Log, "Processing {0}", node.Name);
                    }
                    if (progress > lastProgress)
                    {
                        if (progress <= 1.0f)
                        {
                            LogUtility.Logger.LogFormat(LogType.Log, "{0} Complete.", node.Name);
                        }
                        else if ((progress - lastProgress) > 0.2f)
                        {
                            LogUtility.Logger.LogFormat(LogType.Log, "{0}: {1} % : {2}", node.Name, (int)progress * 100f, message);
                        }
                        lastProgress = progress;
                    }
                };

                // run datas.
                c.Perform(target, true, true, updateHandler);

                AssetDatabase.Refresh();
            } catch (Exception e) {
                LogUtility.Logger.LogError(LogUtility.kTag, e);
                LogUtility.Logger.LogError(LogUtility.kTag, "Building asset bundles terminated due to unexpected error.");
            } finally {
                LogUtility.Logger.Log("End of build.");
            }
        }
Ejemplo n.º 10
0
        public static string EnsureAssetBundleCacheDirExists(BuildTarget t, NodeData node, bool remake = false)
        {
            var cacheDir = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE, node.Id, BuildTargetUtility.TargetToAssetBundlePlatformName(t));

            if (!Directory.Exists(cacheDir))
            {
                Directory.CreateDirectory(cacheDir);
            }
            else
            {
                if (remake)
                {
                    RemakeDirectory(cacheDir);
                }
            }
            return(cacheDir);
        }
Ejemplo n.º 11
0
        public void Run(BuildTarget target,
                        NodeData node,
                        ConnectionPointData inputPoint,
                        ConnectionData connectionToOutput,
                        Dictionary <string, List <Asset> > inputGroupAssets,
                        List <string> alreadyCached,
                        Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node);

            var bundleNames    = inputGroupAssets.Keys.ToList();
            var bundleVariants = new Dictionary <string, List <string> >();

            // get all variant name for bundles
            foreach (var name in bundleNames)
            {
                bundleVariants[name] = new List <string>();
                var assets = inputGroupAssets[name];
                foreach (var a in assets)
                {
                    var variantName = a.variantName;
                    if (!bundleVariants[name].Contains(variantName))
                    {
                        bundleVariants[name].Add(variantName);
                    }
                }
            }

            int validNames = 0;

            foreach (var name in bundleNames)
            {
                var assets = inputGroupAssets[name];
                // we do not build bundle without any asset
                if (assets.Count > 0)
                {
                    validNames += bundleVariants[name].Count;
                }
            }

            AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames];

            int bbIndex = 0;

            foreach (var name in bundleNames)
            {
                foreach (var v in bundleVariants[name])
                {
                    var bundleName = name;
                    var assets     = inputGroupAssets[name];

                    if (assets.Count <= 0)
                    {
                        continue;
                    }

                    bundleBuild[bbIndex].assetBundleName    = bundleName;
                    bundleBuild[bbIndex].assetBundleVariant = v;
                    bundleBuild[bbIndex].assetNames         = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray();
                    ++bbIndex;
                }
            }


            BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)node.BundleBuilderBundleOptions[target], target);


            var output = new Dictionary <string, List <Asset> >();

            output[key] = new List <Asset>();

            var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir);

            // add manifest file
            bundleNames.Add(BuildTargetUtility.TargetToAssetBundlePlatformName(target));
            foreach (var path in generatedFiles)
            {
                var fileName = Path.GetFileName(path);
                if (IsFileIntendedItem(fileName, bundleNames))
                {
                    output[key].Add(Asset.CreateAssetWithImportPath(path));
                }
                else
                {
                    Debug.LogWarning(node.Name + ":Irrelevant file found in assetbundle cache folder:" + fileName);
                }
            }

            Output(connectionToOutput, output, alreadyCached);
        }
        public void Run(BuildTarget target,
                        NodeData node,
                        IEnumerable <PerformGraph.AssetGroups> incoming,
                        IEnumerable <ConnectionData> connectionsToOutput,
                        PerformGraph.Output Output,
                        Action <NodeData, string, float> progressFunc)
        {
            if (incoming == null)
            {
                return;
            }

            var aggregatedGroups = new Dictionary <string, List <AssetReference> >();

            aggregatedGroups[key] = new List <AssetReference>();

            if (progressFunc != null)
            {
                progressFunc(node, "Collecting all inputs...", 0f);
            }

            foreach (var ag in incoming)
            {
                foreach (var name in ag.assetGroups.Keys)
                {
                    if (!aggregatedGroups.ContainsKey(name))
                    {
                        aggregatedGroups[name] = new List <AssetReference>();
                    }
                    aggregatedGroups[name].AddRange(ag.assetGroups[name].AsEnumerable());
                }
            }

            var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node);

            var bundleNames    = aggregatedGroups.Keys.ToList();
            var bundleVariants = new Dictionary <string, List <string> >();

            if (progressFunc != null)
            {
                progressFunc(node, "Building bundle variants map...", 0.2f);
            }

            // get all variant name for bundles
            foreach (var name in aggregatedGroups.Keys)
            {
                if (!bundleVariants.ContainsKey(name))
                {
                    bundleVariants[name] = new List <string>();
                }
                var assets = aggregatedGroups[name];
                foreach (var a in assets)
                {
                    var variantName = a.variantName;
                    if (!bundleVariants[name].Contains(variantName))
                    {
                        bundleVariants[name].Add(variantName);
                    }
                }
            }

            int validNames = 0;

            foreach (var name in bundleNames)
            {
                var assets = aggregatedGroups[name];
                // we do not build bundle without any asset
                if (assets.Count > 0)
                {
                    validNames += bundleVariants[name].Count;
                }
            }

            AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames];

            int bbIndex = 0;

            foreach (var name in bundleNames)
            {
                foreach (var v in bundleVariants[name])
                {
                    var assets = aggregatedGroups[name];

                    if (assets.Count <= 0)
                    {
                        continue;
                    }

                    bundleBuild[bbIndex].assetBundleName    = name;
                    bundleBuild[bbIndex].assetBundleVariant = v;
                    bundleBuild[bbIndex].assetNames         = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray();
                    ++bbIndex;
                }
            }

            if (progressFunc != null)
            {
                progressFunc(node, "Building Asset Bundles...", 0.7f);
            }

            AssetBundleManifest m = BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)node.BundleBuilderBundleOptions[target], target);

            var output = new Dictionary <string, List <AssetReference> >();

            output[key] = new List <AssetReference>();

            var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir);

            // add manifest file
            bundleVariants.Add(BuildTargetUtility.TargetToAssetBundlePlatformName(target).ToLower(), new List <string> {
                null
            });
            foreach (var path in generatedFiles)
            {
                var fileName = path.Substring(bundleOutputDir.Length + 1);
                if (IsFileIntendedItem(fileName, bundleVariants))
                {
                    output[key].Add(AssetReferenceDatabase.GetAssetBundleReference(path));
                }
            }

            if (Output != null)
            {
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();
                Output(dst, output);
            }

            AssetBundleBuildReport.AddBuildReport(new AssetBundleBuildReport(node, m, bundleBuild, output[key], aggregatedGroups, bundleVariants));
        }
        public void Setup(BuildTarget target,
                          NodeData node,
                          IEnumerable <PerformGraph.AssetGroups> incoming,
                          IEnumerable <ConnectionData> connectionsToOutput,
                          PerformGraph.Output Output)
        {
            // BundleBuilder do nothing without incoming connections
            if (incoming == null)
            {
                return;
            }

            var bundleNames    = incoming.SelectMany(v => v.assetGroups.Keys).Distinct().ToList();
            var bundleVariants = new Dictionary <string, List <string> >();

            // get all variant name for bundles
            foreach (var ag in incoming)
            {
                foreach (var name in ag.assetGroups.Keys)
                {
                    if (!bundleVariants.ContainsKey(name))
                    {
                        bundleVariants[name] = new List <string>();
                    }
                    var assets = ag.assetGroups[name];
                    foreach (var a in assets)
                    {
                        var variantName = a.variantName;
                        if (!bundleVariants[name].Contains(variantName))
                        {
                            bundleVariants[name].Add(variantName);
                        }
                    }
                }
            }

            // add manifest file
            var manifestName = BuildTargetUtility.TargetToAssetBundlePlatformName(target);

            bundleNames.Add(manifestName);
            bundleVariants[manifestName] = new List <string>()
            {
                ""
            };

            if (connectionsToOutput != null && Output != null)
            {
                UnityEngine.Assertions.Assert.IsTrue(connectionsToOutput.Any());

                var outputDict = new Dictionary <string, List <AssetReference> >();
                outputDict[key] = new List <AssetReference>();
                var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node);

                foreach (var name in bundleNames)
                {
                    foreach (var v in bundleVariants[name])
                    {
                        string         bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v;
                        AssetReference bundle     = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName));
                        AssetReference manifest   = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName + AssetBundleGraphSettings.MANIFEST_FOOTER));
                        outputDict[key].Add(bundle);
                        outputDict[key].Add(manifest);
                    }
                }

                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();
                Output(dst, outputDict);
            }
        }