// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Experimental.StateVisualizer
{
///
/// The ShaderFloat animatable property adds/sets keyframes for a defined shader property of type Float in an animation clip.
///
public class ShaderFloatStateAnimatableProperty : ShaderStateAnimatableProperty
{
[SerializeField]
[Tooltip("The float value for the defined shader property. ")]
private float shaderPropertyFloatValue;
///
/// The float value for the defined shader property.
///
public float ShaderPropertyFloatValue
{
get => shaderPropertyFloatValue;
set => shaderPropertyFloatValue = value;
}
///
/// Constructor for a Shader Float Animatable Property. Sets the default AnimatablePropertyName.
///
public ShaderFloatStateAnimatableProperty()
{
AnimatablePropertyName = "ShaderFloat";
}
///
public override void SetKeyFrames(AnimationClip animationClip)
{
if (Target != null)
{
string targetPath = GetTargetPath(Target);
string propertyName = GetPropertyName(ShaderPropertyName);
if (propertyName != null)
{
float currentValue = Target.GetComponent().sharedMaterial.GetFloat(propertyName);
AnimationCurve curve = AnimationCurve.EaseInOut(0, currentValue, AnimationDuration, ShaderPropertyFloatValue);
animationClip.SetCurve(targetPath, typeof(MeshRenderer), "material." + propertyName, curve);
}
}
}
///
public override void RemoveKeyFrames(AnimationClip animationClip)
{
if (Target != null)
{
string targetPath = GetTargetPath(Target);
animationClip.SetCurve(targetPath, typeof(MeshRenderer), "material." + GetPropertyName(ShaderPropertyName), null);
}
}
}
}