当前位置:网站首页>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 )
边栏推荐
- Performance features focus & JMeter & LoadRunner advantages and disadvantages
- (2021-08-20) web crawler learning 2
- QQ group collection
- Canoe: what is vtsystem
- QQ get group link, QR code
- os. Path built-in module
- Automatic translation between Chinese and English
- Appscan installation steps
- Enter the smart Park, and change begins here
- 本地Mysql忘记密码的修改方法(windows)
猜你喜欢
Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography
Digital simulation beauty match preparation -matlab basic operation No. 6
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
Function parameters (positional parameters, default value parameters, variable parameters, named keyword parameters, keyword parameters)
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 6
QQ group collection
OSI seven layer model & unit
Practical dry goods: deploy mini version message queue based on redis6.0
Here, the DDS tutorial you want | first experience of fastdds - source code compilation & Installation & Testing
随机推荐
Fundamentals of software testing
Canoe-the second simulation project-xvehicle-1 bus database design (idea)
Summary of collection: (to be updated)
Canoe - the third simulation project - bus simulation-1 overview
(August 9, 2021) example exercise of air quality index calculation (I)
How to deal with the relationship between colleagues
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 14
template<typename MAP, typename LIST, typename First, typename ... Keytypes > recursive call with indefinite parameters - beauty of Pan China
OSI seven layer model & unit
Capl: timer event
Introduction to Lichuang EDA
Simple understanding of seesion, cookies, tokens
本地Mysql忘记密码的修改方法(windows)
Common built-in modules
Video analysis
Common tips
C language compilation process
2021-10-20
Heartbeat启动后无反应
QQ get group link, QR code