Skip to content

Game.Objects.Tree

Assembly:
Assembly-CSharp (game/mod runtime assembly)
{{ Represents a value-type component included in the game's runtime assembly used by mods and the game ECS. }}

Namespace:
Game.Objects
{{ Located under the Game.Objects namespace. }}

Type:
struct
{{ A value type used as an ECS component. }}

Base:
System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable
{{ Implements Unity.Entities.IComponentData for ECS usage, IQueryTypeParameter for query typing, and a custom ISerializable for binary serialization. }}

Summary:
{{ Tree is an ECS component that stores a tree's runtime state and growth stage. It serializes/deserializes itself as two bytes: a TreeState value stored as a byte and a growth byte. This component is intended for use with the game's entity system and save/load serialization. }}


Fields

  • public TreeState m_State
    {{ The tree's logical state (represented by the TreeState enum). Serialized as a single byte. The enum isn't shown here but is written/read as a byte in Serialize/Deserialize. }}

  • public byte m_Growth
    {{ Growth stage stored as a byte (0–255). Represents the tree's growth/progression; exact semantics depend on game logic. Serialized immediately after m_State as a single byte. }}

Properties

{{ This struct declares no properties. Its data is exposed via public fields. }}

Constructors

  • public Tree()
    {{ As a value type, Tree has the implicit default constructor which zero-initializes fields (m_State = 0 / default enum value, m_Growth = 0). You can also initialize fields explicitly when creating an instance. }}

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    {{ Serializes this component to the provided writer. It writes the m_State enum value cast to a byte first, then writes the m_Growth byte. The order is important for matching Deserialize. }}

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    {{ Deserializes this component from the provided reader. It reads a byte into a temporary value for the state, then reads the growth byte into m_Growth, and finally casts the state byte back to the TreeState enum and assigns it to m_State. The method expects the same ordering used in Serialize. }}

Usage Example

// Example usage showing construction and (de)serialization.
// IWriter/IReader are game-provided interfaces for binary serialization.

var tree = new Game.Objects.Tree
{
    m_State = TreeState.Mature, // example enum value
    m_Growth = 128 // example growth stage
};

// Serialize
using (var writer = GetBinaryWriter()) // placeholder for actual writer acquisition
{
    tree.Serialize(writer);
}

// Deserialize
Game.Objects.Tree loadedTree;
using (var reader = GetBinaryReader()) // placeholder for actual reader acquisition
{
    loadedTree = new Game.Objects.Tree();
    loadedTree.Deserialize(reader);
}

{{ Ensure that the writer/reader implementations used match the game's expected IWriter/IReader interfaces and that serialize/deserialize ordering is preserved. }}