Пример #1
0
        public static NPath BuildSlimGameManagers(BuildTarget target, string[] scenes, bool development, string typeDBDirectory)
        {
            NPath tempPath;

            WriteManagerParameters mParams;
            WriteParameters        wParams;

            WriteCommand[] writeCommands;
            PreloadInfo    preloadInfo;

            // Setup
            {
                tempPath = TempDataPath;
                tempPath.CreateDirectory();
                tempPath.Combine("Resources").MakeAbsolute().CreateDirectory();

                //work around bug in unity's TypeDBHelper where it assumes Library/Type will exist
                new NPath("Library/Type").EnsureDirectoryExists();

                mParams = new WriteManagerParameters
                {
                    settings = new UnityEditor.Build.Content.BuildSettings
                    {
                        target     = target,
                        group      = UnityEditor.BuildPipeline.GetBuildTargetGroup(target),
                        buildFlags = development ? ContentBuildFlags.DevelopmentBuild : ContentBuildFlags.None,
                        typeDB     = TypeDbHelper.GetForPlayer(typeDBDirectory)
                    },
                    globalUsage  = ContentBuildInterface.GetGlobalUsageFromGraphicsSettings(),
                    referenceMap = new BuildReferenceMap()
                };

                wParams = new WriteParameters
                {
                    settings     = mParams.settings,
                    globalUsage  = mParams.globalUsage,
                    referenceMap = mParams.referenceMap,
                    usageSet     = new BuildUsageTagSet()
                };

                writeCommands = new[]
                {
                    new WriteCommand
                    {
                        fileName         = "unity_builtin_extra",
                        internalName     = "Resources/unity_builtin_extra",
                        serializeObjects = new List <SerializationInfo>()
                    },
                    new WriteCommand
                    {
                        fileName         = "globalgamemanagers.assets",
                        internalName     = "globalgamemanagers.assets",
                        serializeObjects = new List <SerializationInfo>()
                    }
                };

                preloadInfo = new PreloadInfo
                {
                    preloadObjects = new List <ObjectIdentifier>()
                };
            }

            // Dependency Calculation
            {
                var dependencyResults = ContentBuildInterface.CalculatePlayerDependenciesForGameManagers(mParams.settings, mParams.globalUsage, wParams.usageSet);

                var referencedObjects = dependencyResults.referencedObjects.ToArray();
                var types             = ContentBuildInterface.GetTypeForObjects(referencedObjects);

                for (int i = 0; i < referencedObjects.Length; i++)
                {
                    if (referencedObjects[i].guid == k_UnityBuiltinResources)
                    {
                        // unity default resources contain scripts that need to be preloaded
                        if (types[i] == typeof(MonoScript))
                        {
                            preloadInfo.preloadObjects.Add(referencedObjects[i]);
                        }

                        // Prebuild player specific default resources file, don't remap local identifiers
                        mParams.referenceMap.AddMapping("Library/unity default resources", referencedObjects[i].localIdentifierInFile, referencedObjects[i]);
                    }
                    else if (referencedObjects[i].guid == k_UnityBuiltinExtraResources)
                    {
                        if (types[i] == typeof(Shader))
                        {
                            var command = writeCommands[0];
                            // Resources/unity_builtin_extra
                            // Don't remap local identifiers
                            var info = new SerializationInfo
                            {
                                serializationObject = referencedObjects[i],
                                serializationIndex  = referencedObjects[i].localIdentifierInFile
                            };

                            command.serializeObjects.Add(info);
                            mParams.referenceMap.AddMapping(command.internalName, info.serializationIndex, info.serializationObject);
                        }
                        else
                        {
                            var command = writeCommands[1];
                            // globalgamemanagers.assets
                            // Squash / Remap local identifiers, starting at 2 (PreloadData 1)
                            var info = new SerializationInfo
                            {
                                serializationObject = referencedObjects[i],
                                serializationIndex  = command.serializeObjects.Count + 2
                            };

                            command.serializeObjects.Add(info);
                            mParams.referenceMap.AddMapping(command.internalName, info.serializationIndex, info.serializationObject);
                        }
                    }
                    else if (types[i] == typeof(MonoScript))
                    {
                        //globalgamemanagers.assets
                        //error because we can't support all the ggm features in slim builds
                    }
                    else
                    {
                        //globalgamemanagers.assets
                        //error because we can't support all the ggm features in slim builds
                    }
                }
            }

            // Writing globalgamemanagers
            {
                var writeResults = ContentBuildInterface.WriteGameManagersSerializedFile(tempPath.ToString(), mParams);
                EditorUtility.ClearProgressBar();
                //if (writeResults.serializedObjects.Count == 0) return "FAIL";
            }

            // Writing globalgamemanagers.assets
            {
                wParams.writeCommand = writeCommands[1];
                wParams.preloadInfo  = preloadInfo;
                var writeResults = ContentBuildInterface.WriteSerializedFile(tempPath.ToString(), wParams);
                EditorUtility.ClearProgressBar();
                //if (writeResults.serializedObjects.Count == 0) return "FAIL";
            }

            // Writing unity_builtin_extra"
            {
                wParams.writeCommand = writeCommands[0];
                wParams.preloadInfo  = null;

                // unity_builtin_extras requires absolutepath writing, so fixup the internalName and referenceMap for this
                wParams.writeCommand.internalName = tempPath.Combine(wParams.writeCommand.internalName).MakeAbsolute().ToString();
                wParams.referenceMap.AddMappings(wParams.writeCommand.internalName, wParams.writeCommand.serializeObjects.ToArray(), true);

                var writeResults = ContentBuildInterface.WriteSerializedFile(tempPath.Combine("Resources").ToString(), wParams);
                EditorUtility.ClearProgressBar();
                //if (writeResults.serializedObjects.Count == 0) return "FAIL";
            }

            {
                var parameters = new BundleBuildParameters(mParams.settings.target, mParams.settings.group, TempStreamingAssetsPath.ToString());
                parameters.BundleCompression = UnityEngine.BuildCompression.Uncompressed;
                parameters.ScriptInfo        = mParams.settings.typeDB;

                // Writing scenes.bundle
                {
                    WriteSceneBundles(parameters, scenes);
                    //if (???) return "FAIL";
                }

                // Writing resources.bundle
                {
                    WriteResourcesBundles(parameters);
                    //if (???) return "FAIL";
                }

                {
                    WriteRenderPipelineBundles(parameters);
                    //if (???) return "FAIL";
                }
            }

            return(tempPath);
        }