Class DesignScene
- Namespace
- CodeSmile.AnyMotion.AnimateYourself.Samples /
- Assembly
- ApiSource.dll
Walks and runs characters across a fixed camera framing, either as an automated sequence over a list of characters and a list of presets, or as one character under manual control. The automated sequence is what a screen recording is cut from; the manual mode is what one preset is designed in.
[AddComponentMenu("AnyMotion/Design Scene")]
public sealed class DesignScene : MonoBehaviour
Expand Details ...
- Inheritance
-
objectObjectComponentBehaviourMonoBehaviourDesignScene
Remarks
Both modes run outside Play mode and inside it. Outside Play mode
DesignScenePreviewDriver calls Tick(float) on every editor update;
inside Play mode CodeSmile.AnyMotion.AnimateYourself.Samples.DesignScene.Update() calls it. Neither path uses a
UnityEngine.CharacterController, physics, or anything else Play mode alone provides, so
both produce the same motion.
The camera is placed whether this component is driving or not. ApplyFraming() runs ahead of the IsDriving check in Tick(float) and again from CodeSmile.AnyMotion.AnimateYourself.Samples.DesignScene.OnEnable(), so the two framing sliders move the camera immediately in both states. It writes the camera transform only when the values differ from what the camera already has, so a scene that is not driving is not dirtied on every editor update.
An entry in Characters may be the character itself or a parent of it.
BuildTake(int, WalkGaitPreset, float) takes the entry as given and looks for
AnimateHumanoid on the entry object first and then on its children, so both
shapes work and neither is wrong. Until 2026-08-20 the entry had to be a parent, and an
entry carrying AnimateHumanoid itself was skipped as an R1 violation. That
requirement was wrong: R1 forbids two writers on one transform, and there is only one
writer here. This component writes the entry's transform, the same way a character
controller would; the gait writes bone transforms from Hips downwards
(IkTargetSpaceDriver and BoneFrameSpaceDriver write
hips.localPosition and bone rotations, and nothing in the runtime writes the
transform AnimateHumanoid sits on). The gait reads that transform's rotation
as the frame its rotations are expressed in, which is a read, not a write.
Only characters this component wrote a preset onto get their settings restored. A character's settings are captured as JSON in CodeSmile.AnyMotion.AnimateYourself.Samples.DesignScene.m_Captured immediately before a preset overwrites them. StopDriving() writes a capture back only for a character this component applied a preset to, because those are the only settings it overwrote. A character driven with no preset keeps whatever is being edited on it, which is what Manual Design with Use Preset unchecked is for. The capture is serialized, so a script recompile or a scene reload does not lose it.
Fields
DefaultRunSpeed
Value RunSpeed starts at, in metres per second.
public const float DefaultRunSpeed = 4
Field Value
- float
DefaultWalkSpeed
Value WalkSpeed starts at, in metres per second.
public const float DefaultWalkSpeed = 1.5
Field Value
- float
FramingMarginFraction
Share of the frame height left empty above the reference character, and again below it. 0.125 is the middle of the 10 to 15 percent the framing was asked for.
public const float FramingMarginFraction = 0.125
Field Value
- float
FramingReferenceFieldOfView
Vertical field of view the two default framing constants below were computed for, in degrees. Unity's own default for a new camera.
public const float FramingReferenceFieldOfView = 60
Field Value
- float
FramingReferenceHeight
Character height the default framing is built for, in metres. Not a per-character measurement on purpose: one framing for every character is what makes two takes comparable.
public const float FramingReferenceHeight = 1.8
Field Value
- float
IdleSpeed
Speed the Idle button writes into Speed, in metres per second.
public const float IdleSpeed = 0
Field Value
- float
MaxSpeed
Highest value any of the three speed fields accepts, in metres per second.
public const float MaxSpeed = 12
Field Value
- float
MaxWalkDistance
Longest travel span WalkDistance accepts, in metres.
public const float MaxWalkDistance = 10
Field Value
- float
MinWalkDistance
Shortest travel span WalkDistance accepts, in metres.
public const float MinWalkDistance = 1
Field Value
- float
Properties
Characters
Character roots the sequence plays, in order.
public List<GameObject> Characters { get; }
Property Value
- List<GameObject>
IsDriving
True while this component is moving characters.
public bool IsDriving { get; }
Property Value
- bool
ManualCharacterIndex
Which entry of Characters Manual Design drives.
public int ManualCharacterIndex { get; set; }
Property Value
- int
ManualPresetIndex
Which entry of Presets Manual Design applies while UseManualPreset is true.
public int ManualPresetIndex { get; set; }
Property Value
- int
Mode
Which of the two modes is driving. Changing it restarts from the first take.
public DesignSceneMode Mode { get; set; }
Property Value
Presets
Presets the sequence applies, in order.
public List<WalkGaitPreset> Presets { get; }
Property Value
- List<WalkGaitPreset>
RunSpeed
The run speed, in metres per second. Written into Speed by the Run button, shown in that button's label, and used by the automated sequence's run take.
public float RunSpeed { get; set; }
Property Value
- float
ShowReadout
Whether the on-screen readout is drawn. False hides it, which is how a take is recorded without text over it.
public bool ShowReadout { get; set; }
Property Value
- bool
Speed
Travel speed used by Manual Design, in metres per second.
public float Speed { get; set; }
Property Value
- float
Strafe
True while the character faces the camera or away from it and travels sideways. Sets
AnimateHumanoid.MoveDirection to plus or minus 90 degrees, which is what makes the
gait strafe.
public bool Strafe { get; set; }
Property Value
- bool
StrafeFacing
Which way the character faces while Strafe is true.
public DesignSceneStrafeFacing StrafeFacing { get; set; }
Property Value
TakeCount
How many takes the automated sequence plays: one walk and one run for every combination of a character and a preset. 0 while either list is empty.
public int TakeCount { get; }
Property Value
- int
TakeIndex
Index of the take the automated sequence is playing, counting from 0.
public int TakeIndex { get; }
Property Value
- int
TravelDirection
Which way characters cross the frame.
public DesignSceneTravelDirection TravelDirection { get; set; }
Property Value
UseManualPreset
True while Manual Design applies the preset ManualPresetIndex selects. False applies no preset, which leaves the character's own AnimateHumanoid settings untouched and editable while it moves.
public bool UseManualPreset { get; set; }
Property Value
- bool
WalkBackwards
True while the character keeps facing along the travel line and travels the opposite way,
which sets AnimateHumanoid.MoveDirection to 180 degrees. Ignored while
Strafe is true.
public bool WalkBackwards { get; set; }
Property Value
- bool
WalkDistance
How far a character travels before it returns to the start of the span, in metres, between MinWalkDistance and MaxWalkDistance. The span is centred on the point the camera looks at.
public float WalkDistance { get; set; }
Property Value
- float
WalkSpeed
The walk speed, in metres per second. Written into Speed by the Walk button, shown in that button's label, and used by the automated sequence's walk take.
public float WalkSpeed { get; set; }
Property Value
- float
Methods
ApplyFraming()
Places the camera at the position and rotation the two framing sliders describe and reports whether that moved it. Runs whether this component is driving or not, which is what makes both sliders take effect while driving is stopped.
public bool ApplyFraming()
Returns
- bool
True if the camera transform was written, false if the camera already stood there or if there is no camera to place.
DistanceForVisibleHeight(float, float)
Distance at which a camera's view is visibleHeight metres high.
public static float DistanceForVisibleHeight(float visibleHeight, float verticalFieldOfViewDegrees)
Parameters
| Type | Name | Description |
|---|---|---|
visibleHeight |
||
verticalFieldOfViewDegrees |
Returns
- float
NextTake()
Moves to the next take of the automated sequence, wrapping past the last one.
public void NextTake()
PreviousTake()
Moves to the previous take of the automated sequence, wrapping past the first one.
public void PreviousTake()
RestartTake()
Plays the current take from its beginning again.
public void RestartTake()
ReverseTravelDirection()
Swaps the travel direction between right-to-left and left-to-right.
public void ReverseTravelDirection()
RunBlendWeight(WalkGaitParameters, float)
How far between walking and running a character's settings put it at
moveSpeed: 0 is fully walking, 1 is fully running.
public static float RunBlendWeight(WalkGaitParameters parameters, float moveSpeed)
Parameters
| Type | Name | Description |
|---|---|---|
parameters |
||
moveSpeed |
Returns
- float
SetIdleSpeed()
Writes the Idle speed, 0 metres per second, into Speed.
public void SetIdleSpeed()
SetRunSpeed()
public void SetRunSpeed()
SetWalkSpeed()
public void SetWalkSpeed()
StartDriving()
Starts playing from the first take. Safe to call while already driving: it restarts without capturing a second time, so the settings written back by StopDriving() stay the ones from before any preset was applied.
public void StartDriving()
Remarks
The capture itself happens on the first take that is begun, not here, so a scene that opens already driving captures the same settings a scene started by this method does.
StepLengthMetres(WalkGaitParameters, float, float)
How far the character travels per step at moveSpeed, in metres, given a
character's settings and its measured stride reference.
public static float StepLengthMetres(WalkGaitParameters parameters, float strideReference, float moveSpeed)
Parameters
| Type | Name | Description |
|---|---|---|
parameters |
||
strideReference |
||
moveSpeed |
Returns
- float
Remarks
Mirrors what WalkGait computes for the same speed: the walk step length blended
towards the run step length by the run blend weight, times the measured stride reference. It
is a separate copy because both inputs it needs are public and the blend itself is not, and
because it answers a question about a speed the character is not travelling at yet.
StopDriving()
Stops driving and writes back every captured character's active state and position, plus the settings of each character this component applied a preset to. Leaves the camera where it is, which is the framing the two sliders describe.
public void StopDriving()
Tick(float)
Advances the scene by deltaTime seconds: places the camera, then, while
driving, places the character being played and hands it its speed and travel direction.
Called by CodeSmile.AnyMotion.AnimateYourself.Samples.DesignScene.Update() in Play mode and by DesignScenePreviewDriver outside
it.
public bool Tick(float deltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
deltaTime |
Returns
- bool
True if anything visible changed, which is either the camera moving or this component driving. A caller outside Play mode uses it to decide whether the Scene view needs a repaint.
Remarks
This method does not advance the gait itself. WalkGait advances in its own
Update in Play mode and in WalkGaitPreviewDriver outside it, both of which run
whether this component exists or not.
Public so a recorder or a verification harness can step the scene at a fixed time step instead of at whatever step the editor or the player happens to produce.
VisibleHeight(float, float)
Height of the camera's view at a given distance in front of it, in metres. The plain perspective-camera relation, kept here so the framing numbers in the readout and the framing the camera actually produces come from one place.
public static float VisibleHeight(float distance, float verticalFieldOfViewDegrees)
Parameters
| Type | Name | Description |
|---|---|---|
distance |
||
verticalFieldOfViewDegrees |
Returns
- float