Ejemplo n.º 1
0
        void CreateModule()
        {
            if (!File.Exists(ScriptTemplate))
            {
                Debug.LogError("Missing Module Template file '" + ScriptTemplate + "'!");
                return;
            }
            if (!File.Exists(EditorScriptTemplate))
            {
                Debug.LogError("Missing Module Template file '" + EditorScriptTemplate + "'!");
                return;
            }

            // Script
            string template = File.ReadAllText(ScriptTemplate);

            if (!string.IsNullOrEmpty(template))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(ModuleFileName));
                var stream = File.CreateText(ModuleFileName);
                stream.Write(replaceVars(template));
                stream.Close();
            }
            else
            {
                Debug.LogError("Unable to load template file");
                return;
            }
            // Editor Script
            template = File.ReadAllText(EditorScriptTemplate);
            if (!string.IsNullOrEmpty(template))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(ModuleEditorFileName));
                var stream = File.CreateText(ModuleEditorFileName);
                stream.Write(replaceVars(template));
                stream.Close();
            }
            else
            {
                Debug.LogError("Unable to load editor template file");
                return;
            }
            AssetDatabase.Refresh();
            Close();
            EditorUtility.DisplayDialog("CG Module Wizard", "Scripts successfully created!", "OK");

            Selection.objects = new Object[2]
            {
                AssetDatabase.LoadMainAssetAtPath(ModuleFileName.Replace(Application.dataPath, "Assets")),
                AssetDatabase.LoadMainAssetAtPath(ModuleEditorFileName.Replace(Application.dataPath, "Assets"))
            };
        }
        /// <summary>
        /// Find all third party and private header includes in public engine headers.
        /// </summary>
        public static void FindThirdPartyIncludes(UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, string Architecture)
        {
            Log.TraceInformation("Looking for third party header includes in public engine header files (this may take a few minutes)...");

            TargetInfo    Target           = new TargetInfo(Platform, Configuration, Architecture);
            List <string> UncheckedModules = new List <string>();

            EngineHeaders     = new List <Header>();
            ThirdPartyHeaders = new List <Header>();

            // Create a rules assembly for the engine
            RulesAssembly EngineRulesAssembly = RulesCompiler.CreateEngineRulesAssembly();

            // Find all modules referenced by the current target
            List <FileReference> ModuleFileNames = RulesCompiler.FindAllRulesSourceFiles(RulesCompiler.RulesFileType.Module, GameFolders: null, ForeignPlugins: null, AdditionalSearchPaths: null);

            foreach (FileReference ModuleFileName in ModuleFileNames)
            {
                string ModuleName = Path.GetFileNameWithoutExtension(ModuleFileName.GetFileNameWithoutExtension());
                try
                {
                    ModuleRules RulesObject    = EngineRulesAssembly.CreateModuleRules(ModuleName, Target);
                    bool        bEngineHeaders = RulesObject.Type != ModuleRules.ModuleType.External;
                    foreach (string SystemIncludePath in RulesObject.PublicSystemIncludePaths)
                    {
                        FindHeaders(SystemIncludePath, bEngineHeaders ? EngineHeaders : ThirdPartyHeaders, bEngineHeaders);
                    }
                    foreach (string PublicIncludePath in RulesObject.PublicIncludePaths)
                    {
                        FindHeaders(PublicIncludePath, bEngineHeaders ? EngineHeaders : ThirdPartyHeaders, bEngineHeaders);
                    }
                }
                catch (Exception)
                {
                    // Ignore, some modules may fail here.
                    UncheckedModules.Add(ModuleName);
                }
            }

            // Search for illegal includes.
            List <IncludePath> ThirdPartyIncludes = new List <IncludePath>();
            List <IncludePath> PrivateIncludes    = new List <IncludePath>();

            CheckIfThirdPartyHeadersAreIncluded(ThirdPartyIncludes, PrivateIncludes);

            // List all of the included 3rd party headers unless their name matches with any of the engine header.
            if (ThirdPartyIncludes.Count > 0)
            {
                // Remove ambiguous headers
                for (int IncludeIndex = ThirdPartyIncludes.Count - 1; IncludeIndex >= 0; --IncludeIndex)
                {
                    if (FindHeader(EngineHeaders, ThirdPartyIncludes[IncludeIndex].OtherHeader.Name) != null)
                    {
                        ThirdPartyIncludes.RemoveAt(IncludeIndex);
                    }
                }
                if (ThirdPartyIncludes.Count > 0)
                {
                    Log.TraceInformation("Warning: Found {0} third party header includes in public engine headers. Third party headers should only be included in private engine headers.", ThirdPartyIncludes.Count);
                    foreach (IncludePath HeaderPath in ThirdPartyIncludes)
                    {
                        if (FindHeader(EngineHeaders, HeaderPath.OtherHeader.Name) == null)
                        {
                            Log.TraceInformation("{0} includes {1}.", HeaderPath.PublicHeaderPath, HeaderPath.OtherHeader.Path);
                        }
                    }
                }
            }

            // List all private engine headers included from public engine headers
            if (PrivateIncludes.Count > 0)
            {
                Log.TraceInformation("Warning: Found {0} private engine header includes in public engine headers. Private engine headers should not be included in public engine headers.", PrivateIncludes.Count);
            }
            foreach (IncludePath HeaderPath in PrivateIncludes)
            {
                Log.TraceInformation("{0} includes {1}.", HeaderPath.PublicHeaderPath, HeaderPath.OtherHeader.Path);
            }
            if (PrivateIncludes.Count == 0 && ThirdPartyIncludes.Count == 0)
            {
                Log.TraceInformation("Finished looking for third party includes. Nothing found.");
            }
            if (UncheckedModules.Count > 0)
            {
                Log.TraceInformation("Warning: The following modules could not be checked (exception while trying to create ModuleRules object):");
                for (int ModuleIndex = 0; ModuleIndex < UncheckedModules.Count; ++ModuleIndex)
                {
                    Log.TraceInformation("  {0}", UncheckedModules[ModuleIndex]);
                }
            }
        }