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 Int properties
  /// </summary>
  [AddComponentMenu("UI/Animate UI Material/GraphicPropertyOverrideInt")]
  public class GraphicPropertyOverrideInt : GraphicPropertyOverride<int>
  {
    /// <summary>
    ///   Apply the modified property to the material
    /// </summary>
    /// <param name="material"></param>
    public override void ApplyModifiedProperty(Material material)
    {
      material.SetInteger(PropertyId, propertyValue);
    }

    /// <summary>
    /// Retrieve the default int value from the source material
    /// </summary>
    /// <param name="material">The source material</param>
    /// <param name="defaultValue">The int value from the material</param>
    /// <returns>True if the value could be retrieved</returns>
    public override bool GetDefaultValue(Material material, out int defaultValue)
    {
      bool hasProperty = material.HasInteger(PropertyId);
      if (hasProperty) defaultValue = material.GetInteger(PropertyId);
      else defaultValue = default;
      return hasProperty;
    }
  }
}