mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24:37 +08:00
Implement Add and Del callbacks for Hybrid components.
This commit is contained in:
parent
393c56a166
commit
d674f2da8b
@ -18,9 +18,6 @@ namespace DCFApixels.DragonECS
|
|||||||
private int[] _recycledItems;
|
private int[] _recycledItems;
|
||||||
private int _recycledItemsCount;
|
private int _recycledItemsCount;
|
||||||
|
|
||||||
private IEcsComponentReset<T> _componentResetHandler = EcsComponentResetHandler<T>.instance;
|
|
||||||
private IEcsComponentCopy<T> _componentCopyHandler = EcsComponentCopyHandler<T>.instance;
|
|
||||||
|
|
||||||
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
private List<IEcsPoolEventListener> _listeners = new List<IEcsPoolEventListener>();
|
||||||
|
|
||||||
#region Properites
|
#region Properites
|
||||||
@ -67,6 +64,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
this.IncrementEntityComponentCount(entityID);
|
this.IncrementEntityComponentCount(entityID);
|
||||||
_listeners.InvokeOnAdd(entityID);
|
_listeners.InvokeOnAdd(entityID);
|
||||||
|
component.OnAddToPool();
|
||||||
_items[itemIndex] = component;
|
_items[itemIndex] = component;
|
||||||
}
|
}
|
||||||
public void Set(int entityID, T component)
|
public void Set(int entityID, T component)
|
||||||
@ -90,10 +88,10 @@ namespace DCFApixels.DragonECS
|
|||||||
else
|
else
|
||||||
{//not null
|
{//not null
|
||||||
_listeners.InvokeOnDel(entityID);
|
_listeners.InvokeOnDel(entityID);
|
||||||
if (_items[itemIndex] is IDisposable disposable)
|
component.OnDelFromPool();
|
||||||
disposable.Dispose();
|
|
||||||
}
|
}
|
||||||
_listeners.InvokeOnAdd(entityID);
|
_listeners.InvokeOnAdd(entityID);
|
||||||
|
component.OnAddToPool();
|
||||||
_items[itemIndex] = component;
|
_items[itemIndex] = component;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -125,8 +123,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endif
|
#endif
|
||||||
ref int itemIndex = ref _mapping[entityID];
|
ref int itemIndex = ref _mapping[entityID];
|
||||||
T component = _items[itemIndex];
|
T component = _items[itemIndex];
|
||||||
if (component is IDisposable disposable)
|
component.OnDelFromPool();
|
||||||
disposable.Dispose();
|
|
||||||
if (_recycledItemsCount >= _recycledItems.Length)
|
if (_recycledItemsCount >= _recycledItems.Length)
|
||||||
Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
|
Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
|
||||||
_recycledItems[_recycledItemsCount++] = itemIndex;
|
_recycledItems[_recycledItemsCount++] = itemIndex;
|
||||||
|
Loading…
Reference in New Issue
Block a user