当前位置:网站首页>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 )
边栏推荐
- Usage of with as
- Is Sanli futures safe? How to open a futures account? How to reduce the handling charge of futures at present?
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 9
- Heartbeat报错 attempted replay attack
- OSI seven layer model & unit
- Postman advanced
- How do std:: function and function pointer assign values to each other
- CAPL: on sysVar_ Update difference on sysvar
- QQ set group information
- Canoe - the third simulation project - bus simulation-1 overview
猜你喜欢
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
Games101 Lesson 8 shading 2 Notes
Introduction to Lichuang EDA
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
Day01 preliminary packet capture
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 7
Elevator dispatching (pairing project) ②
DDS-YYDS
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Detailed array expansion analysis --- take you step by step analysis
随机推荐
Postman advanced
Locust installation
Safety testing aspects
本地Mysql忘记密码的修改方法(windows)[通俗易懂]
Data transmission in the network
SSH原理和公钥认证
Canoe - description of common database attributes
Fundamentals of software testing
Introduction of network security research direction of Shanghai Jiaotong University
Enter the smart Park, and change begins here
Heartbeat报错 attempted replay attack
Canoe: the difference between environment variables and system variables
Function introduction of canbedded component
Shift EC20 mode and switch
VPS installation virtualmin panel
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 10
2021-10-20
(August 10, 2021) web crawler learning - Chinese University ranking directed crawler
QQ one click cookie acquisition
Climb Phoenix Mountain on December 19, 2021