当前位置:网站首页>Entitas learning [iv] other common knowledge points
Entitas learning [iv] other common knowledge points
2022-07-04 11:31:00 【Mercury Note】
EntityIndex
[Game, Input, UI]
public class NumberComponent : IComponent
{
[EntityIndex]
public int number;
}
It is written as follows , When an attribute of a component has this tag ,Entitas When generating code based on components, the method to find based on this property will be generated , In a specified context , This attribute can be used as a unique id, Find the exact entity based on this .
It doesn't have to be int type ,string And so on.
Contexts.sharedInstance.game.GetEntitiesWithNumber(666);
The above code works everywhere , Even in monobehaviour In the script , But it is not recommended to access outside the framework Entitas Things inside .
GetEntitiesWithNumber This function only specifies EntityIndex Properties of will be generated .
public static class ContextsExtensions {
public static System.Collections.Generic.HashSet<GameEntity> GetEntitiesWithNumber(this GameContext context, int number) {
return ((Entitas.EntityIndex<GameEntity, int>)context.GetEntityIndex(Contexts.Number)).GetEntities(number);
}
public static System.Collections.Generic.HashSet<InputEntity> GetEntitiesWithNumber(this InputContext context, int number) {
return ((Entitas.EntityIndex<InputEntity, int>)context.GetEntityIndex(Contexts.Number)).GetEntities(number);
}
public static System.Collections.Generic.HashSet<UIEntity> GetEntitiesWithNumber(this UIContext context, int number) {
return ((Entitas.EntityIndex<UIEntity, int>)context.GetEntityIndex(Contexts.Number)).GetEntities(number);
}
}
Event
It is written as follows
[Event(EventTarget.Any, EventType.Added)]
public class NumberComponent : IComponent
{
[EntityIndex]
public int number;
}
In the use of the Event after , The generated code will be in this folder .
One of the
public interface IAnyNumberListener {
void OnAnyNumber(GameEntity entity, int number);
}
Inherit this interface rewrite OnAnyNumber Method ,
When NumberComponent When a component is added or deleted
Will be called back , When calling back, the value and entity of the component are passed in .
EventTarget There are two kinds of ,Any and Self
- The tag Any Of , All inherited IAnyNumberListener Of OnAnyNumber Will be called back , Not limited to Entitas Class .
- The tag Self Of , Only inheritance is limited IAnyNumberListener With NumberComponent The entity class of the component will be notified , So this kind of writing , We also need to be in our own script , Redefine the correlation by distributing classes context Below Entity, Let him inherit IAnyNumberListener Rewrite method .
Parameters EventType There are two options
public enum EventType
{
Added,
Removed,
}
Specify to call when the component is added or deleted
In fact, this label is added ,Entitas Will automatically generate a reaction system
public sealed class AnyNumberEventSystem : Entitas.ReactiveSystem<GameEntity> {
readonly Entitas.IGroup<GameEntity> _listeners;
readonly System.Collections.Generic.List<GameEntity> _entityBuffer;
readonly System.Collections.Generic.List<IAnyNumberListener> _listenerBuffer;
public AnyNumberEventSystem(Contexts contexts) : base(contexts.game) {
_listeners = contexts.game.GetGroup(GameMatcher.AnyNumberListener);
_entityBuffer = new System.Collections.Generic.List<GameEntity>();
_listenerBuffer = new System.Collections.Generic.List<IAnyNumberListener>();
}
protected override Entitas.ICollector<GameEntity> GetTrigger(Entitas.IContext<GameEntity> context) {
return Entitas.CollectorContextExtension.CreateCollector(
context, Entitas.TriggerOnEventMatcherExtension.Added(GameMatcher.Number)
);
}
protected override bool Filter(GameEntity entity) {
return entity.hasNumber;
}
protected override void Execute(System.Collections.Generic.List<GameEntity> entities) {
foreach (var e in entities) {
var component = e.number;
foreach (var listenerEntity in _listeners.GetEntities(_entityBuffer)) {
_listenerBuffer.Clear();
_listenerBuffer.AddRange(listenerEntity.anyNumberListener.value);
foreach (var listener in _listenerBuffer) {
listener.OnAnyNumber(e, component.number);
}
}
}
}
}
Different systems that generate different tags can change the tags themselves and then go in to see what is different .
The difference between different labels I mentioned above can be verified in this way .
Next, it will be recorded with Entitas Record Endless ball Key points of the case .
other
Adding Feature When , Different Feature The addition order of Feature Inside System The order of execution is influential , Therefore, when doing more in-depth, you should clarify when adding Feature Between the execution sequence of their own to do System The impact of the order of execution , That is, if two System Of Trigger identical , Then if two System When the execution order will affect the result , Consider two System Of Feature The order in which they are added , See if you want to belong Feature Changes . If Feature identical , Consider two System In this Feature The order in which they are added .
Reference resources
Unity Framework exploration ——ECS framework Entitas The basic concept of this chapter
EntityComponentSystem framework Entitas Multi context response system ( Four )
边栏推荐
- Lvs+kept realizes four layers of load and high availability
- Properties and methods of OS Library
- Detailed array expansion analysis --- take you step by step analysis
- regular expression
- C language compilation process
- Summary of automated testing framework
- 三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
- Video analysis
- Four sorts: bubble, select, insert, count
- Introduction of network security research direction of Shanghai Jiaotong University
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
Summary of collection: (to be updated)
Force buckle 142 Circular linked list II
F12 clear the cookies of the corresponding web address
Simple understanding of seesion, cookies, tokens
Canoe - description of common database attributes
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
Reptile learning 4 winter vacation series (3)
Global function Encyclopedia
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
Heartbeat报错 attempted replay attack
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
TCP fast retransmission sack mechanism
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
Using terminal connection in different modes of virtual machine
Reptile learning 3 (winter vacation learning)
OSI seven layer reference model
Object. Assign () & JS (= >) arrow function & foreach () function
Postman advanced
thread
Function introduction of canbedded component
OSI model notes
SQL greatest() function instance detailed example
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Decrypt the advantages of low code and unlock efficient application development
Canoe test: two ways to create CAPL test module
os. Path built-in module
Getting started with window functions