SceneObjectNamer - jimdroberts/FishMMO GitHub Wiki
Assigns a generated name to a scene object using prefix and suffix caches. Handles network payloads for name synchronization.
-
public NameCache Prefix
Cache of possible name prefixes.
-
public NameCache Suffix
Cache of possible name suffixes.
-
private int prefixID
The selected prefix index for this object's name.
-
private int suffixID
The selected suffix index for this object's name.
-
public override void OnStartServer()
Called when the server starts. Randomizes prefix and suffix IDs for the object name.
-
public override void ReadPayload(NetworkConnection connection, Reader reader)
Reads the prefix and suffix IDs from the network and sets the object name accordingly. Parameters: - NetworkConnection connection: Network connection. - Reader reader: Network reader for payload.*
-
public override void WritePayload(NetworkConnection connection, Writer writer)
Writes the prefix and suffix IDs to the network for synchronization. Parameters: - NetworkConnection connection: Network connection. - Writer writer: Network writer for payload.*
- Attach the SceneObjectNamer component to a scene object.
- Assign NameCache assets to the Prefix and Suffix fields in the Inspector.
- Ensure the object is networked and the caches contain valid names.
// Example 1: Assigning random names to scene objects
SceneObjectNamer namer = ...; // Reference to the component
namer.Prefix = prefixCache;
namer.Suffix = suffixCache;
// On server start, the object will be assigned a random name from the caches
// Example 2: Accessing the generated name
string generatedName = namer.gameObject.name;
- Ensure Prefix and Suffix caches are populated with valid names for variety.
- Use ReadPayload and WritePayload for proper network synchronization of names.
- Update UI elements (e.g., name labels) on the client when names change.
- Document the intended use of the namer in the asset's Inspector description.