// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Utilities
{
///
/// A copy of the AnimatorControllerParameter because that class is not Serializable and cannot be modified in the editor.
///
[Serializable]
public struct AnimatorParameter
{
///
/// Constructor.
///
/// Name of the animation parameter to modify.
/// Type of the animation parameter to modify.
/// If the animation parameter type is an int, value to set. Ignored otherwise.
/// If the animation parameter type is a float, value to set. Ignored otherwise.
/// "If the animation parameter type is a bool, value to set. Ignored otherwise.
public AnimatorParameter(string name, AnimatorControllerParameterType parameterType, int defaultInt = 0, float defaultFloat = 0f, bool defaultBool = false)
{
this.parameterType = parameterType;
this.defaultInt = defaultInt;
this.defaultFloat = defaultFloat;
this.defaultBool = defaultBool;
this.name = name;
nameStringHash = null;
}
[SerializeField]
[Tooltip("Type of the animation parameter to modify.")]
private AnimatorControllerParameterType parameterType;
///
/// Type of the animation parameter to modify.
///
public AnimatorControllerParameterType ParameterType => parameterType;
[SerializeField]
[Tooltip("If the animation parameter type is an int, value to set. Ignored otherwise.")]
private int defaultInt;
///
/// If the animation parameter type is an int, value to set. Ignored otherwise.
///
public int DefaultInt => defaultInt;
[SerializeField]
[Tooltip("If the animation parameter type is a float, value to set. Ignored otherwise.")]
private float defaultFloat;
///
/// If the animation parameter type is a float, value to set. Ignored otherwise.
///
public float DefaultFloat => defaultFloat;
[SerializeField]
[Tooltip("If the animation parameter type is a bool, value to set. Ignored otherwise.")]
private bool defaultBool;
///
/// If the animation parameter type is a bool, value to set. Ignored otherwise.
///
public bool DefaultBool => defaultBool;
[SerializeField]
[Tooltip("Name of the animation parameter to modify.")]
private string name;
///
/// Name of the animation parameter to modify.
///
public string Name => name;
private int? nameStringHash;
///
/// Animator Name String to Hash.
///
public int NameHash
{
get
{
if (!nameStringHash.HasValue && !string.IsNullOrEmpty(Name))
{
nameStringHash = Animator.StringToHash(Name);
}
Debug.Assert(nameStringHash != null);
return nameStringHash.Value;
}
}
}
}