Class NativeListDataLayer<TItem>
Base class for all data layers that are based on NativeList{T}.
Inherited Members
Namespace: Fwt.Core.DataLayers
Assembly: fwt.core.dll
Syntax
public class NativeListDataLayer<TItem> : DataLayer, IDisposable, ICommitChanges, IListDataLayer<TItem> where TItem : unmanaged
Type Parameters
| Name | Description |
|---|---|
| TItem |
Fields
DefaultValue
When the data layer is resized, new cells will be filled with this value.
Declaration
public TItem DefaultValue
Field Value
| Type | Description |
|---|---|
| TItem |
_data
Declaration
protected NativeList<TItem> _data
Field Value
| Type | Description |
|---|---|
| NativeList<TItem> |
Properties
Data
Container for data in the layer.
Declaration
public NativeList<TItem> Data { get; }
Property Value
| Type | Description |
|---|---|
| NativeList<TItem> |
IsDisposableItems
If true, means when layer is resized or disposed, all items that are removed will be disposed (see nested classes description for details as the process may be different from layer to layer)
Declaration
public override bool IsDisposableItems { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Overrides
Length
Returns the number of items in the layer.
Declaration
public override int Length { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Methods
Cleanup()
Resets the dirty flags of the layer.
Declaration
public virtual void Cleanup()
CleanupAsync(JobHandle)
Resets the dirty flags of the layer.
Declaration
public virtual JobHandle CleanupAsync(JobHandle dependency)
Parameters
| Type | Name | Description |
|---|---|---|
| JobHandle | dependency | input dependency to use into a scheduled job (not used in a NativeListDataLayer<TItem>) |
Returns
| Type | Description |
|---|---|
| JobHandle | job handle of all scheduled jobs. (in NativeListDataLayer<TItem> returns the input dependency) |
CopyValuesFrom(IList<TItem>)
Sets the amount of items in the layer to the provided list count and copies values from the provided list to the layer. If a layer is not initialized, returns false. If the provided list count is different from the current layer size, the layer will be resized to match the list count and new cells will be filled with DefaultValue.
Declaration
public virtual bool CopyValuesFrom(IList<TItem> items)
Parameters
| Type | Name | Description |
|---|---|---|
| IList<TItem> | items | list of values to copy from |
Returns
| Type | Description |
|---|---|
| bool | true if successfull, otherwise = false. |
Deserialize(BinaryReader)
Deserializes data from the specified binary reader into the current instance.
Declaration
public virtual bool Deserialize(BinaryReader reader)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryReader | reader | The binary reader from which to read the serialized data. Cannot be null. |
Returns
| Type | Description |
|---|---|
| bool | true if the data was successfully deserialized; otherwise, false. |
Dispose()
Disposes the data layer and all items in it by calling DisposeAllItems() DisposeAllItems()
Declaration
public override void Dispose()
Overrides
DisposeAllItems()
Disposes all items in the layer by calling DisposeDataItem() for each DisposeDataItem(TItem)
Declaration
public override void DisposeAllItems()
Overrides
DisposeDataItem(TItem)
Disposes the data item if it is IDisposable.
Declaration
protected virtual void DisposeDataItem(TItem item)
Parameters
| Type | Name | Description |
|---|---|---|
| TItem | item |
DisposeExcessItems(int)
When layer is resized, this method is called to dispose items in cells of index greater than layerSize.
Declaration
public virtual void DisposeExcessItems(int layerSize)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerSize |
GetData(int)
Gets the data at the specified index.
Declaration
public virtual TItem GetData(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | index to get data under |
Returns
| Type | Description |
|---|---|
| TItem | data from the cell at provided index |
Init(int, Allocator)
Initializes/Reinitializes the data layer with the specified size.
Declaration
public virtual void Init(int layerSize, Allocator allocator = Allocator.Persistent)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerSize | items count in the layer |
| Allocator | allocator | allocator to create internal collections under. |
Serialize(BinaryWriter)
Serializes the current data to the specified binary writer.
Declaration
public virtual bool Serialize(BinaryWriter writer)
Parameters
| Type | Name | Description |
|---|---|---|
| BinaryWriter | writer | The binary writer to which the data will be serialized. Cannot be null. |
Returns
| Type | Description |
|---|---|
| bool | true if the data was successfully serialized; otherwise, false. |
SetData(int, TItem)
Sets the data at the specified index.
Declaration
public virtual bool SetData(int index, TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | cell index to put data in |
| TItem | data | data to put into the cell at provided index |
Returns
| Type | Description |
|---|---|
| bool |
TryGetData(int, out TItem)
Tries to get the data at the specified index.
Declaration
public virtual bool TryGetData(int index, out TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | cell index to put data in |
| TItem | data | data to put into the cell at provided index |
Returns
| Type | Description |
|---|---|
| bool | true if data was added, otherwise - false |
TrySetData(int, TItem)
Tries to set the data at the specified index.
Declaration
public bool TrySetData(int index, TItem data)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | cell index to put data in |
| TItem | data | data to put into the cell at provided index |
Returns
| Type | Description |
|---|---|
| bool | true if data was set, otherwise - false |