Skip to content

Commit 539c687

Browse files
committed
Add AnimatorParameter data structure for managing hashes
1 parent 9214929 commit 539c687

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using UnityEngine;
2+
3+
namespace Zigurous.Animation
4+
{
5+
/// <summary>
6+
/// An animation parameter that can be set on an animator. A hash id is
7+
/// automatically created for the parameter for optimal code.
8+
/// </summary>
9+
[System.Serializable]
10+
public struct AnimatorParameter
11+
{
12+
[SerializeField]
13+
[HideInInspector]
14+
private int _hash;
15+
16+
/// <summary>
17+
/// The hash id of the animation parameter.
18+
/// </summary>
19+
public int hash => _hash;
20+
21+
[SerializeField]
22+
[Tooltip("The name of the animation parameter.")]
23+
private string _name;
24+
25+
/// <summary>
26+
/// The name of the animation parameter.
27+
/// </summary>
28+
public string name
29+
{
30+
get => _name;
31+
set
32+
{
33+
_name = value;
34+
_hash = Animator.StringToHash(value);
35+
}
36+
}
37+
38+
/// <summary>
39+
/// Constructs a new animation parameter with the given name.
40+
/// </summary>
41+
public AnimatorParameter(string name)
42+
{
43+
_name = name;
44+
_hash = Animator.StringToHash(name);
45+
}
46+
47+
/// <summary>
48+
/// Generates a new hash for the parameter using the current name.
49+
/// </summary>
50+
public int GenerateHash()
51+
{
52+
_hash = Animator.StringToHash(_name);
53+
return _hash;
54+
}
55+
56+
public static implicit operator AnimatorParameter(string name) => new AnimatorParameter(name);
57+
58+
}
59+
60+
}

Runtime/DataStructures/AnimatorParameter.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)