https://github.com/cyi0310/animator-parameter
在Unity的專案環境下,使用指定的Attribute,能取得Animator內部的Parameter功能
https://github.com/cyi0310/animator-parameter
animator-parameter csharp unity
Last synced: 2 months ago
JSON representation
在Unity的專案環境下,使用指定的Attribute,能取得Animator內部的Parameter功能
- Host: GitHub
- URL: https://github.com/cyi0310/animator-parameter
- Owner: Cyi0310
- License: mit
- Created: 2025-04-13T03:02:34.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-08T14:53:27.000Z (about 1 year ago)
- Last Synced: 2025-06-08T15:35:31.510Z (about 1 year ago)
- Topics: animator-parameter, csharp, unity
- Language: C#
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Animator Parameter
#### [README_ZH](https://github.com/Cyi0310/Animator-Parameter/blob/main/README_ZH.md)
`AnimatorParameter` is a custom Unity attribute that automatically lists available parameters from the specified Animator directly in the Inspector. This helps prevent human errors caused by manually typing strings and reduces the chances of compilation or runtime issues due to incorrect parameter names.
## Demo
> 
## Feature
- Automatically lists Animator parameter names
- Selectable in the Inspector without manual input
- Prevents typos and invalid parameter references
- Supports both `Animator Component in the scene` and `AnimatorController Asset file in the project`.
## How to use
- Create an `Animator` or `AnimatorController` field
- Create a string field to store the parameter name
- Apply [AnimatorParameter(nameof(anim))] to the string field
This allows you to select the corresponding parameter from a dropdown in the Inspector.
### Scenario 1: Using the Animator Component in the scene
```csharp
public class UseParameterSimple : MonoBehaviour
{
[SerializeField]
private Animator anim;
// Apply the AnimatorParameter attribute to the string field
[SerializeField, AnimatorParameter(nameof(anim))]
private string animParameter;
}
```
### Scenario 2: Using the AnimatorController Asset file in the project
``` C#
public class UseParameterSimple2 : MonoBehaviour
{
[SerializeField]
private AnimatorController controllerAsset;
// Apply the AnimatorParameter attribute to the string field
[SerializeField, AnimatorParameter(nameof(controllerAsset))]
private string controllerAssetParam;
}
```
### Scenario 3: Supports cross-hierarchy inheritance to retrieve the field
``` C#
public class BaseEntity : MonoBehaviour
{
[SerializeField]
protected Animator anim;
}
public class ChildEntity : BaseEntity
{
// The child class can directly reference the parent class's anim field
[SerializeField, AnimatorParameter(nameof(anim))]
private string jumpParam;
}
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.