Ejemplo n.º 1
0
        /// <summary>
        /// Gets the image data.
        /// </summary>
        /// <param name="graphic">The graphic to check.</param>
        /// <returns>The ImageData, if applicable and one exists.</returns>
        public static ImageData GetImageData(this Graphic graphic)
        {
            Sprite sprite = graphic.GetSpriteImage();

            ExternalImage externalImage = graphic != null?graphic.GetComponent <ExternalImage>() : null;

            var key = externalImage != null ? externalImage.Key : null;

            sprite = externalImage != null && externalImage.DefaultSprite != null ? externalImage.DefaultSprite : sprite;

            if (!string.IsNullOrEmpty(key))
            {
                return(new ImageData(key, sprite));
            }
            else if (sprite != null)
            {
                return(new ImageData(sprite));
            }

            VectorImageData vectorImageData = graphic.GetVectorImage();

            if (vectorImageData != null)
            {
                return(new ImageData(vectorImageData));
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the image of a Graphic (must be of type VectorImage).
        /// </summary>
        /// <param name="graphic">The graphic to modify.</param>
        /// <param name="vectorImageData">The vector image data to set.</param>
        public static void SetImage(this Graphic graphic, VectorImageData vectorImageData)
        {
            VectorImage imageToSet = graphic as VectorImage;

            if (imageToSet != null)
            {
                imageToSet.vectorImageData = vectorImageData;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the ripple. Only called when a ripple is actually created and not needed when reused.
        /// </summary>
        /// <param name="id">The global identifier of the ripple.</param>
        /// <param name="imageData">The image data to use for the ripple.</param>
        public void Create(int id, VectorImageData imageData)
        {
            m_Id          = id;
            m_CanvasGroup = GetComponent <CanvasGroup>();

            if (m_RippleMaterial == null)
            {
                m_RippleMaterial = m_Material;
            }
        }
        public static void Show(VectorImageData data, Object objectToRefresh)
        {
            m_VectorImageData = data;
            m_ObjectToRefresh = objectToRefresh;

            VectorImagePickerWindow window = CreateInstance<VectorImagePickerWindow>();
            window.ShowAuxWindow();
            window.minSize = new Vector2(397, 446);
            window.titleContent = new GUIContent("Icon Picker");

			m_PreviewSize = EditorPrefs.GetInt("ICON_CONFIG_PREVIEW_SIZE", 48);
        }
        public static void Show(VectorImageData data, Object objectToRefresh)
        {
            m_VectorImageData = data;
            m_ObjectToRefresh = objectToRefresh;

            VectorImagePickerWindow window = CreateInstance <VectorImagePickerWindow>();

            window.ShowAuxWindow();
            window.minSize      = new Vector2(397, 446);
            window.titleContent = new GUIContent("Icon Picker");

            m_PreviewSize = EditorPrefs.GetInt("ICON_CONFIG_PREVIEW_SIZE", 48);
        }
Ejemplo n.º 6
0
        public static void VectorImageDataField(string label, VectorImageData targetData, Object targetObject)
        {
            string   code      = targetData.glyph.unicode;
            string   name      = targetData.glyph.name;
            Font     font      = targetData.font;
            GUIStyle iconStyle = new GUIStyle {
                font = font, fontSize = 16
            };

            float offsetH = 0;

            offsetH += 40;
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(label);
                EditorGUILayout.LabelField("", GUILayout.MaxWidth(-12f));

                if (!string.IsNullOrEmpty(name))
                {
                    GUIContent widthLabel      = new GUIContent(IconDecoder.Decode(code));
                    float      widthLabelWidth = iconStyle.CalcSize(widthLabel).x;
                    EditorGUILayout.LabelField(widthLabel, iconStyle, GUILayout.MaxWidth(widthLabelWidth));
                    widthLabel      = new GUIContent(name);
                    widthLabelWidth = GUIStyle.none.CalcSize(widthLabel).x;
                    EditorGUILayout.LabelField(name, GUILayout.MaxWidth(widthLabelWidth + 4));
                    GUILayout.FlexibleSpace();
                }
                else
                {
                    EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(96f));
                    GUILayout.FlexibleSpace();
                }

                if (GUILayout.Button("Pick Icon"))
                {
                    VectorImagePickerWindow.Show(targetData, targetObject);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    if (GUILayout.Button(IconDecoder.Decode(@"\ue14c"), new GUIStyle {
                        font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName), fontSize = 20
                    }))
                    {
                        targetData.font  = null;
                        targetData.glyph = new Glyph();
                        EditorUtility.SetDirty(targetObject);
                    }
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty code      = property.FindPropertyRelative("m_Glyph.m_Unicode");
            SerializedProperty name      = property.FindPropertyRelative("m_Glyph.m_Name");
            SerializedProperty font      = property.FindPropertyRelative("m_Font");
            GUIStyle           iconStyle = new GUIStyle {
                font = (Font)font.objectReferenceValue, fontSize = 16
            };

            RectOffset offset = new RectOffset(0, 0, -1, -3);

            position        = offset.Add(position);
            position.height = EditorGUIUtility.singleLineHeight;

            float offsetH = 0;

            offsetH -= EditorGUI.PrefixLabel(new Rect(position.x + offsetH, position.y, 40, position.height), label).width;

            offsetH += 40;

            if (!string.IsNullOrEmpty(name.stringValue))
            {
                GUIContent iconLabel = new GUIContent(IconDecoder.Decode(code.stringValue));
                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, 16, position.height), iconLabel, iconStyle);

                float iconWidth = iconStyle.CalcSize(iconLabel).x;
                offsetH += iconWidth + 2f;

                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, position.width - offsetH - 80, position.height), name.stringValue);
            }
            else
            {
                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, position.width - 70 - 56, position.height), "No icon selected");
            }

            if (GUI.Button(new Rect(position.width - 74, position.y, 70, position.height), "Pick Icon"))
            {
                VectorImagePickerWindow.Show((VectorImageData)fieldInfo.GetValue(property.serializedObject.targetObject), property.serializedObject.targetObject);
            }
            if (GUI.Button(new Rect(position.width - 2, position.y, 18, position.height), IconDecoder.Decode(@"\ue14c"), new GUIStyle {
                font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
            }))
            {
                VectorImageData data = ((VectorImageData)fieldInfo.GetValue(property.serializedObject.targetObject));
                data.font  = null;
                data.glyph = null;
                EditorUtility.SetDirty(property.serializedObject.targetObject);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates the ripple. Only called when a ripple is actually created and not needed when reused.
        /// </summary>
        /// <param name="id">The global identifier of the ripple.</param>
        /// <param name="imageData">The image data to use for the ripple.</param>
        public void Create(int id, VectorImageData imageData)
        {
            if (m_Id != 0)
            {
                Debug.Log("Cannot Setup a Ripple more than once");
                return;
            }

            m_Id          = id;
            m_CanvasGroup = GetComponent <CanvasGroup>();

            if (m_RippleMaterial == null)
            {
                m_RippleMaterial = m_Material;
            }
        }
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImageData. Supports undo/redo.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="targetData">The VectorImageData to modify.</param>
        /// <param name="objectToUndo">The object to mark for undo/redo.</param>
        /// <param name="onIconPickAction">Action to call when an icon is picked.</param>
        /// <param name="disableIfMultipleObjectsSelected">Is this field drawn disabled if multiple GameObjects are selected?</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool VectorImageDataField(string label, VectorImageData targetData, Object objectToUndo,
                                                Action onIconPickAction = null, bool disableIfMultipleObjectsSelected = true)
        {
            using (new DisabledScope(TooManySelected(!disableIfMultipleObjectsSelected)))
            {
                var code      = targetData.glyph.unicode;
                var name      = targetData.glyph.name;
                var font      = targetData.font;
                var iconStyle = new GUIStyle {
                    font = font, fontSize = vectorIconSize
                };
                using (new GUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel(label);
                    if (EditorGUI.indentLevel > 0)
                    {
                        EditorGUILayout.LabelField("",
                                                   GUILayout.MaxWidth(-(2 + vectorImageDataIndentOffsetSize * EditorGUI.indentLevel)));
                    }

                    if (!string.IsNullOrEmpty(name))
                    {
                        var iconGUIContent = new GUIContent(IconDecoder.Decode(code), name);
                        EditorGUILayout.LabelField(iconGUIContent, iconStyle,
                                                   GUILayout.MaxWidth(iconStyle.CalcSize(iconGUIContent).x));

                        if (EditorGUI.indentLevel > 0)
                        {
                            EditorGUILayout.LabelField("",
                                                       GUILayout.MaxWidth(vectorImageDataIndentOffsetSize * EditorGUI.indentLevel));
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("No icon selected",
                                                   GUILayout.MaxWidth(vectorImageDataMaxLabelWidth));
                    }

                    if (GUILayout.Button("Pick Icon", EditorStyles.miniButton, GUILayout.MinHeight(miniButtonHeight)))
                    {
                        VectorImagePickerWindow.Show(targetData, objectToUndo, onIconPickAction);
                    }
                }
            }

            return(true);
        }
        public static void VectorImageDataField(string label, VectorImageData targetData, Object targetObject)
        {
            string code = targetData.glyph.unicode;
            string name = targetData.glyph.name;
            Font font = targetData.font;
            GUIStyle iconStyle = new GUIStyle { font = font, fontSize = 16 };

            float offsetH = 0;

            offsetH += 40;
			using (new GUILayout.HorizontalScope())
			{
				EditorGUILayout.PrefixLabel(label);
				EditorGUILayout.LabelField("", GUILayout.MaxWidth(-12f));
				
				if (!string.IsNullOrEmpty(name))
				{
					GUIContent widthLabel = new GUIContent(IconDecoder.Decode(code));
					float widthLabelWidth = iconStyle.CalcSize(widthLabel).x;
					EditorGUILayout.LabelField(widthLabel, iconStyle, GUILayout.MaxWidth(widthLabelWidth));
					widthLabel = new GUIContent(name);
					widthLabelWidth = GUIStyle.none.CalcSize(widthLabel).x;
					EditorGUILayout.LabelField(name, GUILayout.MaxWidth(widthLabelWidth + 4));
					GUILayout.FlexibleSpace();
				}
				else
				{
					EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(96f));
					GUILayout.FlexibleSpace();
				}
				
				if (GUILayout.Button("Pick Icon"))
				{
					VectorImagePickerWindow.Show(targetData, targetObject);
				}
				
				if (!string.IsNullOrEmpty(name))
				{
					if (GUILayout.Button(IconDecoder.Decode(@"\ue14c"), new GUIStyle { font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName), fontSize = 20 }))
					{
						targetData.font = null;
						targetData.glyph = new Glyph();
						EditorUtility.SetDirty(targetObject);
					}
				}
			}
        }
