|
1 | 1 | <article> |
2 | | - <h1>Implementing Systems in Unity</h1> |
| 2 | + <h1 id="title">Implementing Systems in Unity</h1> |
3 | 3 | <p> |
4 | | - The Ecsact Unity Integration allows implementations of your declared |
5 | | - systems. |
| 4 | + The Ecsact Unity integration provides a convenient way to implement your |
| 5 | + systems in C# or WebAssembly. |
6 | 6 | </p> |
| 7 | + |
7 | 8 | <section> |
8 | | - <h2>System Declaration</h2> |
| 9 | + <h2 id="csharp-system-impl">C# System Implementation</h2> |
| 10 | + <p> |
| 11 | + To enable C# system implementations open your Unity project and go to |
| 12 | + <strong |
| 13 | + >Project Settings <span class="i24">arrow_right</span> Ecsact |
| 14 | + <span class="i24">arrow_right</span> System Implementations |
| 15 | + </strong> |
| 16 | + and change <strong>Source</strong> to <strong>C#</strong>. In addition to |
| 17 | + setting the source to C# you must also give a C# Assembly. The specified |
| 18 | + C# Assembly must contain your C# system implementation functions. If |
| 19 | + you're not familiar with C# Assemblies and Unity, see Unity's |
| 20 | + <a |
| 21 | + target="_blank" |
| 22 | + href="https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html" |
| 23 | + ><span class="i24">open_in_new</span> Assembly Definitions |
| 24 | + documentation</a |
| 25 | + >. |
| 26 | + </p> |
| 27 | + <p></p> |
9 | 28 | <p> |
10 | | - Systems have a <code>C# Attribute</code> in its implementation. The type |
11 | | - name of the system is put here to get the correct <code>context</code>. |
12 | | - The context holds the logic of the system. This includes getting |
13 | | - components, generating entities and retrieving data on actions. |
| 29 | + C# System implementations must be a <code>public</code> |
| 30 | + <code>static</code> function that returns <code>void</code> with 1 |
| 31 | + parameter of type <code>EcsactRuntime.SystemExecutionContext</code>. Be |
| 32 | + very conscientious of which methods in context are called. |
| 33 | + <a routerLink="/docs/system-impl" |
| 34 | + >Read more about system implementations to know what can and cannot be |
| 35 | + called.</a |
| 36 | + > |
14 | 37 | </p> |
| 38 | + <h3>Example</h3> |
15 | 39 | <code-block-variation> |
16 | 40 | <pre codeBlockVariationOption><code prism language="csharp"> |
17 | | -[Ecsact.DefaultSystemImpl(typeof(example.ExampleSystem))] |
18 | | -public static void AddToExampleSystem(EcsactRuntime.SystemExecutionContext context) {{'{'}} |
19 | | - // Get component from the context |
20 | | - var value = context.Get<{{'example.Example'}}>(); |
21 | | -{{'}'}} |
| 41 | + [Ecsact.DefaultSystemImpl(typeof(example.ExampleSystem))] |
| 42 | + public static void AddToExampleSystem(EcsactRuntime.SystemExecutionContext context) {{'{'}} |
| 43 | + // Get component from the context |
| 44 | + var myExampleComponent = context.Get<{{'example.Example'}}>(); |
| 45 | + {{'}'}} |
22 | 46 | </code></pre> |
23 | 47 | </code-block-variation> |
| 48 | + </section> |
24 | 49 |
|
| 50 | + <section> |
| 51 | + <h2 id="wasm-system-impl">Wasm System Implementations</h2> |
25 | 52 | <p> |
26 | | - It's essential that the system is both public and static. In addition, it |
27 | | - needs to be part of the assembly that can be generated alongside your |
28 | | - .Ecsact file in <code>edit -> Project Settings -> Ecsact</code> |
| 53 | + To enable Wasm system implementations open your Unity project and go to |
| 54 | + <strong |
| 55 | + >Project Settings <span class="i24">arrow_right</span> Ecsact |
| 56 | + <span class="i24">arrow_right</span> System Implementations |
| 57 | + </strong> |
| 58 | + and change <strong>Source</strong> to <strong>WebAssembly</strong>. A |
| 59 | + <code>.wasm</code> file may be specified in these settings for each |
| 60 | + system. Learn more about Wasm system implementations in the |
| 61 | + <a routerLink="/docs/system-impl-wasm" |
| 62 | + >Wasm Systems Overview documentation</a |
| 63 | + >. |
29 | 64 | </p> |
30 | 65 | </section> |
31 | 66 | </article> |
0 commit comments