/// <inheritdoc /> public void AddAttribute(OverridableAttribute attribute) { if (m_Attributes.Any(x => x.attributeName == attribute.attributeName)) { throw new ArgumentException($"The attribute with the name: {attribute.attributeName} already exists."); } m_Attributes.Add(attribute); }
private void Awake() { m_SourceAttribute = m_Style.value[m_AttributeName]; if (Application.isPlaying) { Assert.IsFalse(string.IsNullOrEmpty(m_AttributeName), "The attribute name cannot be null"); UpdateProperty(); } }
/// <inheritdoc /> public T GetAttribute <T>(string attributeName) where T : OverridableAttribute { OverridableAttribute attribute = m_Attributes.FirstOrDefault(x => x.attributeName == attributeName); if (attribute == null) { throw new ArgumentException($"The attribute with the name: {attribute.attributeName} already exists."); } return(attribute as T); }
/// <inheritdoc /> public bool TryGetAttribute <T>(string attributeName, out T attribute) where T : OverridableAttribute { attribute = null; OverridableAttribute a = m_Attributes.FirstOrDefault(x => x.attributeName == attributeName); if (a != null) { attribute = a as T; return(true); } return(false); }
/// <inheritdoc /> public void SetAttributeValue <T>(string attributeName, T attributeValue) { if (string.IsNullOrWhiteSpace(attributeName)) { throw new ArgumentNullException(nameof(attributeName)); } OverridableAttribute a = m_Attributes.FirstOrDefault(x => x.attributeName == attributeName); if (a == null) { throw new Exception($"Could not find Attribute named {attributeName}."); } a.Set(attributeValue); }
/// <inheritdoc /> public bool RemoveAttribute(OverridableAttribute attribute) { return(m_Attributes.Remove(attribute)); }