Ejemplo n.º 11
0
        public static void DrawIconPickLine(VectorImageData data, Object objectToRefresh, bool indent = false)
        {
            using (new GUILayout.HorizontalScope())
            {
                if (data.font == null)
                {
                    data.font = VectorImageManager.GetIconFont(VectorImageManager.GetAllIconSetNames()[0]);
                }

                GUIStyle iconGuiStyle = new GUIStyle {
                    font = VectorImageManager.GetIconFont(data.font.name)
                };

                EditorGUILayout.PrefixLabel("Icon");

                if (indent)
                {
                    EditorGUI.indentLevel--;
                }

                EditorGUILayout.LabelField(IconDecoder.Decode(data.glyph.unicode), iconGuiStyle, GUILayout.Width(18f));
                EditorGUILayout.LabelField(data.glyph.name, GUILayout.MaxWidth(100f), GUILayout.MinWidth(0f));

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Pick icon", EditorStyles.miniButton, GUILayout.MaxWidth(60f)))
                {
                    Show(data, objectToRefresh);
                    return;
                }

                if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.MaxWidth(20f)))
                {
                    for (int i = 0; i < m_VectorImageDatas.Length; i++)
                    {
                        m_VectorImageDatas[i] = null;
                    }
                    return;
                }

                if (indent)
                {
                    EditorGUI.indentLevel++;
                }
            }
        }
Ejemplo n.º 12
0
        public void Create(int id, VectorImageData imageData)
        {
            if (m_Id != 0)
            {
                Debug.Log("Cannot Setup a Ripple more than once");
                return;
            }

            m_Id                         = id;
            m_RectTransform              = GetComponent <RectTransform>();
            m_Image                      = GetComponent <VectorImage>();
            m_CanvasGroup                = GetComponent <CanvasGroup>();
            m_Image.vectorImageData      = imageData;
            m_CanvasGroup.blocksRaycasts = false;
            m_CanvasGroup.interactable   = false;
            gameObject.AddComponent <LayoutElement>().ignoreLayout = true;
        }
