Class IconFactory
Factory for generating item icons using the game's IconGenerator and MugshotGenerator.
Item Icon Generation (Experimental): Direct item icon generation using IconGenerator is experimental. Use GenerateIcon(Transform, int, bool) for static mesh item models.
Accessory Icon Generation (Confirmed Working): Accessory icon generation using MugshotGenerator is confirmed to work. Use GenerateAccessoryIcon(string, Action<Texture2D>, Color?, int) or GenerateAccessoryIconSprite(string, Action<Sprite>, Color?, int) for clothing accessories (hats, glasses, etc.).
public static class IconFactory
- Inheritance
-
IconFactory
- Inherited Members
Methods
GenerateAccessoryIcon(string, Action<Texture2D>, Color?, int)
Generates an icon for an accessory by rendering it on an avatar using MugshotGenerator. This is an asynchronous operation that will invoke the callback when complete.
public static void GenerateAccessoryIcon(string accessoryPath, Action<Texture2D> callback, Color? accessoryColor = null, int size = 512)
Parameters
accessoryPathstringThe resource path to the accessory (e.g., from Appearances.AccessoryFields.Head)
callbackAction<Texture2D>Callback invoked with the generated texture when complete
accessoryColorColor?Optional tint color for the accessory (defaults to white)
sizeintThe size of the square icon (default 512)
Remarks
This method attempts to use the local player's current avatar settings for a personalized icon. However, if called during mod initialization (e.g., in OnSceneWasLoaded), the player may not have spawned yet, causing it to fall back to a generic avatar with neutral face, eyes, and basic clothing. To use the player's actual appearance, consider deferring icon generation until after player spawn by subscribing to LocalPlayerSpawned.
GenerateAccessoryIconSprite(string, Action<Sprite>, Color?, int)
Generates an icon for an accessory as a Sprite by rendering it on an avatar using MugshotGenerator. This is an asynchronous operation that will invoke the callback when complete.
public static void GenerateAccessoryIconSprite(string accessoryPath, Action<Sprite> callback, Color? accessoryColor = null, int size = 512)
Parameters
accessoryPathstringThe resource path to the accessory (e.g., from Appearances.AccessoryFields.Head)
callbackAction<Sprite>Callback invoked with the generated sprite when complete
accessoryColorColor?Optional tint color for the accessory (defaults to white)
sizeintThe size of the square icon (default 512)
GenerateIcon(Transform, int, bool)
Generates a preview texture for the specified model.
public static Texture2D? GenerateIcon(Transform model, int size = 512, bool bakeSkinnedMeshes = true)
Parameters
modelTransformThe model to generate an icon for.
sizeintThe size of the square icon (default 512).
bakeSkinnedMeshesboolIf true, bakes SkinnedMeshRenderers to static MeshRenderers to ensure correct bounds (default true).
Returns
- Texture2D
A Texture2D containing the icon, or null if generation failed.
GenerateIconSprite(Transform, int, bool)
Generates a preview icon as a Sprite for the specified model.
public static Sprite? GenerateIconSprite(Transform model, int size = 512, bool bakeSkinnedMeshes = true)
Parameters
modelTransformThe model to generate an icon for.
sizeintThe size of the square icon (default 512).
bakeSkinnedMeshesboolIf true, bakes SkinnedMeshRenderers to static MeshRenderers to ensure correct bounds (default true).
Returns
- Sprite
A Sprite containing the icon, or null if generation failed.
GeneratePackagingIcon(string, string)
Generates an icon for a packaging ID and product ID.
public static Texture2D? GeneratePackagingIcon(string packagingID, string productID)
Parameters
packagingIDstringThe ID of the packaging visuals to use.
productIDstringThe ID of the product to display in the packaging.
Returns
- Texture2D
A Texture2D containing the packaging icon, or null if generation failed.
GeneratePackagingIconSprite(string, string)
Generates an icon as a Sprite for a packaging ID and product ID.
public static Sprite? GeneratePackagingIconSprite(string packagingID, string productID)
Parameters
packagingIDstringThe ID of the packaging visuals to use.
productIDstringThe ID of the product to display in the packaging.
Returns
- Sprite
A Sprite containing the packaging icon, or null if generation failed.