This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e66495f
commit 3b7c48d
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
workers/unity/Packages/io.improbable.gdk.debug/.codegen/Source/ComponentVisualElementJob.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using Improbable.Gdk.CodeGeneration.FileHandling; | ||
using Improbable.Gdk.CodeGeneration.Jobs; | ||
using Improbable.Gdk.CodeGeneration.Model.Details; | ||
|
||
namespace Improbable.Gdk.CodeGenerator | ||
{ | ||
public class ComponentVisualElementJob : CodegenJob | ||
{ | ||
private const string DebugAsmdefFileName = "Improbable.Gdk.Generated.Debug.asmdef"; | ||
private readonly string relativeOutputPath = Path.Combine("improbable", "debugextensions"); | ||
|
||
public ComponentVisualElementJob(CodegenJobOptions options, IFileSystem fileSystem, DetailsStore detailsStore) : base(options.AsEditor(), fileSystem, detailsStore) | ||
{ | ||
const string jobName = nameof(ComponentVisualElementJob); | ||
Logger.Trace($"Initialising {jobName}."); | ||
|
||
Logger.Trace($"Adding job target for {DebugAsmdefFileName}"); | ||
AddJobTarget(Path.Combine(relativeOutputPath, DebugAsmdefFileName), () => DebugAssemblyGenerator.Generate()); | ||
|
||
var componentsToGenerate = detailsStore.Components.Values.ToList(); | ||
AddGenerators(relativeOutputPath, componentsToGenerate, component => ($"{component.Name}Renderer.cs", ComponentVisualElementGenerator.Generate)); | ||
Logger.Trace($"Added job targets for {componentsToGenerate.Count} components"); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...e.gdk.debug/.codegen/Source/Generators/DebugExtensions/ComponentVisualElementGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Improbable.Gdk.CodeGeneration.CodeWriter; | ||
using Improbable.Gdk.CodeGeneration.CodeWriter.Scopes; | ||
using Improbable.Gdk.CodeGeneration.Model.Details; | ||
|
||
namespace Improbable.Gdk.CodeGenerator | ||
{ | ||
public static class ComponentVisualElementGenerator | ||
{ | ||
public static CodeWriter Generate(UnityComponentDetails details) | ||
{ | ||
return CodeWriter.Populate(cgw => | ||
{ | ||
cgw.UsingDirectives( | ||
"Unity.Entities", | ||
"UnityEngine.UIElements", | ||
"Improbable.Gdk.Debug.WorkerInspector.Codegen" | ||
); | ||
|
||
cgw.Namespace(details.Namespace, ns => | ||
{ | ||
ns.Type($"public class {details.Name}Renderer : ComponentVisualElement", type => | ||
{ | ||
type.Line($"public override ComponentType ComponentType {{ get; }} = ComponentType.ReadOnly<{details.Name}.Component>();"); | ||
|
||
GenerateConstructor(type, details); | ||
GenerateUpdateMethod(type, details); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
private static void GenerateConstructor(TypeBlock typeBlock, UnityComponentDetails details) | ||
{ | ||
typeBlock.Method($"public {details.Name}Renderer() : base()", mb => | ||
{ | ||
mb.Line($"ComponentFoldout.text = \"{details.Name}\";"); | ||
mb.Line($"AuthoritativeToggle.SetEnabled(false);"); | ||
}); | ||
} | ||
|
||
private static void GenerateUpdateMethod(TypeBlock typeBlock, UnityComponentDetails details) | ||
{ | ||
typeBlock.Method("public override void Update(EntityManager manager, Entity entity)", mb => | ||
{ | ||
mb.Line($"AuthoritativeToggle.value = manager.HasComponent<{details.Name}.HasAuthority>(entity);"); | ||
}); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...improbable.gdk.debug/.codegen/Source/Generators/DebugExtensions/DebugAssemblyGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace Improbable.Gdk.CodeGenerator | ||
{ | ||
public static class DebugAssemblyGenerator | ||
{ | ||
public static string Generate() | ||
{ | ||
return @"{ | ||
""name"": ""Improbable.Gdk.Generated.Debug"", | ||
""references"": [ | ||
""Improbable.Gdk.Generated"", | ||
""Improbable.Gdk.Debug.WorkerInspector.Codegen"", | ||
""Unity.Entities"" | ||
], | ||
""includePlatforms"": [ | ||
""Editor"" | ||
], | ||
""excludePlatforms"": [], | ||
""allowUnsafeCode"": false, | ||
""overrideReferences"": false, | ||
""precompiledReferences"": [], | ||
""autoReferenced"": true, | ||
""defineConstraints"": [], | ||
""versionDefines"": [] | ||
} | ||
"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters