-
Notifications
You must be signed in to change notification settings - Fork 0
Initial Bases Development
A component is a data structure that inherits from IComponentData, there is no more science to it 😁. Here is an example
using Unity.Entities;
public struct ExampleComponent : IComponentData
{
public int number;
}
To create an Entity we will need an EntityManger. In order to create this EntityManager we will create a class that inherits from monobehaviour, in this class we only use the Start method(regarding the monobehaviour methods, you can make more classes to preserve the clean code).
In the start method, we will create an entity manager like this.
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
This entity manager will handle a lot of things in our entity, such as creation of entities or setting components to these entities.
In order to create a bunch of entities that will share the same components we will create an entity architecture. Like this:
EntityArchetype entityArchetype = entityManager.CreateArchetype(
typeof(ComponentName)
);
Then we will take this architecture and we will create a bunch of entities that will share this components.
NativeArray entityArray = new NativeArray(numberOfPlayersToSpawn, Allocator.Temp);
entityManager.CreateEntity(entityArchetype, entityArray);
A system will handle all the logic that we are going to apply to the components. So for each entity we are going to that the reference of a certain component a modify it the way we want. In this example we are modifying the level of the player, so we take the LevelComponent reference and we add 1 to his level attribute every frame.
public class LevelUpSystem : ComponentSystem
{
protected override void OnUpdate(){
Entities.ForEach((ref LevelComponent levelComponent) =>{
levelComponent.level += 1f * Time.DeltaTime;
});
}
}Home
C#
Game Design Patterns
- Command
- Flyweight pattern & Scriptable Objects
- Observer pattern
- State pattern
- Object Pool pattern
- Factory pattern
ECS
PlayFab
- Introduction
- Template Class
- Player Authentication
- Mobile Authentication
- Player Statistics
- Leaderboard
- Player Data
- Friends
Mirror