ProjectDDD/Assets/Plugins/Animate UI Materials/GraphicPropertyOverrideVector.cs

36 lines
1.3 KiB
C#

using UnityEngine;
namespace Plugins.Animate_UI_Materials
{
/// <summary>
/// Used in with GraphicMaterialOverride to modify a material without creating a variant
/// Added to a child of the Graphic element
/// This variant only applies to Vector properties
/// </summary>
[AddComponentMenu("UI/Animate UI Material/GraphicPropertyOverrideVector")]
public class GraphicPropertyOverrideVector : GraphicPropertyOverride<Vector4>
{
/// <summary>
/// Apply the modified property to the material
/// </summary>
/// <param name="material"></param>
public override void ApplyModifiedProperty(Material material)
{
material.SetVector(PropertyId, propertyValue);
}
/// <summary>
/// Retrieve the default Vector value from the source material
/// </summary>
/// <param name="material">The source material</param>
/// <param name="defaultValue">The Vector value from the material</param>
/// <returns>True if the value could be retrieved</returns>
public override bool GetDefaultValue(Material material, out Vector4 defaultValue)
{
bool hasProperty = material.HasVector(PropertyId);
if (hasProperty) defaultValue = material.GetVector(PropertyId);
else defaultValue = default;
return hasProperty;
}
}
}