Ejemplo n.º 13
0
        public void Create(int id, VectorImageData imageData)
        {
            if (m_Id != 0)
            {
                Debug.Log("Cannot Setup a Ripple more than once");
                return;
            }

            m_Id = id;
            m_RectTransform = GetComponent<RectTransform>();
            m_Image = GetComponent<VectorImage>();
            m_CanvasGroup = GetComponent<CanvasGroup>();
            m_Image.vectorImageData = imageData;
            m_CanvasGroup.blocksRaycasts = false;
            m_CanvasGroup.interactable = false;
            gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the image data.
        /// </summary>
        /// <param name="graphic">The graphic to check.</param>
        /// <returns>The ImageData, if applicable and one exists.</returns>
        public static ImageData GetImageData(this Graphic graphic)
        {
            Sprite sprite = graphic.GetSpriteImage();

            if (sprite != null)
            {
                return(new ImageData(sprite));
            }

            VectorImageData vectorImageData = graphic.GetVectorImage();

            if (vectorImageData != null)
            {
                return(new ImageData(vectorImageData));
            }

            return(null);
        }
Ejemplo n.º 15
0
        public static bool VectorImageDataField(Rect rect, string label, VectorImageData targetData, UnityEngine.Object objectToUndo, Action onIconPickAction = null)
        {
            string   code      = targetData.glyph.unicode;
            string   name      = targetData.glyph.name;
            Font     font      = targetData.font;
            GUIStyle iconStyle = new GUIStyle {
                font = font, fontSize = vectorIconSize
            };

            var v_remainingRect = rect;

            if (!string.IsNullOrEmpty(label))
            {
                var v_prefixLabelRect = new Rect(rect.x, rect.y, rect.width / 2, rect.height);
                EditorGUI.LabelField(v_prefixLabelRect, new GUIContent(label));
                v_remainingRect = new Rect(v_prefixLabelRect.xMax + 5, v_prefixLabelRect.y, rect.width - v_prefixLabelRect.width - 5, rect.height);
            }
            if (!string.IsNullOrEmpty(name))
            {
                GUIContent iconGUIContent  = new GUIContent(IconDecoder.Decode(code), name);
                var        v_iconGlyphRect = new Rect(v_remainingRect.x, v_remainingRect.y, Mathf.Min(v_remainingRect.width, iconStyle.CalcSize(iconGUIContent).x), v_remainingRect.y);
                v_remainingRect.x      = v_iconGlyphRect.xMax + 5;
                v_remainingRect.width -= (v_iconGlyphRect.width + 5);
                EditorGUI.LabelField(v_iconGlyphRect, iconGUIContent, iconStyle);
            }
            else
            {
                var v_noIconRect = new Rect(v_remainingRect.x, v_remainingRect.y, Mathf.Min(v_remainingRect.width, vectorImageDataMaxLabelWidth), v_remainingRect.y);
                v_remainingRect.x      = v_noIconRect.xMax + 5;
                v_remainingRect.width -= (v_noIconRect.width + 5);
                EditorGUI.LabelField(v_noIconRect, "No icon selected");
            }

            var v_buttonRect = new Rect(v_remainingRect.x, v_remainingRect.y, v_remainingRect.width, v_remainingRect.height);

            if (GUI.Button(v_buttonRect, "Pick Icon", EditorStyles.miniButton))
            {
                VectorImagePickerWindow.Show(targetData, objectToUndo, onIconPickAction);
            }

            return(true);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates the ripple. Only called when a ripple is actually created and not needed when reused.
        /// </summary>
        /// <param name="id">The global identifier of the ripple.</param>
        /// <param name="imageData">The image data to use for the ripple.</param>
        public void Create(int id, VectorImageData imageData)
        {
            if (m_Id != 0)
            {
                Debug.Log("Cannot Setup a Ripple more than once");
                return;
            }

            m_Id          = id;
            m_CanvasGroup = GetComponent <CanvasGroup>();

            gameObject.GetAddComponent <Canvas>();

            var layoutElement = gameObject.GetAddComponent <LayoutElement>();

            layoutElement.ignoreLayout = true;

            if (m_RippleMaterial == null)
            {
                m_RippleMaterial = m_Material;
            }
        }
Ejemplo n.º 17
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GetProperties(property);

            Rect pos = position;

            pos.height = EditorGUI.GetPropertyHeight(m_ImageDataType);

            float labelWidth = GUI.skin.GetStyle("Label").CalcSize(label).x;

            float i = EditorGUI.PrefixLabel(new Rect(pos.x, pos.y, labelWidth, pos.height), label).width;

            pos.x     -= i - 54;
            pos.width += i - 55;

            if (property.name.Equals("m_ToggleOnIcon") || property.name.Equals("m_ToggleOffIcon"))
            {
                pos.x     += 33;
                pos.width -= 33;
            }
            else if (property.name.Equals("m_TabIcon"))
            {
                pos.x     -= 3;
                pos.width += 3;
            }

            if (m_ImageDataType.enumValueIndex == 0)
            {
                pos.height = EditorGUI.GetPropertyHeight(m_Sprite);
                EditorGUI.PropertyField(pos, m_Sprite, GUIContent.none);
            }

            if (m_ImageDataType.enumValueIndex == 1)
            {
                pos.height = EditorGUI.GetPropertyHeight(m_VectorImageData);

                SerializedProperty code      = m_VectorImageData.FindPropertyRelative("m_Glyph.m_Unicode");
                SerializedProperty name      = m_VectorImageData.FindPropertyRelative("m_Glyph.m_Name");
                SerializedProperty font      = m_VectorImageData.FindPropertyRelative("m_Font");
                GUIStyle           iconStyle = new GUIStyle {
                    font = (Font)font.objectReferenceValue
                };

                float pickButtonWidth    = 70;
                float pickButtonPadding  = 88;
                float clearButtonWidth   = 18;
                float clearButtonPadding = 14;

                if (!string.IsNullOrEmpty(name.stringValue))
                {
                    EditorGUI.LabelField(new Rect(pos.x, pos.y, 16, pos.height), IconDecoder.Decode(code.stringValue),
                                         iconStyle);
                    pos.x     += 16;
                    pos.width -= 16;
                    EditorGUI.LabelField(new Rect(pos.x, pos.y, pos.width, position.height), name.stringValue);
                }
                else
                {
                    EditorGUI.LabelField(
                        new Rect(pos.x, pos.y, pos.width - (pickButtonWidth + clearButtonWidth), pos.height),
                        "No icon selected");
                }

                if (GUI.Button(new Rect((pos.x + pos.width) - pickButtonPadding, pos.y, pickButtonWidth, pos.height),
                               "Pick Icon"))
                {
                    VectorImagePickerWindow.Show(
                        ((ImageData)fieldInfo.GetValue(m_VectorImageData.serializedObject.targetObject))
                        .vectorImageData, property.serializedObject.targetObject);
                }

                if (GUI.Button(new Rect((pos.x + pos.width - 1) - clearButtonPadding, pos.y, clearButtonWidth, pos.height),
                               IconDecoder.Decode(@"\ue14c"),
                               new GUIStyle {
                    font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                }))
                {
                    VectorImageData data =
                        (((ImageData)fieldInfo.GetValue(m_VectorImageData.serializedObject.targetObject))
                         .vectorImageData);
                    data.font  = null;
                    data.glyph = null;
                    EditorUtility.SetDirty(property.serializedObject.targetObject);
                }
            }
        }
Ejemplo n.º 18
0
        public static ImageData[] ArrayFromVectorArray(VectorImageData[] vectorArray)
        {
            ImageData[] array = new ImageData[vectorArray.Length];

            for (int i = 0; i < vectorArray.Length; i++)
            {
                array[i] = new ImageData(vectorArray[i]);
            }

            return array;
        }
Ejemplo n.º 19
0
 public ImageData(VectorImageData vectorImageData)
 {
     m_VectorImageData = vectorImageData;
     m_ImageDataType = ImageDataType.VectorImage;
 }
Ejemplo n.º 20
0
        protected override void OnValidate()
        {
            if (m_Graphic && m_ChangeGraphicColor)
            {
                if (m_Interactable)
                {
                    m_Graphic.color = toggle.isOn ? m_GraphicOnColor : m_GraphicOffColor;
                }
                else
                {
                    m_Graphic.color = m_GraphicDisabledColor;
                }
            }
            if (materialRipple && m_ChangeRippleColor)
            {
                materialRipple.rippleData.Color = toggle.isOn ? m_RippleOnColor : m_RippleOffColor;
            }

            UpdateGraphicToggleState();

            if (m_Graphic != null)
            {
                if (m_Graphic.IsSpriteOrVectorImage())
                {
                    if (m_Graphic.GetType() == typeof(Image))
                    {
                        if (m_LastIconSprite == m_Icon.sprite)
                        {
                            m_Icon.sprite = m_Graphic.GetSpriteImage();
                        }
                        else
                        {
                            m_Graphic.SetImage(m_Icon.sprite);
                        }

                        m_LastIconSprite = m_Icon.sprite;
                    }
                    else
                    {
                        if (m_LastIconVectorImageData == m_Icon.vectorImageData)
                        {
                            m_Icon.vectorImageData = m_Graphic.GetVectorImage();
                        }
                        else
                        {
                            m_Graphic.SetImage(m_Icon.vectorImageData);
                        }

                        m_LastIconVectorImageData = m_Icon.vectorImageData;
                    }
                }
                else
                {
                    Text text = m_Graphic as Text;
                    if (text != null)
                    {
                        if (m_LastLabelText == m_Label)
                        {
                            m_Label = text.text;
                        }
                        else
                        {
                            text.text = m_Label;
                        }

                        m_LastLabelText = m_Label;
                    }
                }
            }

        }
Ejemplo n.º 21
0
 public static void Show(VectorImageData data, Object objectToRefresh)
 {
     Show(new[] { data }, new[] { objectToRefresh }, null);
 }
 /// <summary>
 ///     Inspector control (eg: EditorGUILayout.SpriteField) for VectorImageData. Supports undo/redo and multiple
 ///     selected objects.
 /// </summary>
 /// <param name="label">The label to appear in the inspector control.</param>
 /// <param name="getReferenceFunc">The function used to get each VectorImageData reference from each selected GameObject.</param>
 /// <param name="objectsToUndo">The objects to mark for undo/redo.</param>
 /// <param name="onIconPickAction">Action to call when an icon is picked.</param>
 /// <param name="visualReference">
 ///     The VectorImageData to use for the 'current' values in the control if the VectorImageData
 ///     values are different.
 /// </param>
 /// <returns>Whether the control was successfully able to be drawn.</returns>
 public static bool VectorImageDataMultiField(string label, Func <GameObject, VectorImageData> getReferenceFunc,
                                              Object[] objectsToUndo, Action onIconPickAction = null, VectorImageData visualReference = null)
 {
     return(VectorImageDataMultiField(label, Selection.gameObjects.Select(getReferenceFunc).ToArray(),
                                      objectsToUndo, onIconPickAction, visualReference));
 }
        protected virtual void DrawResources(string p_name, Color32[] p_colors, Object[] p_graphicAssets, VectorImageData[] p_vectorImageDatas, bool p_readOnly, params GUILayoutOption[] p_options)
        {
            using (new EditorGUILayout.VerticalScope("Box", p_options))
            {
                //Draw Title
                using (new EditorGUILayout.VerticalScope("Box"))
                {
                    EditorGUILayout.LabelField(p_name, EditorStyles.boldLabel);
                }

                var v_oldGui = GUI.enabled;
                if (p_readOnly)
                {
                    GUI.enabled = false;
                }

                if (p_colors.Length > 0)
                {
                    EditorGUILayout.LabelField("Color Palette");
                }
                //Draw Colors
                for (int i = 0; i < p_colors.Length; i++)
                {
                    var v_newColor = EditorGUILayout.ColorField(new GUIContent(), p_colors[i], false, false, false);
                    if (v_newColor != p_colors[i])
                    {
                        _changed = true;
                        if (this != null)
                        {
                            Undo.RecordObject(this, "Color Changed");
                        }
                        p_colors[i] = v_newColor;
                    }
                }

                if (p_graphicAssets.Length > 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Graphic Assets");
                }
                //Draw Object Assets
                for (int i = 0; i < p_graphicAssets.Length; i++)
                {
                    var v_assetObject = p_graphicAssets[i] as Object;

                    if (v_assetObject != null)
                    {
                        var v_newAssetObject = EditorGUILayout.ObjectField(v_assetObject, v_assetObject.GetType(), false);
                        if (v_newAssetObject != null && v_newAssetObject != v_assetObject)
                        {
                            _changed = true;
                            if (this != null)
                            {
                                Undo.RecordObject(this, "Asset Changed");
                            }
                            p_graphicAssets[i] = v_newAssetObject;
                        }
                    }
                }
                if (p_vectorImageDatas.Length > 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("VectorImage Assets");
                }
                //Draw VectorImageDatas
                for (int i = 0; i < p_vectorImageDatas.Length; i++)
                {
                    var v_vectorImgData = p_vectorImageDatas[i] as VectorImageData;

                    if (v_vectorImgData != null)
                    {
                        var v_indexToSet = i;
                        var v_newImgData = new VectorImageData(new Glyph(v_vectorImgData.glyph.name, v_vectorImgData.glyph.unicode, false), v_vectorImgData.vectorFont);
                        MaterialUI.InspectorFields.VectorImageDataField("", v_newImgData, m_target, () =>
                        {
                            if (v_newImgData != v_vectorImgData)
                            {
                                _changed = true;
                                if (this != null)
                                {
                                    Undo.RecordObject(this, "VectorImage Changed");
                                }
                                p_vectorImageDatas[v_indexToSet] = v_newImgData;
                                Repaint();
                            }
                        });
                    }
                }
                GUI.enabled = v_oldGui;
            }
        }
Ejemplo n.º 24
0
        public static void DrawIconPickLine(VectorImageData data, Object objectToRefresh, bool indent = false)
        {
			using (new GUILayout.HorizontalScope())
			{
				if (data.font == null)
				{
					data.font = VectorImageManager.GetIconFont(VectorImageManager.GetAllIconSetNames()[0]);
				}
				
				GUIStyle iconGuiStyle = new GUIStyle { font = VectorImageManager.GetIconFont(data.font.name) };
				
				EditorGUILayout.PrefixLabel("Icon");
				
				if (indent)
				{
					EditorGUI.indentLevel--;
				}
				
				EditorGUILayout.LabelField(IconDecoder.Decode(data.glyph.unicode), iconGuiStyle, GUILayout.Width(18f));
				EditorGUILayout.LabelField(data.glyph.name, GUILayout.MaxWidth(100f), GUILayout.MinWidth(0f));
				
				GUILayout.FlexibleSpace();
				
				if (GUILayout.Button("Pick icon", EditorStyles.miniButton, GUILayout.MaxWidth(60f)))
				{
					Show(data, objectToRefresh);
					return;
				}
				
				if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.MaxWidth(20f)))
				{
					m_VectorImageData = null;
					return;
				}
				
				if (indent)
				{
					EditorGUI.indentLevel++;
				}
			}
        }
