Using Accessories
In code accessories are managed by the AccessoryBuilder. The accessory builder places items into slots and runs the MeshCombine to optimize the character with its new look.
Add / Remove Accessories
Working with Outfits
import { Airship } from "@Easy/Core/Shared/Airship";
export default class LoadAccessoryList extends AirshipBehaviour {
@Header("Accessory Prefabs")
@Tooltip("Requires AccessoryComponent")
public accPrefabs: GameObject[];
private loadingOurAccessories = false;
override Start(): void {
// Listen for the local character
Airship.Characters.ObserveCharacters((char) => {
char.WaitForInit();
if (char.IsLocalCharacter()) {
// This is the local character
// Mesh combined fires when new accessories are added to the character
// So if your character auto loads its outfit this will fire
char.accessoryBuilder.OnMeshCombined.Connect(() => {
// Make sure this event isn't from our CombineMesh call
if (this.loadingOurAccessories) {
this.loadingOurAccessories = false;
return;
}
this.loadingOurAccessories = true;
// Add each accessory from our prefab list
for (const acc of this.accPrefabs) {
char.accessoryBuilder.Add(acc.GetComponent<AccessoryComponent>()!);
}
// Regenerate the character mesh with the new accessories
char.accessoryBuilder.UpdateCombinedMesh();
});
}
});
}
}
Last updated