@@ -55,22 +55,43 @@ <h2 id="create-entity">Creating an Entity</h2>
5555 Great! We have a simple < code > .Ecsact</ code > file we can build on. Now we
5656 can make a C# script in Unity, for our use it will be called
5757 < code > BasicExample.cs</ code > . This script will allow us to
58- < a href ="/docs/unity/entities "> create an entity</ a >
58+ < a href ="/docs/unity/entities "> create an entity</ a > with some components
59+ </ p >
60+ < p > We'll start by declaring the components we'll be adding to our entity</ p >
61+ < code-block-variation >
62+ < pre codeBlockVariationOption > < code prism language ="csharp ">
63+ // Declare an Example component type
64+ var exampleComponent = new example.Example {{'{'}}
65+ example_value = 5,
66+ {{'}'}};
67+
68+ var removeComponent = new example.ToBeRemoved {{'{'}}{{'}'}};
69+ </ code > </ pre >
70+ </ code-block-variation >
71+
72+ < p >
73+ Components can be declared from the namespace that is dervied from the
74+ name of your package in the < code > .ecsact</ code > file. Now that we have
75+ our components, we can add them to a newly created entity using the
76+ Runner's < code > executionOptions</ code >
5977 </ p >
6078
6179 < code-block-variation >
6280 < pre codeBlockVariationOption > < code prism language ="csharp ">
63- // The Registry is a convenient way to access the Core api.
64- int entityId = Ecsact.Defaults.Registry.CreateEntity();
81+ Ecsact.Defaults.Runner.executionOptions
82+ .CreateEntity()
83+ .AddComponent(exampleComponent)
84+ .AddComponent(removeComponent);
6585 </ code > </ pre >
6686 </ code-block-variation >
6787 </ section >
6888 < section >
6989 < h2 id ="listeners "> Runtime Listeners</ h2 >
7090 < p >
7191 The < a href ="docs/unity/defaults "> Runtime</ a > gives you access to
72- everything used during Unity's runtime. In this case, we can add listeners
73- for changes to component state
92+ everything used during Unity's runtime. For example, listeners can be
93+ added for changes to component state or when an entity is created or
94+ destroyed.
7495 </ p >
7596
7697 < code-block-variation >
@@ -79,62 +100,30 @@ <h2 id="listeners">Runtime Listeners</h2>
79100 List< {{'System.Action'}}> cleanUpFns = new();
80101
81102 cleanUpFns.AddRange(new[] {{'{'}}
82- // Callback that's invoked on the removal of a component
83- Ecsact.Defaults.Runtime.OnRemoveComponent< {{'example.ToBeRemoved'}}> ((entity, component) => {{'{'}}
84- Debug.Log("Example component removed");
103+ // Callback invoked when Example component is added
104+ Ecsact.Defaults.Runtime.OnInitComponent< {{'example.Example'}}> ((entity, component) => {{'{'}}
105+ Debug.Log("Example component added");
106+ Debug.Log(component.example_value);
85107 {{'}'}}),
86- // Callback that's invoked on the removal of a component
108+ // Callback invoked when Example component is updated
87109 Ecsact.Defaults.Runtime.OnUpdateComponent< {{'example.Example'}}> ((entity, component) => {{'{'}}
88110 Debug.Log(component.example_value);
111+ {{'}'}}),
112+ // Callback invoked when Example component is removed
113+ Ecsact.Defaults.Runtime.OnRemoveComponent< {{'example.ToBeRemoved'}}> ((entity, component) => {{'{'}}
114+ Debug.Log("Example component removed");
115+ {{'}'}}),
116+ // Callback invoked on the creation of an entity
117+ Ecsact.Defaults.Runtime.OnEntityCreated((entityId, placeholderId) => {{'{'}}
118+ Debug.Log("Entity created");
89119 {{'}'}})
90120 {{'}'}});
91121 </ code > </ pre >
92122 </ code-block-variation >
93-
94- < p >
95- Whenever a component is updated and removed, these callbacks will be
96- invoked. We'll go over how to update components later, but first we'll
97- declare the components to add to our newly created entity
98- </ p >
99123 </ section >
100124
101125 < section >
102- < h2 id ="components "> Declaring and adding components</ h2 >
103- < code-block-variation >
104- < pre codeBlockVariationOption > < code prism language ="csharp ">
105- // Declare an Example component type
106- var exampleComponent = new example.Example {{'{'}}
107- example_value = 5,
108- {{'}'}};
109-
110- var removeComponent = new example.ToBeRemoved {{'{'}}{{'}'}};
111- </ code > </ pre >
112- </ code-block-variation >
113-
114- < p >
115- Components can be declared from the namespace that is dervied from the
116- name of your package in the < code > .ecsact</ code > file. Now that we have
117- our components, we can add it to an entity with its id using the
118- < code > Registry</ code >
119- </ p >
120-
121- < code-block-variation >
122- < pre codeBlockVariationOption > < code prism language ="csharp ">
123- // Add components to your entity
124- Ecsact.Defaults.Registry.AddComponent(
125- entityId,
126- exampleComponent
127- );
128-
129- Ecsact.Defaults.Registry.AddComponent(
130- entityId,
131- removeComponent
132- );
133- </ code > </ pre >
134- </ code-block-variation >
135- </ section >
136- < section >
137- < p > Then, when the class is destroyed the listeners will be cleaned up</ p >
126+ < p > When the class is destroyed the listeners will be cleaned up</ p >
138127 < code-block-variation >
139128 < pre codeBlockVariationOption > < code prism language ="csharp ">
140129 void OnDestroy() {{'{'}}
0 commit comments