Conversation
- 添加缓存机制以优化动画参数的获取,减少重复计算 - 更新获取参数值的方法,支持从 Animator 中获取外部参数 - 扩展 AnimatorParamInfo 以包含 IsExternal 属性,区分内部和外部参数 - 改进 UpdateAnimatorParamsCache 方法,确保参数列表的准确性和完整性
- 新增 ModelParameterDriver 组件,支持多种参数操作类型(Set、Add、Random、Copy) - 支持所有 Animator 参数类型,并在动画状态进入时自动应用参数驱动 - 新增 AnimatorParameterDriverManager 管理器,统一管理参数驱动逻辑 - 增强动画参数显示功能,添加参数缓存机制和外部参数支持 - 新增 BlueprintID 组件,用于为游戏对象分配唯一标识符 - 更新 DuckovGameLibs 依赖版本至 1.2.5-Steam
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive animation parameter driver system to support runtime parameter control within Unity animation state machines, along with enhanced parameter display capabilities.
Key Changes:
- Introduced
ModelParameterDrivercomponent andAnimatorParameterDriverManagerto enable custom parameter control in animation states with support for Set, Add, Random, and Copy operations across all Animator parameter types - Enhanced the animator parameter display UI with caching mechanism and support for showing external parameters defined in Animator controllers alongside custom parameters
- Updated dependency
DuckovGameLibsfrom version 1.1.6-Steam to 1.2.5-Steam
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| DuckovCustomModel.Core/MonoBehaviours/Animators/ModelParameterDriver.cs | New component implementing StateMachineBehaviour to drive animator parameters on state enter with JSON serialization support |
| DuckovCustomModel.Core/Managers/AnimatorParameterDriverManager.cs | New manager providing initialization and application logic for parameter drivers with validation |
| DuckovCustomModel.Core/MonoBehaviours/Packages/BlueprintID.cs | New placeholder component for assigning unique IDs to game objects (no functionality yet) |
| DuckovCustomModel/UI/ConfigWindow.cs | Enhanced with parameter caching and support for displaying both custom and external animator parameters |
| DuckovCustomModel.Core/Data/CustomAnimatorHash.cs | Added IsExternal property to distinguish between custom and animator controller parameters |
| DuckovCustomModel/DuckovCustomModel.csproj | Updated DuckovGameLibs dependency to version 1.2.5-Steam |
| DuckovCustomModel.Core/DuckovCustomModel.Core.csproj | Updated DuckovGameLibs dependency to version 1.2.5-Steam |
| DuckovCustomModel/Constant.cs | Updated ModVersion to 1.8.6 |
| CHANGELOG.md, CHANGELOG_EN.md | Added changelog entries for version 1.8.6 |
| DuckovCustomModel.Core/Data/SoundPlayMode.cs | Removed trailing blank line |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public float destMin; | ||
| public float destMax; |
There was a problem hiding this comment.
The fields destMin and destMax are defined but never used. The range conversion logic in AnimatorParameterDriverManager.ApplyParameterAsCopy (lines 172-173) uses valueMin and valueMax instead. Either remove these unused fields or update the range conversion logic to use them if they were intended for a different purpose than valueMin/valueMax.
| public float destMin; | |
| public float destMax; |
| animator.SetFloat(targetParam.name, randomFloat); | ||
| break; | ||
| case AnimatorControllerParameterType.Int: | ||
| var randomInt = Random.Range((int)parameter.valueMin, (int)parameter.valueMax); |
There was a problem hiding this comment.
Unity's Random.Range for integers is exclusive on the upper bound, meaning Random.Range((int)parameter.valueMin, (int)parameter.valueMax) will never return valueMax. This differs from the float version which is inclusive. Consider documenting this behavior or adding 1 to valueMax if inclusive behavior is intended: Random.Range((int)parameter.valueMin, (int)parameter.valueMax + 1).
| var randomInt = Random.Range((int)parameter.valueMin, (int)parameter.valueMax); | |
| var randomInt = Random.Range((int)parameter.valueMin, (int)parameter.valueMax + 1); |
| public class ModelParameterDriver : StateMachineBehaviour, ISerializationCallbackReceiver | ||
| { |
There was a problem hiding this comment.
[nitpick] The class lacks documentation explaining its purpose and usage. Consider adding a summary comment explaining that this component drives animator parameters when animation states are entered, similar to Unity's built-in Animator Parameter Driver behavior. This would help users understand how to use it in their animation state machines.
| public class ModelParameterDriver : StateMachineBehaviour, ISerializationCallbackReceiver | |
| { | |
| /// <summary> | |
| /// Drives animator parameters when animation states are entered, similar to Unity's built-in Animator Parameter Driver. | |
| /// Attach this component to animation state machine states to automatically set, add, randomize, or copy animator parameters | |
| /// when the state is entered. Useful for controlling complex animation logic and parameter changes in a modular way. | |
| /// </summary> | |
| public class ModelParameterDriver : StateMachineBehaviour, ISerializationCallbackReceiver |
|
|
||
| public object? DestParam; |
There was a problem hiding this comment.
[nitpick] Public properties DestParam and SourceParam store cached parameter references but lack documentation explaining their purpose and that they are populated during initialization. Consider adding XML documentation comments to clarify that these are runtime-only cached values used for performance optimization.
| public object? DestParam; | |
| /// <summary> | |
| /// Runtime-only cached reference to the destination parameter. | |
| /// Populated during initialization for performance optimization. | |
| /// Not intended to be set manually or serialized. | |
| /// </summary> | |
| public object? DestParam; | |
| /// <summary> | |
| /// Runtime-only cached reference to the source parameter. | |
| /// Populated during initialization for performance optimization. | |
| /// Not intended to be set manually or serialized. | |
| /// </summary> |
| namespace DuckovCustomModel.Core.MonoBehaviours.Packages | ||
| { | ||
| [AddComponentMenu("Duckov Custom Model/Blueprint ID")] | ||
| [DisallowMultipleComponent] |
There was a problem hiding this comment.
[nitpick] The class lacks documentation explaining its purpose. According to the PR description, it "assigns unique identifiers to game objects" but currently has no functionality. Consider adding a summary comment explaining its intended purpose and that it's currently a placeholder for future functionality.
| [DisallowMultipleComponent] | |
| [DisallowMultipleComponent] | |
| /// <summary> | |
| /// Assigns unique identifiers to game objects. Currently a placeholder for future functionality. | |
| /// </summary> |
| [AddComponentMenu("Duckov Custom Model/Blueprint ID")] | ||
| [DisallowMultipleComponent] | ||
| public class BlueprintID : MonoBehaviour | ||
| { |
There was a problem hiding this comment.
[nitpick] The public field id should have a tooltip attribute to explain its purpose in the Unity Inspector. Consider adding [Tooltip("Unique identifier for this game object")] above the field declaration to improve usability for users configuring this component in Unity.
| { | |
| { | |
| [Tooltip("Unique identifier for this game object")] |
| var targetMin = parameter.valueMin; | ||
| var targetMax = parameter.valueMax; | ||
|
|
||
| if (sourceMax - sourceMin != 0) |
There was a problem hiding this comment.
Equality checks on floating point values can yield unexpected results.
| if (sourceMax - sourceMin != 0) | |
| if (Mathf.Abs(sourceMax - sourceMin) > Mathf.Epsilon) |
主要更新
新增 \ModelParameterDriver\ 组件,支持在动画状态机中自定义参数控制
新增 \AnimatorParameterDriverManager\ 管理器,统一管理参数驱动的初始化和应用逻辑
增强动画参数显示器功能:
新增 \BlueprintID\ 组件,用于为游戏对象分配唯一标识符(当前暂无实际功能)
更新依赖版本:\DuckovGameLibs\ 从 1.1.6-Steam 更新到 1.2.5-Steam
相关提交