Skip to content

Hello World Entitas Redux Plugin

Jeff Campbell edited this page Jun 19, 2021 · 5 revisions

Overview

With Genesis v2, code generation plugins are written as classes in .Net Core assemblies that are loaded by the Genesis.CLI application. This tutorial walks through how to create a new code generation plugin that can also use EntitasRedux data step by step.

Steps

  • Create a new .Net Core Assembly Project targeting 3.1.X.

  • Add the EntitasRedux.Core.Plugins Nuget package to your project.

  • Create a new class ExampleERCodeGeneratorPlugin. Add the following file contents below.
using System.Linq;
using EntitasRedux.Core.Plugins;
using Genesis.Plugin;

namespace ExamplePlugin
{
    public class ExampleERCodeGeneratorPlugin : ICodeGenerator
    {
        /// <inheritdoc />
        public string Name => nameof(ExampleERCodeGeneratorPlugin);

        /// <inheritdoc />
        public int Priority => 0;

        /// <inheritdoc />
        public bool RunInDryMode => false;

        /// <inheritdoc />
        public CodeGenFile[] Generate(CodeGeneratorData[] data)
        {
            // Get all component data instances
            var componentData = data.OfType<ComponentData>();

            // Get all context data instances
            var contextData = data.OfType<ContextData>();

            // TODO Do something to generate additional Entitas Redux related classes.
            return new CodeGenFile[0];
        }
    }
}
  • Build the project and copy the contents of the bin folder to the Plugins\ERPlugins folder of your GenesisCLI installation along with any of the other assemblies it relies on.
  • Add the new plugin to your genesis config by either:
    • If using Unity, you can update your GenesisSettings asset to include your new config by selecting the Auto Import button on the inspector OR.
    • Generate a new Genesis config by opening the command line to the GenesisCLI installation folder and entering dotnet genesis.cli.dll config create OR.
    • Opening an existing genesis config and add the full type name (including namespace) of your HelloWorldPlugin to the value entry of the key-value-pairs with keys Genesis.PreProcessors and Genesis.AllPreProcessors.

Redacted Example Json

{
  "keyValuePairs": [
    {
      "key": "Genesis.CodeGenerators",
      "value": "ExamplePlugin.ExampleERCodeGeneratorPlugin"
    },
    {
      "key": "Genesis.CodeGenerators",
      "value": "ExamplePlugin.ExampleERCodeGeneratorPlugin"
    }
  ]
}

After Auto-Import on GenesisSettings

Done! From this point on when running code generation your new ExampleERCodeGeneratorPlugin should also execute.