Пример #1
0
        /// <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);
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
 /// <inheritdoc />
 public bool RemoveAttribute(OverridableAttribute attribute)
 {
     return(m_Attributes.Remove(attribute));
 }