Skip to content

feat: 添加 ModelParameterDriver 以支持自定义参数控制并增强参数显示器#14

Merged
BAKAOLC merged 3 commits into
mainfrom
develop
Nov 21, 2025
Merged

feat: 添加 ModelParameterDriver 以支持自定义参数控制并增强参数显示器#14
BAKAOLC merged 3 commits into
mainfrom
develop

Conversation

@BAKAOLC

@BAKAOLC BAKAOLC commented Nov 21, 2025

Copy link
Copy Markdown
Collaborator

主要更新

  • 新增 \ModelParameterDriver\ 组件,支持在动画状态机中自定义参数控制

    • 支持多种参数操作类型:Set、Add、Random、Copy
    • 支持所有 Animator 参数类型(Float、Int、Bool、Trigger)
    • 在动画状态进入时自动应用参数驱动
    • 支持参数验证,确保目标参数和源参数存在后才应用驱动
  • 新增 \AnimatorParameterDriverManager\ 管理器,统一管理参数驱动的初始化和应用逻辑

  • 增强动画参数显示器功能:

    • 添加参数缓存机制,优化参数获取性能,减少重复计算
    • 支持显示 Animator 控制器中定义的外部参数,默认排列在列表末尾
  • 新增 \BlueprintID\ 组件,用于为游戏对象分配唯一标识符(当前暂无实际功能)

  • 更新依赖版本:\DuckovGameLibs\ 从 1.1.6-Steam 更新到 1.2.5-Steam

相关提交

  • f694b32: feat: 添加 AnimatorParameterDriverManager 和 ModelParameterDriver 以支持动画参数驱动
  • 140679d: feat: 增强动画参数管理功能

- 添加缓存机制以优化动画参数的获取,减少重复计算
- 更新获取参数值的方法,支持从 Animator 中获取外部参数
- 扩展 AnimatorParamInfo 以包含 IsExternal 属性,区分内部和外部参数
- 改进 UpdateAnimatorParamsCache 方法,确保参数列表的准确性和完整性
- 新增 ModelParameterDriver 组件,支持多种参数操作类型(Set、Add、Random、Copy)
- 支持所有 Animator 参数类型,并在动画状态进入时自动应用参数驱动
- 新增 AnimatorParameterDriverManager 管理器,统一管理参数驱动逻辑
- 增强动画参数显示功能,添加参数缓存机制和外部参数支持
- 新增 BlueprintID 组件,用于为游戏对象分配唯一标识符
- 更新 DuckovGameLibs 依赖版本至 1.2.5-Steam
Copilot AI review requested due to automatic review settings November 21, 2025 10:02
@BAKAOLC BAKAOLC merged commit 9540050 into main Nov 21, 2025
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ModelParameterDriver component and AnimatorParameterDriverManager to 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 DuckovGameLibs from 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.

Comment on lines +84 to +85
public float destMin;
public float destMax;

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
public float destMin;
public float destMax;

Copilot uses AI. Check for mistakes.
animator.SetFloat(targetParam.name, randomFloat);
break;
case AnimatorControllerParameterType.Int:
var randomInt = Random.Range((int)parameter.valueMin, (int)parameter.valueMax);

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
var randomInt = Random.Range((int)parameter.valueMin, (int)parameter.valueMax);
var randomInt = Random.Range((int)parameter.valueMin, (int)parameter.valueMax + 1);

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +9
public class ModelParameterDriver : StateMachineBehaviour, ISerializationCallbackReceiver
{

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +86 to +87

public object? DestParam;

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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>

Copilot uses AI. Check for mistakes.
namespace DuckovCustomModel.Core.MonoBehaviours.Packages
{
[AddComponentMenu("Duckov Custom Model/Blueprint ID")]
[DisallowMultipleComponent]

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
[DisallowMultipleComponent]
[DisallowMultipleComponent]
/// <summary>
/// Assigns unique identifiers to game objects. Currently a placeholder for future functionality.
/// </summary>

Copilot uses AI. Check for mistakes.
[AddComponentMenu("Duckov Custom Model/Blueprint ID")]
[DisallowMultipleComponent]
public class BlueprintID : MonoBehaviour
{

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
{
{
[Tooltip("Unique identifier for this game object")]

Copilot uses AI. Check for mistakes.
var targetMin = parameter.valueMin;
var targetMax = parameter.valueMax;

if (sourceMax - sourceMin != 0)

Copilot AI Nov 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equality checks on floating point values can yield unexpected results.

Suggested change
if (sourceMax - sourceMin != 0)
if (Mathf.Abs(sourceMax - sourceMin) > Mathf.Epsilon)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants