com.elestrago.unity.entitas-redux 3.7.2 → 3.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  ---
4
4
 
5
+ ## [3.7.4](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.7.4)
6
+
7
+ ### Fixed
8
+
9
+ - `ContextObserver` do not add already created entities to observe
10
+
11
+ ---
12
+
13
+ ## [3.7.3](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.7.3)
14
+
15
+ ### Changed
16
+
17
+ - Simplified `LinkableView` component subscription pattern by removing `IUnsubscribeEvent` dependency and replacing with
18
+ direct `OnEntityLinked`/`OnEntityUnlinked` lifecycle methods
19
+ - Updated event listener API to support `invokeOnSubscribe` parameter in add event listener method
20
+
21
+ ### Removed
22
+
23
+ - `UnsubscribeEvent` class and related utilities
24
+
25
+ ---
26
+
5
27
  ## [3.7.2](https://gitlab.com/elestrago-pkg/entitas-redux/-/tags/3.7.2)
6
28
 
7
29
  ### Fixed
@@ -341,6 +341,8 @@ namespace JCMG.EntitasRedux
341
341
  return entity;
342
342
  }
343
343
 
344
+ IEntity[] IContext.GetEntities() => GetEntities();
345
+
344
346
  /// <summary>
345
347
  /// Destroys all entities in the context.
346
348
  /// Throws an exception if there are still retained entities.
@@ -46,6 +46,8 @@ namespace JCMG.EntitasRedux
46
46
 
47
47
  event ContextGroupChanged OnGroupCreated;
48
48
 
49
+ IEntity[] GetEntities();
50
+
49
51
  void DestroyAllEntities();
50
52
 
51
53
  void AddEntityIndex(IEntityIndex entityIndex);
@@ -67,7 +69,7 @@ namespace JCMG.EntitasRedux
67
69
 
68
70
  bool HasEntity(TEntity entity);
69
71
 
70
- TEntity[] GetEntities();
72
+ new TEntity[] GetEntities();
71
73
 
72
74
  ArrayDisposable<TEntity> GetEntities(out Span<TEntity> entities);
73
75
 
@@ -1,4 +1,3 @@
1
- using JCMG.EntitasRedux.Core.Utils;
2
1
  using UnityEngine;
3
2
 
4
3
  namespace JCMG.EntitasRedux.Core.View.Impls
@@ -6,10 +5,15 @@ namespace JCMG.EntitasRedux.Core.View.Impls
6
5
  public abstract class LinkableView<TEntity> : LinkableView
7
6
  where TEntity : class, IEntity
8
7
  {
9
- protected sealed override void Subscribe(IEntity entity, IUnsubscribeEvent unsubscribe)
10
- => Subscribe(entity as TEntity, unsubscribe);
8
+ protected sealed override void OnEntityLinked(IEntity entity) => OnEntityLinked(entity as TEntity);
11
9
 
12
- protected virtual void Subscribe(TEntity entity, IUnsubscribeEvent unsubscribe)
10
+ protected virtual void OnEntityLinked(TEntity entity)
11
+ {
12
+ }
13
+
14
+ protected sealed override void OnEntityUnlinked(IEntity entity) => OnEntityUnlinked(entity as TEntity);
15
+
16
+ protected virtual void OnEntityUnlinked(TEntity entity)
13
17
  {
14
18
  }
15
19
  }
@@ -17,8 +21,6 @@ namespace JCMG.EntitasRedux.Core.View.Impls
17
21
  [RequireComponent(typeof(EntityLink))]
18
22
  public abstract partial class LinkableView : MonoBehaviour, ILinkable
19
23
  {
20
- private readonly UnsubscribeEvent _unsubscribeEvent = new();
21
-
22
24
  [SerializeField] protected EntityLink entityLink;
23
25
 
24
26
  private bool _destroyed;
@@ -40,7 +42,7 @@ namespace JCMG.EntitasRedux.Core.View.Impls
40
42
  return;
41
43
 
42
44
  entity.OnBeforeDestroyEntity += OnDestroyEntity;
43
- Subscribe(entity, _unsubscribeEvent);
45
+ OnEntityLinked(entity);
44
46
  }
