Game.Areas.WoodResource
Assembly:
(Assembly-CSharp / Game assembly where the mod code is compiled)
Namespace: Game.Areas
Type: struct
Base: IBufferElementData, ISerializable
Summary: WoodResource is a Unity.Entities buffer element that holds a reference to a single tree entity representing a wood resource. The struct is serializable via Colossal.Serialization.Entities (implements ISerializable) so instances can be written to and read from the game's save/serialization system. The [InternalBufferCapacity(0)] attribute indicates this is intended to be stored in a DynamicBuffer with no inline capacity (all elements stored out-of-line).
Fields
public Unity.Entities.Entity m_Tree
Holds the Unity.Entities.Entity that represents the tree/resource. This is the primary payload of the buffer element and is used to link area data to the actual tree entity instance in the world.
Properties
- None
Constructors
public WoodResource(Unity.Entities.Entity tree)
Creates a new WoodResource wrapping the provided tree entity. Use this to add elements into a DynamicBuffer.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the contained Entity (m_Tree) to the provided writer. Used by the serialization system to persist this buffer element. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads an Entity value into m_Tree from the provided reader. Used by the deserialization system when loading saved data.
Usage Example
// Add a WoodResource buffer to an entity and push one element
var buffer = entityManager.AddBuffer<WoodResource>(areaEntity);
buffer.Add(new WoodResource(treeEntity));
// Read elements in a SystemBase
public partial class WoodProcessingSystem : SystemBase
{
protected override void OnUpdate()
{
Entities
.ForEach((in Entity areaEntity, in DynamicBuffer<WoodResource> woods) =>
{
for (int i = 0; i < woods.Length; i++)
{
Entity tree = woods[i].m_Tree;
// process tree entity...
}
})
.WithoutBurst()
.Run();
}
}
Notes:
- Because WoodResource implements IBufferElementData, store multiple entries on an entity via DynamicBuffer