예제 #1
0
        public bool TryGetValue(CustomStyleProperty <Color> property, out Color value)
        {
            if (m_CustomProperties != null && m_CustomProperties.TryGetValue(property.name, out var customProp))
            {
                var handle = customProp.handle;
                switch (handle.valueType)
                {
                case StyleValueType.Enum:
                {
                    var colorName = customProp.sheet.ReadAsString(handle);
                    return(StyleSheetColor.TryGetColor(colorName.ToLower(), out value));
                }

                case StyleValueType.Color:
                {
                    if (customProp.sheet.TryReadColor(customProp.handle, out value))
                    {
                        return(true);
                    }
                    break;
                }

                default:
                    LogCustomPropertyWarning(property.name, StyleValueType.Color, customProp);
                    break;
                }
            }

            value = Color.clear;
            return(false);
        }
예제 #2
0
 public static Color GetColor(this StyleSheet styleSheet, StyleValueHandle valueHandle)
 {
     if (valueHandle.valueType == StyleValueType.Enum)
     {
         var colorName = styleSheet.ReadAsString(valueHandle);
         StyleSheetColor.TryGetColor(colorName.ToLower(), out var value);
         return(value);
     }
     return(styleSheet.ReadColor(valueHandle));
 }
        public static Color GetColor(this StyleSheet styleSheet, StyleValueHandle valueHandle)
        {
#if UNITY_2019_3_OR_NEWER
            if (valueHandle.valueType == StyleValueType.Enum)
            {
                var colorName = styleSheet.ReadAsString(valueHandle);
                StyleSheetColor.TryGetColor(colorName.ToLower(), out var value);
                return(value);
            }
#endif
            return(styleSheet.ReadColor(valueHandle));
        }
        public static IEnumerable <VariableInfo> GetAllAvailableVariables(VisualElement currentVisualElement, StyleValueType[] compatibleTypes, bool editorExtensionMode)
        {
            return(currentVisualElement.variableContext.variables
                   .Where(variable =>
            {
                if (variable.name == BuilderConstants.SelectedStyleRulePropertyName)
                {
                    return false;
                }

                if (!editorExtensionMode && variable.sheet.IsUnityEditorStyleSheet())
                {
                    return false;
                }

                var valueHandle = variable.handles[0];
                var valueType = valueHandle.valueType;
                if (valueType == StyleValueType.Enum)
                {
                    var colorName = variable.sheet.ReadAsString(valueHandle);
                    if (StyleSheetColor.TryGetColor(colorName.ToLower(), out var color))
                    {
                        valueType = StyleValueType.Color;
                    }
                }

                return (compatibleTypes == null || compatibleTypes.Contains(valueType)) && !variable.name.StartsWith("--unity-theme");
            })
                   .Distinct()
                   .Select(variable =>
            {
                string descr = null;
                if (variable.sheet.IsUnityEditorStyleSheet())
                {
                    editorVariableDescriptions.TryGetValue(variable.name, out descr);
                }
                return new VariableInfo(variable, descr);
            }));
        }