Struct HumanoidStyle
- Namespace
- CodeSmile.AnyMotion.AnimateYourself /
- Assembly
- ApiSource.dll
How much of each named style one character is using. Reached through Style.
public readonly struct HumanoidStyle
Expand Details ...
Examples
// Bind a style to a value the game already tracks.
humanoid.Style.SetWeight("Limp", 1f - health.Normalised);
// Give every member of a crowd its own mix.
for (var slot = 0; slot < humanoid.Style.AnchorCount; slot++)
humanoid.Style.SetWeight(slot, Random.value);
Remarks
A style is a second complete set of animation settings the character blends towards — a limp, a swagger, an exhausted trudge — so game code changes how a character moves by moving one number per style instead of re-authoring the settings themselves. Which styles a character has is set by the Gait Style Set assigned to it in the Inspector; how much of each it is using is stored on the character, so every member of a crowd sharing one set can carry a different mix.
A style is addressed by its slot: its position in that set's own list, from 0 to AnchorCount minus 1. An anchor is one style in the set, so AnchorCount is how many styles this character can blend between. Slot order is fixed once a project is using it, which is why a style is emptied rather than removed from the set.
Nothing here throws, and nothing here allocates. Every member is safe to call every frame, on a character with no style set assigned, with a slot that does not exist, or with a name that matches no style: a read then returns 0 or an empty name, and a write does nothing at all. A game that spawns styled and unstyled characters from the same code therefore needs no special case for the unstyled ones.
Reading Style is a field read rather than an object, so it is equally cheap to store in a local or to write out in full at every call site.
Properties
AnchorCount
How many styles this character can blend between, which is how many slots the Gait Style Set assigned to it has. 0 when no set is assigned, in which case every other member here is inert.
public int AnchorCount { get; }
Property Value
- int
Remarks
Every valid slot is below this number, so it is the bound for a loop over a character's styles. It can change while the game runs, when a style set is edited or reassigned, so read it rather than storing a count taken at startup.
Methods
EffectiveWeight(int)
How much of one style is in effect right now, from 0 to 1. A style takes up to the Gait Style Set's Blend Duration to reach a new weight, so this trails GetWeight(int) while a style is arriving or leaving, and equals it once it has settled.
public float EffectiveWeight(int slot)
Parameters
| Type | Name | Description |
|---|---|---|
slot |
Which style, from 0 to AnchorCount minus 1. |
Returns
- float
0 for a slot that does not exist, and for a character with no style set.
Remarks
Read this to show what a character is actually doing — a debug readout, a UI meter, or game logic that should wait until a style has fully arrived. Read GetWeight(int) instead to read back what was asked for.
A style set whose Blend Duration is 0 changes weight immediately, so the two agree at all times. They also agree on the frame a character is first given a style set: an authored mix starts in effect rather than easing in from unstyled.
GetWeight(int)
How much of one style this character is being asked for, from 0 to 1. This is the requested amount — what was last written here, or what the Inspector shows — which is not the same as how much of it has arrived yet. Read EffectiveWeight(int) for that.
public float GetWeight(int slot)
Parameters
| Type | Name | Description |
|---|---|---|
slot |
Which style, from 0 to AnchorCount minus 1. |
Returns
- float
0 for a slot that does not exist, and for a character with no style set.
NameOf(int)
The name of the style in one slot, exactly as it is written in the Gait Style Set. Use it to show a character's styles to a player or a designer, and to find which slot a name refers to without writing an index into game code.
public string NameOf(int slot)
Parameters
| Type | Name | Description |
|---|---|---|
slot |
Which style, from 0 to AnchorCount minus 1. |
Returns
- string
An empty string — never null — for a slot outside that range, for a slot left empty in the set, and for a character with no style set.
SetWeight(int, float)
Asks for one style at a given strength, from 0 (unused) to 1 (fully). Values outside that range are brought into it, so a weight computed from game state needs no clamping first.
public void SetWeight(int slot, float weight)
Parameters
| Type | Name | Description |
|---|---|---|
slot |
Which style, from 0 to AnchorCount minus 1. |
|
weight |
How much of it to use, 0 to 1. |
Remarks
Safe to call every frame, and intended to be: the character moves towards the new weight no faster than the Gait Style Set's Blend Duration allows, rather than snapping to it, so a weight that jumps still produces a smooth change of movement. Writing the same weight repeatedly costs nothing and changes nothing.
Does nothing when the slot carries no style, including on a character with no style set — the character keeps animating from its own settings.
SetWeight(string, float)
Asks for the style with a given name at a given strength, which is the same as calling SetWeight(int, float) on the slot that carries it. Use this when a style is easier to name in game code than to number.
public void SetWeight(string anchorName, float weight)
Parameters
| Type | Name | Description |
|---|---|---|
anchorName |
The style's Name in the Gait Style Set. |
|
weight |
How much of it to use, 0 to 1. |
Remarks
Names are compared exactly, including capitalisation, against the Name of each style in the Gait Style Set. A name that matches none of them does nothing, and is reported once in the console with the names this character does have, so a misspelling is visible rather than silent. A character with no style set is not reported, because passing the same name to styled and unstyled characters is ordinary rather than a mistake.