private void BuildPropertyDictionary() { // Populate the dictionary from the serialized values _properties = new Dictionary <int, Dictionary <ulong, StylezPropertyValue> >(); _selectorBase = new Dictionary <ulong, ulong>(); if (_styles == null) { return; } foreach (var serializedStyle in _styles) { var styleNameHashId = StylezStyle.StringToHash(serializedStyle.selector.name); var selector = MakeSelector(styleNameHashId, (StylezState)serializedStyle.selector.state); // Inheritence if (!string.IsNullOrEmpty(serializedStyle.inherit.name)) { var inheritNameHashId = StylezStyle.StringToHash(serializedStyle.inherit.name); // If both states are "All" then inherit each state individually if (serializedStyle.selector.state == -1 && serializedStyle.inherit.state == -1) { foreach (var state in Enum.GetValues(typeof(StylezState)) as StylezState[]) { SetBaseSelector(MakeSelector(styleNameHashId, state), MakeSelector(inheritNameHashId, state)); } } // If no state was specified for the selector then set all states for this selector to the same base state else if (serializedStyle.selector.state == -1) { var baseSelector = MakeSelector(inheritNameHashId, (StylezState)serializedStyle.inherit.state); foreach (var state in Enum.GetValues(typeof(StylezState)) as StylezState[]) { SetBaseSelector(MakeSelector(styleNameHashId, state), baseSelector); } } // If no state was specified for the base then use the normal state else if (serializedStyle.inherit.state == -1) { SetBaseSelector(selector, MakeSelector(inheritNameHashId, StylezState.Normal)); } // Inerit one state from another.. else { SetBaseSelector(selector, MakeSelector(inheritNameHashId, (StylezState)serializedStyle.inherit.state)); } } foreach (var serializedProperty in serializedStyle.properties) { var propertyNameHashId = StylezStyle.StringToHash(serializedProperty.name); if (!_properties.TryGetValue(propertyNameHashId, out var selectors)) { selectors = new Dictionary <ulong, StylezPropertyValue>(); _properties[propertyNameHashId] = selectors; } if (!StylezStyle._propertyInfos.TryGetValue(propertyNameHashId, out var propertyInfo)) { Debug.LogWarning($"Unknown property \"{name}\" in style sheet"); return; } var property = propertyInfo.Parse(serializedProperty.value); if (null == property) { return; } selectors[selector] = property; } } }
public bool TryGetValue <T> (StylezStyle style, string propertyName, out T value) => TryGetValue <T>(style, StylezStyle.StringToHash(propertyName), out value);