Ejemplo n.º 25
0
        /// <summary>Inspector control (eg: EditorGUILayout.SpriteField) for VectorImageData. Supports undo/redo and multiple selected objects.</summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="targetDatas">The VectorImageDatas to modify.</param>
        /// <param name="objectsToUndo">The objects to mark for undo/redo.</param>
        /// <param name="onIconPickAction">Action to call when an icon is picked.</param>
        /// <param name="visualReference">The VectorImageData to use for the 'current' values in the control if the VectorImageData values are different.</param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool VectorImageDataMultiField(string label, VectorImageData[] targetDatas, Object[] objectsToUndo, Action onIconPickAction = null, VectorImageData visualReference = null)
        {
            if (targetDatas.ToList().TrueForAll(data => data == null))
            {
                return(false);
            }

            if (visualReference == null)
            {
                visualReference = targetDatas.ToList().First(data => data != null);
            }

            string code       = visualReference.glyph.unicode;
            string name       = visualReference.glyph.name;
            Font   font       = visualReference.font;
            var    vectorFont = visualReference.vectorFont;

            GUIStyle iconStyle = null;

            s_iconStyles.TryGetValue(visualReference, out iconStyle);
            if (iconStyle == null)
            {
                iconStyle = new GUIStyle {
                    font = font, fontSize = font != null && font.dynamic ? vectorIconSize : 0
                };
                if (iconStyle.font == null && vectorFont != null && vectorFont.fontTMPro != null)
                {
                    iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(vectorFont.fontTMPro.creationSettings.sourceFontFileGUID));
                }
                s_iconStyles[visualReference] = iconStyle;
            }
            iconStyle.fontSize = iconStyle.font != null && iconStyle.font.dynamic ? vectorIconSize : 0;

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(label);
                if (EditorGUI.indentLevel > 0)
                {
                    //  2 is a good 'base' offset when there are indents
                    EditorGUILayout.LabelField("", GUILayout.MaxWidth(-(2 + vectorImageDataIndentOffsetSize * EditorGUI.indentLevel)));
                }

                if (!string.IsNullOrEmpty(name))
                {
                    GUIContent iconGUIContent = new GUIContent(IconDecoder.Decode(code), name);

                    if (iconStyle.font != null && !iconStyle.font.dynamic)
                    {
                        CharacterInfo charInfo;
                        iconStyle.font.GetCharacterInfo(iconGUIContent.text[0], out charInfo);
                        var uvRect = Rect.MinMaxRect(charInfo.uvBottomLeft.x, charInfo.uvBottomLeft.y, charInfo.uvTopRight.x, charInfo.uvTopRight.y);

                        EditorGUILayout.LabelField("", GUILayout.Width(vectorIconSize), GUILayout.Height(vectorIconSize));
                        GUI.DrawTextureWithTexCoords(GUILayoutUtility.GetLastRect(), iconStyle.font.material.mainTexture, uvRect);
                    }
                    else
                    {
                        EditorGUILayout.LabelField(iconGUIContent, iconStyle, GUILayout.MaxWidth(iconStyle.CalcSize(iconGUIContent).x));
                    }

                    if (EditorGUI.indentLevel > 0)
                    {
                        EditorGUILayout.LabelField("", GUILayout.MaxWidth(vectorImageDataIndentOffsetSize * EditorGUI.indentLevel));
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(vectorImageDataMaxLabelWidth));
                    GUILayout.FlexibleSpace();
                }

                if (GUILayout.Button("Pick Icon", EditorStyles.miniButton, GUILayout.MinHeight(miniButtonHeight)))
                {
                    VectorImagePickerWindow.Show(targetDatas, objectsToUndo, onIconPickAction);
                }
                if (visualReference != null && visualReference.ContainsData() &&
                    GUILayout.Button(IconDecoder.Decode(@"\ue14c"),
                                     new GUIStyle {
                    fontSize = iconStyle.fontSize, font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                },
                                     GUILayout.MaxWidth(20)))
                {
                    if (objectsToUndo != null)
                    {
                        Undo.RecordObjects(objectsToUndo, "Set Icon");
                    }

                    foreach (var imageData in targetDatas)
                    {
                        imageData.glyph      = null;
                        imageData.vectorFont = null;
                    }
                }
            }

            return(true);
        }
        /// <summary>
        ///     Inspector control (eg: EditorGUILayout.SpriteField) for VectorImageData. Supports undo/redo and multiple
        ///     selected objects.
        /// </summary>
        /// <param name="label">The label to appear in the inspector control.</param>
        /// <param name="targetDatas">The VectorImageDatas to modify.</param>
        /// <param name="objectsToUndo">The objects to mark for undo/redo.</param>
        /// <param name="onIconPickAction">Action to call when an icon is picked.</param>
        /// <param name="visualReference">
        ///     The VectorImageData to use for the 'current' values in the control if the VectorImageData
        ///     values are different.
        /// </param>
        /// <returns>Whether the control was successfully able to be drawn.</returns>
        public static bool VectorImageDataMultiField(string label, VectorImageData[] targetDatas,
                                                     Object[] objectsToUndo, Action onIconPickAction = null, VectorImageData visualReference = null)
        {
            if (targetDatas.ToList().TrueForAll(data => data == null))
            {
                return(false);
            }

            if (visualReference == null)
            {
                visualReference = targetDatas.ToList().First(data => data != null);
            }

            var code      = visualReference.glyph.unicode;
            var name      = visualReference.glyph.name;
            var font      = visualReference.font;
            var iconStyle = new GUIStyle {
                font = font, fontSize = vectorIconSize
            };

            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(label);
                if (EditorGUI.indentLevel > 0)
                {
                    EditorGUILayout.LabelField("",
                                               GUILayout.MaxWidth(-(2 + vectorImageDataIndentOffsetSize * EditorGUI.indentLevel)));
                }

                if (!string.IsNullOrEmpty(name))
                {
                    var iconGUIContent = new GUIContent(IconDecoder.Decode(code), name);
                    EditorGUILayout.LabelField(iconGUIContent, iconStyle,
                                               GUILayout.MaxWidth(iconStyle.CalcSize(iconGUIContent).x));

                    if (EditorGUI.indentLevel > 0)
                    {
                        EditorGUILayout.LabelField("",
                                                   GUILayout.MaxWidth(vectorImageDataIndentOffsetSize * EditorGUI.indentLevel));
                    }

                    GUILayout.FlexibleSpace();
                }
                else
                {
                    EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(vectorImageDataMaxLabelWidth));
                    GUILayout.FlexibleSpace();
                }

                if (GUILayout.Button("Pick Icon", EditorStyles.miniButton, GUILayout.MinHeight(miniButtonHeight)))
                {
                    VectorImagePickerWindow.Show(targetDatas, objectsToUndo, onIconPickAction);
                }
            }

            return(true);
        }
