当前位置:网站首页>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 )
边栏推荐
- Properties and methods of OS Library
- Heartbeat error attempted replay attack
- 三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
- 2020 Summary - Magic year, magic me
- SSH principle and public key authentication
- Canoe - the third simulation project - bus simulation - 3-2 project implementation
- Canoe-the second simulation project-xvehicle-1 bus database design (idea)
- Reptile learning 4 winter vacation series (3)
- Detailed explanation of classic process synchronization problems
- Usage of case when then else end statement
猜你喜欢
Summary of Shanghai Jiaotong University postgraduate entrance examination module firewall technology
TCP fast retransmission sack mechanism
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 13
Elevator dispatching (pairing project) ②
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
Usage of case when then else end statement
Automatic translation between Chinese and English
Btrace tells you how to debug online without restarting the JVM
Serialization oriented - pickle library, JSON Library
Some summaries of the 21st postgraduate entrance examination 823 of network security major of Shanghai Jiaotong University and ideas on how to prepare for the 22nd postgraduate entrance examination pr
随机推荐
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Simple understanding of generics
Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution
Heartbeat报错 attempted replay attack
Swagger and OpenAPI
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
Using terminal connection in different modes of virtual machine
re. Sub() usage
About the use of URL, href, SRC attributes
How to create a new virtual machine
Daemon xinted and logging syslogd
Common built-in modules
2021-10-20
(August 9, 2021) example exercise of air quality index calculation (I)
Here, the DDS tutorial you want | first experience of fastdds - source code compilation & Installation & Testing
IO stream ----- open
Polymorphic system summary
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Locust installation
Ternsort model integration summary