MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Create

Method Create

Source/Editor/Content/Proxy/CSharpProxy.cs:41–66  ·  view source on GitHub ↗

(string outputPath, object arg)

Source from the content-addressed store, hash-verified

39
40 /// <inheritdoc />
41 public override void Create(string outputPath, object arg)
42 {
43 // Load template
44 GetTemplatePath(out var templatePath);
45 var scriptTemplate = File.ReadAllText(templatePath);
46
47 // Find the module that this script is being added (based on the path)
48 var scriptNamespace = Editor.Instance.GameProject.Name;
49 var project = TryGetProjectAtFolder(outputPath, out var moduleName);
50 if (project != null)
51 {
52 scriptNamespace = moduleName.Length != 0 ? moduleName : project.Name;
53 }
54 scriptNamespace = scriptNamespace.Replace(" ", "");
55
56 // Format
57 var gameSettings = GameSettings.Load();
58 var scriptName = ScriptItem.CreateScriptName(outputPath);
59 var copyrightComment = string.IsNullOrEmpty(gameSettings.CopyrightNotice) ? string.Empty : string.Format("// {0}{1}{1}", gameSettings.CopyrightNotice, Environment.NewLine);
60 scriptTemplate = scriptTemplate.Replace("%copyright%", copyrightComment);
61 scriptTemplate = scriptTemplate.Replace("%class%", scriptName);
62 scriptTemplate = scriptTemplate.Replace("%namespace%", scriptNamespace);
63
64 // Save
65 File.WriteAllText(outputPath, scriptTemplate, Encoding.UTF8);
66 }
67
68 /// <inheritdoc />
69 public override string FileExtension => "cs";

Callers

nothing calls this directly

Calls 6

ReadAllTextMethod · 0.80
ReplaceMethod · 0.80
CreateScriptNameMethod · 0.80
FormatMethod · 0.80
WriteAllTextMethod · 0.80
LoadMethod · 0.45

Tested by

no test coverage detected