Ejemplo n.º 27
0
        private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
        {
            SerializedProperty itemData      = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
            SerializedProperty itemText      = itemData.FindPropertyRelative("m_Text");
            SerializedProperty onSelectEvent = itemData.FindPropertyRelative("onOptionSelected");

            SerializedProperty itemSprite = itemData.FindPropertyRelative("m_ImageData.m_Sprite");
            SerializedProperty imgUrl     = itemData.FindPropertyRelative("m_ImageData.m_ImgUrl");

            SerializedProperty itemCode  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Unicode");
            SerializedProperty itemName  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Name");
            GUIStyle           iconStyle = null;

            if (iconStyle == null)
            {
                object          v_asset    = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Font").objectReferenceValue;
                VectorImageFont vectorFont = v_asset as VectorImageFont;
                iconStyle = new GUIStyle {
                    font = vectorFont != null ? vectorFont.font : v_asset as Font
                };
                if (iconStyle.font == null && vectorFont != null && vectorFont.fontTMPro != null)
                {
                    iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(vectorFont.fontTMPro.creationSettings.sourceFontFileGUID));
                }
            }

            SerializedProperty itemImageType = itemData.FindPropertyRelative("m_ImageData.m_ImageDataType");

            RectOffset offset = new RectOffset(-5, 0, -1, -3);

            rect        = offset.Add(rect);
            rect.height = EditorGUIUtility.singleLineHeight;

            float offsetH = 2;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), index.ToString());
            offsetH += 16;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 35, rect.height), "Text", EditorStyles.boldLabel);
            offsetH += 35;

            EditorGUI.PropertyField(new Rect(rect.x + offsetH, rect.y, (rect.width / 3) - offsetH, rect.height), itemText, GUIContent.none);
            offsetH += (rect.width / 3) - offsetH + 8;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 32, rect.height), "Icon", EditorStyles.boldLabel);
            offsetH += 32;

            itemImageType.enumValueIndex = m_ImageType.enumValueIndex;


            if (m_ImageType.enumValueIndex == 0)
            {
                var itemSpriteRect = new Rect(rect.x + offsetH, rect.y, rect.width - offsetH, rect.height);
                EditorGUI.PropertyField(itemSpriteRect, itemSprite, GUIContent.none);
            }
            else
            {
                if (!string.IsNullOrEmpty(itemName.stringValue))
                {
                    var iconText = IconDecoder.Decode(itemCode.stringValue);
                    //EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), IconDecoder.Decode(itemCode.stringValue), iconStyle);
                    if (iconStyle.font != null && !iconStyle.font.dynamic)
                    {
                        CharacterInfo charInfo;
                        iconStyle.font.GetCharacterInfo(iconText[0], out charInfo);
                        var uvRect = Rect.MinMaxRect(charInfo.uvBottomLeft.x, charInfo.uvBottomLeft.y, charInfo.uvTopRight.x, charInfo.uvTopRight.y);

                        GUI.DrawTextureWithTexCoords(new Rect(rect.x + offsetH, rect.y, 16, rect.height), iconStyle.font.material.mainTexture, uvRect);
                    }
                    else
                    {
                        iconStyle.fontSize = (int)rect.height;
                        EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), iconText, iconStyle);
                    }

                    offsetH += 16;
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), itemName.stringValue);
                }
                else
                {
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), "No icon selected");
                }

                if (GUI.Button(new Rect(rect.width - 60, rect.y, 70, rect.height), "Pick Icon"))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    VectorImagePickerWindow.Show(optionDataListContainer.optionDataList.options[index].imageData.vectorImageData, itemData.serializedObject.targetObject);
                }

                var fontStyle = new GUIStyle {
                    font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                };
                if (fontStyle.font != null && fontStyle.font.dynamic)
                {
                    fontStyle.fontSize = (int)rect.height;
                }
                if (GUI.Button(new Rect(rect.width + 16, rect.y, 18, rect.height), IconDecoder.Decode(@"\ue14c"), fontStyle))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    if (optionDataListContainer != null && optionDataListContainer.optionDataList.options[index].imageData != null)
                    {
                        VectorImageData data = optionDataListContainer.optionDataList.options[index].imageData.vectorImageData;
                        if (data != null)
                        {
                            data.vectorFont = null;
                            data.glyph      = null;
                        }
                    }
                    EditorUtility.SetDirty(itemData.serializedObject.targetObject);
                }
            }

            EditorGUI.PropertyField(rect, itemData, new GUIContent(string.Empty), false);
            //itemData.isExpanded = EditorGUI.Foldout(rect, itemData.isExpanded, string.Empty);
            if (itemData.isExpanded)
            {
                var drawUrl = m_ImageType.enumValueIndex == 0;
                rect.y += EditorGUIUtility.singleLineHeight + 3;
                if (drawUrl)
                {
                    var itemSpriteRect = new Rect(rect.x + offsetH, rect.y, rect.width - offsetH, rect.height);

                    EditorGUI.LabelField(new Rect(itemSpriteRect.x - 32, rect.y, 32, rect.height), "Url", EditorStyles.boldLabel);
                    EditorGUI.PropertyField(itemSpriteRect, imgUrl, GUIContent.none);

                    rect.y += EditorGUIUtility.singleLineHeight + 7;
                }
                EditorGUI.PropertyField(rect, onSelectEvent);
            }
        }