45
47
 
46
48
  public void Unlink()
@@ -59,26 +61,18 @@ namespace JCMG.EntitasRedux.Core.View.Impls
59
61
  if (entity.Enabled)
60
62
  {
61
63
  entity.OnBeforeDestroyEntity -= OnDestroyEntity;
62
- Unsubscribe();
64
+ OnEntityUnlinked(entity);
63
65
  }
64
66
 
65
67
  if (!_destroyed)
66
- OnClear();
68
+ OnEntityDestroy();
67
69
  }
68
70
 
69
- protected abstract void Subscribe(IEntity entity, IUnsubscribeEvent unsubscribe);
71
+ protected abstract void OnEntityLinked(IEntity entity);
70
72
 
71
- private void Unsubscribe()
72
- {
73
- _unsubscribeEvent.Clear();
74
- OnUnsubscribe();
75
- }
76
-
77
- protected virtual void OnUnsubscribe()
78
- {
79
- }
73
+ protected abstract void OnEntityUnlinked(IEntity entity);
80
74
 
81
- protected virtual void OnClear()
75
+ protected virtual void OnEntityDestroy()
82
76
  {
83
77
  }
84
78
 
@@ -54,6 +54,12 @@ namespace JCMG.EntitasRedux.VisualDebugging
54
54
 
55
55
  _context.OnEntityCreated += OnEntityCreated;
56
56
  _context.OnGroupCreated += OnGroupCreated;
57
+
58
+ var entities = _context.GetEntities();
59
+ foreach (var entity in entities)
60
+ {
61
+ OnEntityCreated(_context, entity);
62
+ }
57
63
  }
58
64
 
59
65
  public void Deactivate()
@@ -104,4 +110,4 @@ namespace JCMG.EntitasRedux.VisualDebugging
104
110
  return str;
105
111
  }
106
112
  }
107
- }
113
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.elestrago.unity.entitas-redux",
3
- "version": "3.7.2",
3
+ "version": "3.7.4",
4
4
  "displayName": "JCMG Entitas Redux",
5
5
  "description": "Entitas Redux is an fast, accessible, and feature-rich ECS framework for Unity. It leverages code generation and an extensible plugin framework to make life easier for developers.",
6
6
  "category": "Unity",
@@ -1,30 +0,0 @@
1
- using System;
2
- using EntitasRedux.Core.Libs;
3
-
4
- namespace JCMG.EntitasRedux.Core.Utils
5
- {
6
- public class UnsubscribeEvent : IUnsubscribeEvent
7
- {
8
- private readonly Event<Action> _events = new();
9
-
10
- public event Action Value
11
- {
12
- add => _events.AddListener(value);
13
- remove => _events.RemoveListener(value);
14
- }
15
-
16
- public void Clear()
17
- {
18
- using var _ = _events.Invokable(out var listeners);
19
- _events.RemoveAllListeners();
20
-
21
- foreach (var listener in listeners)
22
- listener();
23
- }
24
- }
25
-
26
- public interface IUnsubscribeEvent
27
- {
28
- event Action Value;
29
- }
30
- }
@@ -1,3 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: b07e7461736e4e0e922ac0177723ceb2
3
- timeCreated: 1678487489
@@ -1,13 +0,0 @@
1
- using System;
2
-
3
- namespace JCMG.EntitasRedux.Core.Utils
4
- {
5
- public static class UnsubscribeEventExtensions
6
- {
7
- public static IDisposable AddTo(this IDisposable disposable, IUnsubscribeEvent unsubscribe)
8
- {
9
- unsubscribe.Value += disposable.Dispose;
10
- return disposable;
11
- }
12
- }
13
- }
@@ -1,3 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: 8c9e182590544717a4755da46f9f806f
3
- timeCreated: 1678487883
@@ -1,3 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: 823e28aebd324636ab22d6c8d563ed6a
3
- timeCreated: 1678487365