Class ProceduralAnimatorScaffoldGenerator
Static utility class for generating ProceduralAnimator assets. Creates complete scaffold with proper references and folder structure.
Inherited Members
Namespace: Serenity.ProceduralAnimator.Infrastructure.Editor
Assembly: Serenity.UnityProceduralAnimator.Infrastructure.Editor.dll
Syntax
public static class ProceduralAnimatorScaffoldGenerator
Methods
AssetsExist(string, string)
Checks if assets already exist at the given root path.
Declaration
public static bool AssetsExist(string rootPath, string namePrefix)
Parameters
| Type | Name | Description |
|---|---|---|
| string | rootPath | Root path to check. |
| string | namePrefix | Name prefix for assets. |
Returns
| Type | Description |
|---|---|
| bool | True if any assets exist. |
CreateConstantWeightProvider(string, string, string, float)
Creates a ConstantWeightProviderSO asset.
Declaration
public static ConstantWeightProviderSO CreateConstantWeightProvider(string folderPath, string namePrefix, string name, float value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | Folder path for the asset. |
| string | namePrefix | Prefix for the asset filename (typically prefab name). |
| string | name | Descriptive name for the weight provider. |
| float | value | Constant weight value. |
Returns
| Type | Description |
|---|---|
| ConstantWeightProviderSO |
CreateFolderStructure(string)
Creates the folder structure for a ProceduralAnimator setup.
Declaration
public static bool CreateFolderStructure(string rootPath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | rootPath | Root path starting with Assets/ |
Returns
| Type | Description |
|---|---|
| bool | True if successful, false if failed. |
CreateFolderStructure(string, out string)
Creates the folder structure for a ProceduralAnimator setup.
Declaration
public static bool CreateFolderStructure(string rootPath, out string error)
Parameters
| Type | Name | Description |
|---|---|---|
| string | rootPath | Root path starting with Assets/ |
| string | error | Error message if creation fails. |
Returns
| Type | Description |
|---|---|
| bool | True if successful, false if failed. |
CreateLayerInstance(Type, string, string, string, List<string>, UnityStateKey, ProceduralLayerSO)
Creates an instance of any ProceduralLayerSO subtype as the idle layer, using the type's own inline field defaults for everything except the bone(s) it targets and its intensity key. Generalizes what CreatePeriodicOscillationLayer(string, string, string, string, UnityStateKey, float, Vector3, Vector3) did for one hardcoded type: every private field of type BoneIdRef the layer declares (primaryBoneId, targetBoneId, primaryBoneA1, ...) is pointed at the wizard-selected primary bone so the generated layer actually animates a bone that exists on this rig instead of the type's hardcoded placeholder default (e.g. "Spine", "Head"). A private "intensityKey" field of type UnityStateKey, if the type declares one, is wired to the supplied state key — every shipped layer type declares this field, so it is always set when one is supplied.
Declaration
public static ProceduralLayerSO CreateLayerInstance(Type layerType, string folderPath, string namePrefix, string name, List<string> selectedBoneIds, UnityStateKey intensityKey = null, ProceduralLayerSO parameterTemplate = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | layerType | Concrete ProceduralLayerSO subtype to instantiate. |
| string | folderPath | Folder path for the asset. |
| string | namePrefix | Prefix for the asset filename (typically prefab name). |
| string | name | Descriptive name for the layer. |
| List<string> | selectedBoneIds | List of available bone IDs; the best one becomes every BoneIdRef field's value. |
| UnityStateKey | intensityKey | Optional state key controlling the layer's intensity. |
| ProceduralLayerSO | parameterTemplate | Optional instance whose serialized field values (the type's own
configurable parameters, tuned by the wizard user) seed the created layer via UnityEngine.Object.Instantiate(UnityEngine.Object)
instead of the type's inline field defaults. Ignored — falling back to a clean UnityEngine.ScriptableObject.CreateInstance(System.Type) —
when null or when its runtime type does not match |
Returns
| Type | Description |
|---|---|
| ProceduralLayerSO |
CreatePeriodicOscillationLayer(string, string, string, List<string>, UnityStateKey, float, Vector3, Vector3)
Creates a PeriodicOscillationLayerSO asset using a list of selected bones. Automatically selects the best primary bone from the list.
Declaration
public static PeriodicOscillationLayerSO CreatePeriodicOscillationLayer(string folderPath, string namePrefix, string name, List<string> selectedBoneIds, UnityStateKey intensityKey = null, float frequency = 0.25, Vector3 positionScale = null, Vector3 rotationScale = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | Folder path for the asset. |
| string | namePrefix | Prefix for the asset filename (typically prefab name). |
| string | name | Descriptive name for the layer. |
| List<string> | selectedBoneIds | List of available bone IDs. |
| UnityStateKey | intensityKey | Optional state key controlling oscillation intensity. |
| float | frequency | Oscillation frequency in Hz. |
| Vector3 | positionScale | Position animation scale. |
| Vector3 | rotationScale | Rotation animation scale. |
Returns
| Type | Description |
|---|---|
| PeriodicOscillationLayerSO |
CreatePeriodicOscillationLayer(string, string, string, string, UnityStateKey, float, Vector3, Vector3)
Creates a PeriodicOscillationLayerSO asset. Applies sine-wave periodic oscillation to target bones.
Declaration
public static PeriodicOscillationLayerSO CreatePeriodicOscillationLayer(string folderPath, string namePrefix, string name, string primaryBoneId, UnityStateKey intensityKey = null, float frequency = 0.25, Vector3 positionScale = null, Vector3 rotationScale = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | Folder path for the asset. |
| string | namePrefix | Prefix for the asset filename (typically prefab name). |
| string | name | Descriptive name for the layer. |
| string | primaryBoneId | Bone ID for the primary bone to oscillate. |
| UnityStateKey | intensityKey | Optional state key controlling oscillation intensity. |
| float | frequency | Oscillation frequency in Hz. |
| Vector3 | positionScale | Position animation scale. |
| Vector3 | rotationScale | Rotation animation scale. |
Returns
| Type | Description |
|---|---|
| PeriodicOscillationLayerSO |
CreateProfile(string, string, UnityRigDefinition, ProceduralLayerSO[], ProceduralActionSO[], RuleSO[], string, List<UnityMaterialTargetMapping>, ProceduralLayerSO[])
Creates a ProceduralAnimatorProfileSO asset.
Declaration
public static ProceduralAnimatorProfileSO CreateProfile(string folderPath, string name, UnityRigDefinition editorRig, ProceduralLayerSO[] layers, ProceduralActionSO[] actions, RuleSO[] rules, string prefabAssetPath = null, List<UnityMaterialTargetMapping> materialTargets = null, ProceduralLayerSO[] baseLayers = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | Folder path for the asset. |
| string | name | Name for the profile (used in filename). |
| UnityRigDefinition | editorRig | Editor rig reference. |
| ProceduralLayerSO[] | layers | Array of procedural layers. |
| ProceduralActionSO[] | actions | Array of procedural actions. |
| RuleSO[] | rules | Array of rules. |
| string | prefabAssetPath | Optional prefab asset path as fallback for rig assignment. |
| List<UnityMaterialTargetMapping> | materialTargets | Optional material targets for auto-registration. |
| ProceduralLayerSO[] | baseLayers | Optional base layers that are always active regardless of rules. |
Returns
| Type | Description |
|---|---|
| ProceduralAnimatorProfileSO |
Remarks
NOTE: The layers and actions parameters are kept for backward compatibility but are ignored. With the new Rules-as-composition-root architecture, layers and actions are derived from rules. Pass base layers via the baseLayers parameter for always-active layers.
CreateSetLayerWeightRule(string, string, string, ProceduralLayerSO, WeightProviderSO, int, float, float)
Creates a RuleSO asset for SetLayerWeight effect with an inline AlwaysTrue condition.
Declaration
public static RuleSO CreateSetLayerWeightRule(string folderPath, string namePrefix, string name, ProceduralLayerSO targetLayer, WeightProviderSO weightProvider, int priority = 100, float blendInSeconds = 0.5, float blendOutSeconds = 0.5)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | Folder path for the asset. |
| string | namePrefix | Prefix for the asset filename (typically prefab name). |
| string | name | Descriptive name for the rule. |
| ProceduralLayerSO | targetLayer | Layer to set weight on. |
| WeightProviderSO | weightProvider | Provider for weight value. |
| int | priority | Rule priority (higher = evaluated first). |
| float | blendInSeconds | Blend-in duration. |
| float | blendOutSeconds | Blend-out duration. |
Returns
| Type | Description |
|---|---|
| RuleSO |
CreateStateKey(string, string, string, Vector2, Color)
Creates a UnityStateKey asset.
Declaration
public static UnityStateKey CreateStateKey(string folderPath, string namePrefix, string name, Vector2 rangeHint, Color debugColor)
Parameters
| Type | Name | Description |
|---|---|---|
| string | folderPath | Folder path for the asset. |
| string | namePrefix | Prefix for the asset filename (typically prefab name). |
| string | name | Descriptive name for the state key. |
| Vector2 | rangeHint | Value range hint for the state. |
| Color | debugColor | Debug visualization color. |
Returns
| Type | Description |
|---|---|
| UnityStateKey |
DeleteExistingAssets(string, string)
Deletes all generated assets at the given root path. Uses the same naming convention as asset creation (with namePrefix).
Declaration
public static void DeleteExistingAssets(string rootPath, string namePrefix)
Parameters
| Type | Name | Description |
|---|---|---|
| string | rootPath | Root folder path. |
| string | namePrefix | Prefix used in asset filenames. |
DescribeLayerType(Type)
A short, human-readable label for a layer type: the class name with the "LayerSO" suffix stripped and PascalCase split into words (e.g. "PeriodicOscillationLayerSO" → "Periodic Oscillation").
Declaration
public static string DescribeLayerType(Type layerType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | layerType |
Returns
| Type | Description |
|---|---|
| string |
DetectDefaultMaterialTarget(GameObject)
Detects a default material target from a prefab. Finds the first Renderer on the prefab (root or children) and creates a mapping. IMPORTANT: The EditorRenderer field is assigned for editor UX, and RendererPath/ColorPropertyName are computed from the renderer for runtime resolution.
Declaration
public static UnityMaterialTargetMapping? DetectDefaultMaterialTarget(GameObject prefabRoot)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | prefabRoot | The prefab root GameObject to search. |
Returns
| Type | Description |
|---|---|
| UnityMaterialTargetMapping? | A material target mapping, or null if no renderer found. |
EnsureFolderExists(string, out string)
Ensures a folder exists, creating it and all parent folders if necessary. Uses AssetDatabase.CreateFolder for proper Unity integration.
Declaration
public static bool EnsureFolderExists(string assetPath, out string error)
Parameters
| Type | Name | Description |
|---|---|---|
| string | assetPath | The asset path (e.g., "Assets/MyFolder/SubFolder"). |
| string | error | Error message if creation fails. |
Returns
| Type | Description |
|---|---|
| bool | True if folder exists or was created successfully. |
GenerateMinimalIdleSetup(string, string, List<string>, UnityRigDefinition, string, Type, ProceduralLayerSO)
Generates the complete minimal idle setup using a list of selected bones. Automatically selects the best chest/spine bone from the list. Also detects and creates default material targets from the prefab.
Declaration
public static ProceduralAnimatorProfileSO GenerateMinimalIdleSetup(string rootPath, string namePrefix, List<string> selectedBoneIds, UnityRigDefinition editorRig = null, string prefabAssetPath = null, Type idleLayerType = null, ProceduralLayerSO idleLayerParameterTemplate = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | rootPath | Root folder path starting with Assets/ |
| string | namePrefix | Prefix for all assets (usually prefab name) |
| List<string> | selectedBoneIds | List of selected bone IDs |
| UnityRigDefinition | editorRig | Optional rig reference for the profile |
| string | prefabAssetPath | Optional prefab asset path as fallback for rig assignment |
| Type | idleLayerType | The ProceduralLayerSO subtype to author as the idle layer. Defaults to PeriodicOscillationLayerSO — the wizard's long-standing "breathing" idle — when null, so every pre-existing caller keeps generating exactly what it always has. |
| ProceduralLayerSO | idleLayerParameterTemplate | Optional instance whose serialized field values seed the generated idle layer, forwarded as-is to CreateLayerInstance(Type, string, string, string, List<string>, UnityStateKey, ProceduralLayerSO). See that method's parameter documentation for the fallback and bone/intensity-key authority rules. |
Returns
| Type | Description |
|---|---|
| ProceduralAnimatorProfileSO | The created profile, or null if failed. |
GenerateMinimalIdleSetup(string, string, string, UnityRigDefinition, string)
Generates the complete minimal idle setup.
Declaration
public static ProceduralAnimatorProfileSO GenerateMinimalIdleSetup(string rootPath, string namePrefix, string chestBoneId, UnityRigDefinition editorRig = null, string prefabAssetPath = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | rootPath | Root folder path starting with Assets/ |
| string | namePrefix | Prefix for all assets (usually prefab name) |
| string | chestBoneId | Bone ID for the chest bone |
| UnityRigDefinition | editorRig | Optional rig reference for the profile |
| string | prefabAssetPath | Optional prefab asset path as fallback for rig assignment |
Returns
| Type | Description |
|---|---|
| ProceduralAnimatorProfileSO | The created profile, or null if failed. |
GetAvailableIdleLayerTypes()
Every concrete ProceduralLayerSO subtype the project ships, in the order Unity's
TypeCache returns them. Discovery mirrors [CreateAssetMenu]: only types that carry the
attribute are author-facing layer kinds — abstract bases are excluded that way, and a test
assembly's helper subclass (which could carry the attribute) is separately excluded via
Serenity.Global.Infrastructure.Editor.EditorTypePickerFilters, the same shared rule every other Serenity type picker uses.
This is the catalog the Setup wizard's "Default Idle Animation" dropdown reads from, so a new
shipped layer type appears there automatically.
Declaration
public static List<Type> GetAvailableIdleLayerTypes()
Returns
| Type | Description |
|---|---|
| List<Type> |
GetWizardManagedFieldNames(Type)
Names of every field CreateLayerInstance(Type, string, string, string, List<string>, UnityStateKey, ProceduralLayerSO) assigns itself — every BoneIdRef
field plus "intensityKey" — for layerType. The Setup wizard uses this to hide those
fields from its per-type parameter editor, since a value the user set there would be silently
overwritten by the wizard-selected bone(s)/intensity key at generation time.
Declaration
public static IReadOnlyList<string> GetWizardManagedFieldNames(Type layerType)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | layerType |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<string> |
IsValidAssetPath(string, out string)
Validates an asset path.
Declaration
public static bool IsValidAssetPath(string path, out string error)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to validate. |
| string | error | Error message if validation fails. |
Returns
| Type | Description |
|---|---|
| bool | True if valid, false otherwise. |
NormalizePath(string)
Normalizes a path to ensure it starts with "Assets/".
Declaration
public static string NormalizePath(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to normalize. |
Returns
| Type | Description |
|---|---|
| string | Normalized path starting with "Assets/". |
ResolveDefaultIdleLayerIndex(IReadOnlyList<Type>)
Resolves which index in types (as returned by
GetAvailableIdleLayerTypes()) should be pre-selected as the wizard's default idle
animation: PeriodicOscillationLayerSO — the long-standing "breathing" idle every
prior version of this wizard generated unconditionally — wherever it appears in the list, not
index 0. Alphabetical sort (the list's own order) does not put it first, so defaulting to index 0
would silently pick a different layer type than the one the wizard has always produced. Falls back
to 0 only if the type is somehow absent from the catalog (never true for a normal project, since
the type ships with the module) or the list is empty.
Declaration
public static int ResolveDefaultIdleLayerIndex(IReadOnlyList<Type> types)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<Type> | types |
Returns
| Type | Description |
|---|---|
| int |
SelectBestPrimaryBone(List<string>)
Selects the best primary bone from a list of bone IDs for periodic oscillation. Priority: chest bones > spine bones > first bone > "Chest" fallback. Delegates to SelectBestPrimaryBone(List<string>) (the engine-agnostic rule).
Declaration
public static string SelectBestPrimaryBone(List<string> boneIds)
Parameters
| Type | Name | Description |
|---|---|---|
| List<string> | boneIds | List of bone IDs to choose from. |
Returns
| Type | Description |
|---|---|
| string | The best bone ID for periodic oscillation. |