Ejemplo n.º 28
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty code = property.FindPropertyRelative("m_Glyph.m_Unicode");
            SerializedProperty name = property.FindPropertyRelative("m_Glyph.m_Name");
            SerializedProperty font = property.FindPropertyRelative("m_Font");
            var vectorFont          = font.objectReferenceValue as VectorImageFont;

            if (iconStyle == null)
            {
                iconStyle = new GUIStyle {
                    font = vectorFont != null ? vectorFont.font : font.objectReferenceValue as Font
                };
                if (iconStyle.font == null && vectorFont != null && vectorFont.fontTMPro != null)
                {
                    iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(vectorFont.fontTMPro.creationSettings.sourceFontFileGUID));
                }
            }

            if (iconStyle.font != null && iconStyle.font.dynamic)
            {
                iconStyle.fontSize = 16;
            }

            RectOffset offset = new RectOffset(0, 0, -1, -3);

            position        = offset.Add(position);
            position.height = EditorGUIUtility.singleLineHeight;

            float offsetH = 0;

            offsetH -= EditorGUI.PrefixLabel(new Rect(position.x + offsetH, position.y, 40, position.height), label).width;

            offsetH += 40;

            if (!string.IsNullOrEmpty(name.stringValue))
            {
                GUIContent iconLabel = new GUIContent(IconDecoder.Decode(code.stringValue));

                if (iconStyle.font != null && !iconStyle.font.dynamic)
                {
                    CharacterInfo charInfo;
                    iconStyle.font.GetCharacterInfo(iconLabel.text[0], out charInfo);
                    var uvRect = Rect.MinMaxRect(charInfo.uvBottomLeft.x, charInfo.uvBottomLeft.y, charInfo.uvTopRight.x, charInfo.uvTopRight.y);

                    GUI.DrawTextureWithTexCoords(new Rect(position.x + offsetH, position.y, 16, position.height), iconStyle.font.material.mainTexture, uvRect);
                }
                else
                {
                    EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, 16, position.height), iconLabel, iconStyle);
                }

                float iconWidth = 16; // iconStyle.CalcSize(iconLabel).x;
                offsetH += iconWidth + 2f;

                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, position.width - offsetH - 80, position.height), name.stringValue);
            }
            else
            {
                EditorGUI.LabelField(new Rect(position.x + offsetH, position.y, position.width - 70 - 56, position.height), "No icon selected");
            }

            if (GUI.Button(new Rect(position.width - 74, position.y, 70, position.height), "Pick Icon"))
            {
                var target = GetTargetFromSerializedProperty(property);
                VectorImagePickerWindow.Show((VectorImageData)fieldInfo.GetValue(target), property.serializedObject.targetObject);
            }
            if (GUI.Button(new Rect(position.width - 2, position.y, 18, position.height), IconDecoder.Decode(@"\ue14c"), new GUIStyle {
                fontSize = 16, font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
            }))
            {
                var             target = GetTargetFromSerializedProperty(property);
                VectorImageData data   = (VectorImageData)fieldInfo.GetValue(target);
                data.vectorFont = null;
                data.glyph      = null;
                EditorUtility.SetDirty(property.serializedObject.targetObject);
            }
        }
Ejemplo n.º 29
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GetProperties(property);

            Rect pos = position;

            pos.height = EditorGUI.GetPropertyHeight(m_ImageDataType);


            var labelRect = new Rect(position.x, position.y, position.width, EditorGUI.GetPropertyHeight(m_ImageDataType));

            pos        = EditorGUI.PrefixLabel(labelRect, label);
            pos.x     -= (15 * EditorGUI.indentLevel);
            pos.width += (15 * EditorGUI.indentLevel);

            if (m_ImageDataType.enumValueIndex == 0)
            {
                pos.height = EditorGUI.GetPropertyHeight(m_Sprite);

                EditorGUI.PropertyField(pos, m_Sprite, GUIContent.none);

                //property.isExpanded = EditorGUI.Foldout(new Rect(position.x - 4, position.y, position.width, pos.height), property.isExpanded, string.Empty);
                EditorGUI.PropertyField(new Rect(position.x - 4, position.y, position.width, pos.height), property, new GUIContent(string.Empty), false);
                if (property.isExpanded)
                {
                    pos.y       += pos.height + 3;
                    labelRect.y += EditorGUIUtility.singleLineHeight + 3;

                    labelRect = EditorGUI.IndentedRect(labelRect);
                    EditorGUI.LabelField(labelRect, "Url");
                    EditorGUI.PropertyField(pos, m_ImgUrl, GUIContent.none);
                }
                pos.y += pos.height;
            }

            if (m_ImageDataType.enumValueIndex == 1)
            {
                pos.height = EditorGUI.GetPropertyHeight(m_VectorImageData);

                SerializedProperty code = m_VectorImageData.FindPropertyRelative("m_Glyph.m_Unicode");
                SerializedProperty name = m_VectorImageData.FindPropertyRelative("m_Glyph.m_Name");
                SerializedProperty font = m_VectorImageData.FindPropertyRelative("m_Font");
                var vectorFont          = font.objectReferenceValue as VectorImageFont;

                if (iconStyle == null)
                {
                    iconStyle = new GUIStyle {
                        font = vectorFont != null ? vectorFont.font : font.objectReferenceValue as Font
                    };
                    if (iconStyle.font == null && vectorFont != null && vectorFont.fontTMPro != null)
                    {
                        iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(vectorFont.fontTMPro.creationSettings.sourceFontFileGUID));
                    }
                    if (iconStyle.font != null && iconStyle.font.dynamic)
                    {
                        iconStyle.fontSize = 16;
                    }
                }

                float pickButtonWidth    = 70;
                float pickButtonPadding  = 88;
                float clearButtonWidth   = 18;
                float clearButtonPadding = 14;

                if (!string.IsNullOrEmpty(name.stringValue))
                {
                    var iconText = IconDecoder.Decode(code.stringValue);
                    if (iconStyle.font != null && !iconStyle.font.dynamic)
                    {
                        CharacterInfo charInfo;
                        iconStyle.font.GetCharacterInfo(iconText[0], out charInfo);
                        var uvRect = Rect.MinMaxRect(charInfo.uvBottomLeft.x, charInfo.uvBottomLeft.y, charInfo.uvTopRight.x, charInfo.uvTopRight.y);

                        GUI.DrawTextureWithTexCoords(new Rect(pos.x, pos.y, 16, pos.height), iconStyle.font.material.mainTexture, uvRect);
                    }
                    else
                    {
                        EditorGUI.LabelField(new Rect(pos.x, pos.y, 16, pos.height), iconText, iconStyle);
                    }

                    pos.x     += 16;
                    pos.width -= 16;
                    EditorGUI.LabelField(new Rect(pos.x, pos.y, pos.width, position.height), name.stringValue);
                }
                else
                {
                    EditorGUI.LabelField(
                        new Rect(pos.x, pos.y, pos.width - (pickButtonWidth + clearButtonWidth), pos.height),
                        "No icon selected");
                }

                if (GUI.Button(new Rect((pos.x + pos.width) - pickButtonPadding, pos.y, pickButtonWidth, pos.height),
                               "Pick Icon"))
                {
                    var fieldValue = MaterialSerializedPropertyExtensions.GetFieldValue(property);
                    VectorImagePickerWindow.Show(
                        ((ImageData)fieldValue)
                        .vectorImageData, property.serializedObject.targetObject);
                }

                var v_guiButtonFont = new GUIStyle {
                    font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                };
                if (v_guiButtonFont.font != null && v_guiButtonFont.font.dynamic)
                {
                    v_guiButtonFont.fontSize = 16;
                }
                if (GUI.Button(new Rect((pos.x + pos.width - 1) - clearButtonPadding, pos.y, clearButtonWidth, pos.height),
                               IconDecoder.Decode(@"\ue14c"), v_guiButtonFont
                               ))
                {
                    var             fieldValue = MaterialSerializedPropertyExtensions.GetFieldValue(property);
                    VectorImageData data       = ((ImageData)fieldValue).vectorImageData;
                    data.vectorFont = null;
                    data.glyph      = null;
                    EditorUtility.SetDirty(property.serializedObject.targetObject);
                }
            }
        }
Ejemplo n.º 30
0
 public ImageData(VectorImageData vectorImageData)
 {
     m_VectorImageData = vectorImageData;
     m_ImageDataType   = ImageDataType.VectorImage;
 }
Ejemplo n.º 31
0
        public static bool VectorImageDataField(string label, VectorImageData targetData, Object objectToUndo, Action onIconPickAction = null, bool disableIfMultipleObjectsSelected = true)
        {
            if (targetData == null)
            {
                return(false);
            }

            using (new DisabledScope(TooManySelected(!disableIfMultipleObjectsSelected)))
            {
                string code       = targetData.glyph.unicode;
                string name       = targetData.glyph.name;
                Font   font       = targetData.font;
                var    vectorFont = targetData.vectorFont;

                GUIStyle iconStyle = null;
                s_iconStyles.TryGetValue(targetData, out iconStyle);
                if (iconStyle == null)
                {
                    iconStyle = new GUIStyle {
                        font = font, fontSize = font != null && font.dynamic ? vectorIconSize : 0
                    };
                    if (iconStyle.font == null && vectorFont != null && vectorFont.fontTMPro != null)
                    {
                        iconStyle.font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(vectorFont.fontTMPro.creationSettings.sourceFontFileGUID));
                    }
                    s_iconStyles[targetData] = iconStyle;
                }
                iconStyle.fontSize = iconStyle.font != null && iconStyle.font.dynamic ? vectorIconSize : 0;

                using (new GUILayout.HorizontalScope())
                {
                    EditorGUILayout.PrefixLabel(label);
                    if (EditorGUI.indentLevel > 0)
                    {
                        //  2 is a good 'base' offset when there are indents
                        EditorGUILayout.LabelField("", GUILayout.MaxWidth(-(2 + vectorImageDataIndentOffsetSize * EditorGUI.indentLevel)));
                    }

                    if (!string.IsNullOrEmpty(name))
                    {
                        GUIContent iconGUIContent = new GUIContent(IconDecoder.Decode(code), name);

                        if (iconStyle.font != null && !iconStyle.font.dynamic)
                        {
                            CharacterInfo charInfo;
                            iconStyle.font.GetCharacterInfo(iconGUIContent.text[0], out charInfo);
                            var uvRect = Rect.MinMaxRect(charInfo.uvBottomLeft.x, charInfo.uvBottomLeft.y, charInfo.uvTopRight.x, charInfo.uvTopRight.y);

                            EditorGUILayout.LabelField("", GUILayout.Width(vectorIconSize), GUILayout.Height(vectorIconSize));
                            GUI.DrawTextureWithTexCoords(GUILayoutUtility.GetLastRect(), iconStyle.font.material.mainTexture, uvRect);
                        }
                        else
                        {
                            EditorGUILayout.LabelField(iconGUIContent, iconStyle, GUILayout.MaxWidth(iconStyle.CalcSize(iconGUIContent).x));
                        }

                        if (EditorGUI.indentLevel > 0)
                        {
                            EditorGUILayout.LabelField("", GUILayout.MaxWidth(vectorImageDataIndentOffsetSize * EditorGUI.indentLevel));
                        }
                    }
                    else
                    {
                        EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(vectorImageDataMaxLabelWidth));
                    }

                    if (GUILayout.Button("Pick Icon", EditorStyles.miniButton, GUILayout.MinHeight(miniButtonHeight)))
                    {
                        VectorImagePickerWindow.Show(targetData, objectToUndo, onIconPickAction);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// See MonoBehaviour.OnValidate.
        /// </summary>
        protected override void OnValidate()
        {
            if (m_Graphic && m_ChangeGraphicColor)
            {
                if (m_Interactable)
                {
                    m_Graphic.color = toggle.isOn ? m_GraphicOnColor : m_GraphicOffColor;
                }
                else
                {
                    m_Graphic.color = m_GraphicDisabledColor;
                }
            }
            if (materialRipple && m_ChangeRippleColor)
            {
                materialRipple.rippleData.Color = toggle.isOn ? m_RippleOnColor : m_RippleOffColor;
            }

            UpdateGraphicToggleState();

            if (m_Graphic != null)
            {
                if (m_Graphic.IsSpriteOrVectorImage())
                {
                    if (m_Graphic.GetType() == typeof(Image))
                    {
                        if (m_LastIconSprite == m_Icon.sprite)
                        {
                            m_Icon.sprite = m_Graphic.GetSpriteImage();
                        }
                        else
                        {
                            m_Graphic.SetImage(m_Icon.sprite);
                        }

                        m_LastIconSprite = m_Icon.sprite;
                    }
                    else
                    {
                        if (m_LastIconVectorImageData == m_Icon.vectorImageData)
                        {
                            m_Icon.vectorImageData = m_Graphic.GetVectorImage();
                        }
                        else
                        {
                            m_Graphic.SetImage(m_Icon.vectorImageData);
                        }

                        m_LastIconVectorImageData = m_Icon.vectorImageData;
                    }
                }
                else
                {
                    Text text = m_Graphic as Text;
                    if (text != null)
                    {
                        if (m_LastLabelText == m_Label)
                        {
                            m_Label = text.text;
                        }
                        else
                        {
                            text.text = m_Label;
                        }

                        m_LastLabelText = m_Label;
                    }
                }
            }
        }
Ejemplo n.º 33
0
        private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
        {
            SerializedProperty itemData = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
            SerializedProperty itemText = itemData.FindPropertyRelative("m_Text");

            SerializedProperty itemSprite = itemData.FindPropertyRelative("m_ImageData.m_Sprite");

            SerializedProperty itemCode  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Unicode");
            SerializedProperty itemName  = itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Glyph.m_Name");
            GUIStyle           iconStyle = new GUIStyle {
                font = (Font)itemData.FindPropertyRelative("m_ImageData.m_VectorImageData.m_Font").objectReferenceValue
            };

            SerializedProperty itemImageType = itemData.FindPropertyRelative("m_ImageData.m_ImageDataType");

            RectOffset offset = new RectOffset(0, 0, -1, -3);

            rect        = offset.Add(rect);
            rect.height = EditorGUIUtility.singleLineHeight;

            float offsetH = 0;

            EditorGUI.LabelField(new Rect(rect.x, rect.y, 16, rect.height), index.ToString());
            offsetH += 16;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 35, rect.height), "Text", EditorStyles.boldLabel);
            offsetH += 35;

            EditorGUI.PropertyField(new Rect(rect.x + offsetH, rect.y, (rect.width / 3) - offsetH, rect.height), itemText, GUIContent.none);
            offsetH += (rect.width / 3) - offsetH + 8;

            EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 32, rect.height), "Icon", EditorStyles.boldLabel);
            offsetH += 32;

            itemImageType.enumValueIndex = m_ImageType.enumValueIndex;

            if (m_ImageType.enumValueIndex == 0)
            {
                EditorGUI.PropertyField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH, rect.height), itemSprite, GUIContent.none);
            }
            else
            {
                if (!string.IsNullOrEmpty(itemName.stringValue))
                {
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, 16, rect.height), IconDecoder.Decode(itemCode.stringValue), iconStyle);
                    offsetH += 16;
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), itemName.stringValue);
                }
                else
                {
                    EditorGUI.LabelField(new Rect(rect.x + offsetH, rect.y, rect.width - offsetH - 80, rect.height), "No icon selected");
                }

                if (GUI.Button(new Rect(rect.width - 60, rect.y, 70, rect.height), "Pick Icon"))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    VectorImagePickerWindow.Show(optionDataListContainer.optionDataList.options[index].imageData.vectorImageData, itemData.serializedObject.targetObject);
                }

                if (GUI.Button(new Rect(rect.width + 16, rect.y, 18, rect.height), IconDecoder.Decode(@"\ue14c"), new GUIStyle {
                    font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName)
                }))
                {
                    IOptionDataListContainer optionDataListContainer = itemData.serializedObject.targetObject as IOptionDataListContainer;
                    VectorImageData          data = optionDataListContainer.optionDataList.options[index].imageData.vectorImageData;
                    data.font  = null;
                    data.glyph = null;
                    EditorUtility.SetDirty(itemData.serializedObject.targetObject);
                }
            }
        }
Ejemplo n.º 34
0
 public static void Show(VectorImageData data, Object objectToRefresh, Action refreshAction)
 {
     Show(new[] { data }, new[] { objectToRefresh }, refreshAction);
 }